من یه برنامه تقویم را بدون هیچ RTC ای با Timer2 راه انداختم ولی در نیم ساعت 5 دقیقه عقب می افتد اشکال کار چیه؟؟؟
هرجوریشم که بخواین عوضش کردم یعنی کدهای برنامه را بین while و سرویس وقفه عوض کردم ولی همیشه توی نیم ساعت 5 دقیقه عقب میمونه
چرا؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟ ؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟
کد:
#include <mega16.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>
#include <delay.h>
#include <stdlib.h>
char s[3];
char m[3];
char h[3];
char d[3];
char mo[3];
char y[5];
unsigned char a;
char second;
char minute;
char hour;
char day;
char month;
char year;
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
// Place your code here
a++;
if(a==7)
{
a=0;
lcd_clear();
lcd_putsf("SHAHRYAR");
lcd_gotoxy(6,1);
lcd_putsf("RAJABZADEH");
delay_ms(200);
lcd_clear();
}
}
// External Interrupt 1 service routine
interrupt [EXT_INT1] void ext_int1_isr(void)
{
// Place your code here
if(a==1)
{
second++;
}
if(a==2)
{
minute++;
}
if(a==3)
{
hour++;
}
if(a==4)
{
day++;
}
if(a==5)
{
month++;
}
if(a==6)
{
year++;
}
}
// External Interrupt 2 service routine
interrupt [EXT_INT2] void ext_int2_isr(void)
{
// Place your code here
if(a==1)
{
second--;
}
if(a==2)
{
minute--;
}
if(a==3)
{
hour--;
}
if(a==4)
{
day--;
}
if(a==5)
{
month--;
}
if(a==6)
{
year--;
}
}
// Timer 2 overflow interrupt service routine
interrupt [TIM2_OVF] void timer2_ovf_isr(void)
{
// Reinitialize Timer 2 value
TCNT2=0x01;
// Place your code here
second++;
lcd_clear();
lcd_gotoxy(2,0);
itoa(hour,h);
lcd_puts(h);
lcd_putsf(":");
itoa(minute,m);
lcd_puts(m);
lcd_putsf(":");
itoa(second,s);
lcd_puts(s);
lcd_gotoxy(2,1);
itoa(year,y);
lcd_puts(y);
lcd_putsf("/");
itoa(month,mo);
lcd_puts(mo);
lcd_putsf("/");
itoa(day,d);
lcd_puts(d);
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
ASSR=0x08;
TCCR2=0x05;
TCNT2=0x01;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Falling Edge
// INT1: On
// INT1 Mode: Falling Edge
// INT2: On
// INT2 Mode: Falling Edge
GICR|=0xE0;
MCUCR=0x0A;
MCUCSR=0x00;
GIFR=0xE0;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x40;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
// LCD module initialization
lcd_init(16);
lcd_clear();
// Global enable interrupts
#asm("sei")
a=0;
second=0;
minute=0;
hour=11;
day=23;
month=9;
year=88;
while (1)
{
// Place your code here
if(second==59)
{
second=0;
minute++;
}
if(minute==60)
{minute=0;
hour++;
}
if(hour==24)
{
hour=0;
day++;
}
if(month<6)
{
if(day==32)
{
day=1;
month++;
}
}
if(6<month<12)
{
if(day==31)
{
day=1;
month++;
}
}
if(month==12)
{
if(day==30)
{
day=1;
month++;
}
}
if(month==13)
{
month=1;
year++;
}
};
}
چرا؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟ ؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟





دیدگاه