Например:
Код: Выделить всё
ldi r16, 124Код: Выделить всё
ldi r16, 124Код: Выделить всё
..............
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x60;
TIMSK=0x80;
// Global enable interrupts
#asm("sei")
while (1)
.............Код: Выделить всё
#include <mega8.h>
bit flag;
unsigned char second, minute=20, hour=5;
unsigned int x,z,y;
//unsigned int s,m,h,;
// Timer1 output compare A interrupt service routine
interrupt [TIM1_COMPA] void timer1_compa_isr(void)
{
second++;
if(second == 60)
{ second = 0;
minute++;
if(minute == 60)
{ minute = 0;
hour++;
if(hour == 24)
{hour = 0;}}}
}
// Timer2 output compare interrupt service routine
interrupt [TIM2_COMP] void timer2_comp_isr(void)
{x++;
y++;
if (PINB>0){flag=1;}else{flag=0;}
//if (PINB.0>0){if (x!=0)*/{z++;x=0;}}// s=(second*z)/60, m=(minute*z)/60, h=(hour*z)/60;}}
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// float r;
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTC=0x00;
DDRC=0x7F;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 16000,000 kHz
// Mode: CTC top=OCR1A
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: On
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x0D;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x1E;
OCR1AL=0x84;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: 16000,000 kHz
// Mode: CTC top=OCR2
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x09;
TCNT2=0x00;
OCR2=0xA0;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x90;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// Global enable interrupts
#asm("sei")
while (1)
/*{if (flag==1)
{z++; if(z==0){PORTC.0=1,PORTC.1=0;}
if(z==1){PORTC.0=0,PORTC.1=1;}
if(z==2){z=0,PORTC.0=1,PORTC.1=0;}}} }*/
/*{for (i=0;i<60;i++)
{y=0; while(y<=z){
PORTC.0=0;
PORTC.1=0;
PORTC.2=0;
PORTC.3=1;
PORTC.4=0;
PORTC.5=0;}
if (i==second)
{y=0; while(y<=z)
{PORTC.0=1;
PORTC.1=0;
PORTC.2=0;
PORTC.3=0;
PORTC.4=0;
PORTC.5=0;}}
if (i==minute)
{y=0; while(y<=z)
{PORTC.0=0;
PORTC.1=1;
PORTC.2=0;
PORTC.3=0;
PORTC.4=0;
PORTC.5=0;}}
if (i==hour)
{y=0; while(y<=z)
{PORTC.0=0;
PORTC.1=0;
PORTC.2=1;
PORTC.3=0;
PORTC.4=0;
PORTC.5=0;}}
}}}