union TunionData
{
FATFS fat; // без этой строчки работает нормально
char buffer[BUF_SIZE];
unsigned char romCode[BUF_SIZE / 9][9];
unsigned char queue[BUF_SIZE];
};
Код: Выделить всё
void main(void){
PORTB=0x00;
DDRB=0x00000111;
while (1)
{ }
}
Код: Выделить всё
UCSRA=0x00;
UCSRB=0x08;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x67;Код: Выделить всё
UCSRA=(0<<RXC) | (0<<TXC) | (0<<UDRE) | (0<<FE) | (0<<DOR) | (0<<UPE) | (0<<U2X) | (0<<MPCM);
UCSRB=(0<<RXCIE) | (0<<TXCIE) | (0<<UDRIE) | (0<<RXEN) | (1<<TXEN) | (0<<UCSZ2) | (0<<RXB8) | (0<<TXB8);
UCSRC=(1<<URSEL) | (0<<UMSEL) | (0<<UPM1) | (0<<UPM0) | (0<<USBS) | (1<<UCSZ1) | (1<<UCSZ0) | (0<<UCPOL);
UBRRH=0x00;
UBRRL=0x67;Код: Выделить всё
#include <tiny13a.h>
#define SIGNAL_PIN PINB.0
#define TIME_MS 2500
#define OUT_PIN_1 PORTB3
#define OUT_PIN_2 PORTB4
volatile char flag = 2;
volatile unsigned int time = 0;
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
if (SIGNAL_PIN == 1) flag = 1;
if (SIGNAL_PIN == 0) flag = 0;
time = 0; // сбрасываем delay()
}
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// Reinitialize Timer 0 value
TCNT0=0xB5;
time = time--;
}
void delay (unsigned int a)
{
time = a;
TCCR0A=(0<<COM0A1) | (0<<COM0A0) | (0<<COM0B1) | (0<<COM0B0) | (0<<WGM01) | (0<<WGM00);
TCNT0=0xB5;
OCR0A=0x00;
OCR0B=0x00;
TCCR0B=(0<<WGM02) | (0<<CS02) | (1<<CS01) | (1<<CS00); //включаем таймер
while (time); // висим пока счётчик не будет 0
TCCR0B=(0<<WGM02) | (0<<CS02) | (0<<CS01) | (0<<CS00); //выключаем счётчик
}
void opening (void)
{
PORTB = (0<<OUT_PIN_1) | (1<<OUT_PIN_2);
delay(TIME_MS);
PORTB = (1<<OUT_PIN_1) | (1<<OUT_PIN_2);
}
void closing (void)
{
PORTB = (1<<OUT_PIN_1) | (0<<OUT_PIN_2);
delay(TIME_MS);
PORTB = (1<<OUT_PIN_1) | (1<<OUT_PIN_2);
}
void main(void)
{
// Declare your local variables here
// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=(1<<CLKPCE);
CLKPR=(0<<CLKPCE) | (0<<CLKPS3) | (0<<CLKPS2) | (0<<CLKPS1) | (0<<CLKPS0);
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
// Input/Output Ports initialization
// Port B initialization
// Func5=In Func4=Out Func3=Out Func2=In Func1=In Func0=In
// State5=T State4=1 State3=1 State2=T State1=T State0=T
PORTB=0x18;
DDRB=0x18;
// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=(0<<OCIE0B) | (0<<OCIE0A) | (1<<TOIE0);
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Any change
// Interrupt on any change on pins PCINT0-5: Off
GIMSK=(1<<INT0) | (0<<PCIE);
MCUCR=(0<<ISC01) | (1<<ISC00);
GIFR=(1<<INTF0) | (0<<PCIF);
#asm("sei") // Global enable interrupts
flag = 2;
delay(100); // пусть всё устаканится при включении
if (SIGNAL_PIN == 1) opening();
if (SIGNAL_PIN == 0) closing();
while (1)
{
switch (flag)
{
case 1:
opening();
if(flag == 0) break;
flag = 2;
break;
case 0:
closing();
if(flag == 1) break;
flag = 2;
break;
default:
flag = 2;
};
}
}