ucsam
Advanced Member level 4
- Joined
- Oct 12, 2010
- Messages
- 119
- Helped
- 3
- Reputation
- 6
- Reaction score
- 3
- Trophy points
- 1,298
- Location
- kathmandu,nepal
- Activity points
- 2,058
Hey guys i am having a serious problem.
The following program compiles successfully but when i turn on the system, there wont be be timer (caused) delay ( which can be set via some switches) after looking for long time, i figured that the timer 0 ISR is not being served. Since, I am new to MickroC compiler for 8051. Help me out!!
The following program compiles successfully but when i turn on the system, there wont be be timer (caused) delay ( which can be set via some switches) after looking for long time, i figured that the timer 0 ISR is not being served. Since, I am new to MickroC compiler for 8051. Help me out!!
Code:
sbit LCD_RS at P2.B0;
sbit LCD_EN at P2.B1;
sbit LCD_D7 at P2.B5;
sbit LCD_D6 at P2.B4;
sbit LCD_D5 at P2.B3;
sbit LCD_D4 at P2.B2;
sbit ok at P2.B7;
sbit inc at P2.B6;
sbit led at P3.B0;
volatile char power_flag=0;
volatile char time_variable=1;
volatile int time_count=0;
void main(void)
{
TMOD=0x01;
EA=1;
ET0=1;
TH0=0xB8;
TL0=0x00;
ok=inc=1;
Lcd_Init(); // Initialize LCD
Lcd_Out(1,6,"Hello!");
led=0;
delay_ms(500);
led=1;
delay_ms(500);
while(1)
{
Lcd_Out(1,1,"Set time: sec");
while(ok)
{
if(!inc)
delay_ms(20);
if(!inc)
{
time_variable++;
if(time_variable>99)
time_variable=1;
}
Lcd_Chr(1,11,((time_variable/10)+48));
Lcd_Chr(1,12,((time_variable%10)+48));
}
delay_ms(500);
Lcd_Out(2,2,"Timer Running!");
TR0=1;
while(power_flag)
PCON=0x02;
TR0=0;
led=0;
delay_ms(100);
led=1;
delay_ms(100);
Lcd_Out(2,1," ");
Lcd_Out(2,3,"Timer over!");
delay_ms(300);
}
}
void timer_int(void) org 0x0B ilevel 0
{
time_count++;
if(time_count<50*time_variable)
power_flag=1;
else
{
time_variable=0;
time_count=0;
power_flag=0;
}
TH0=0xB8;
TL0=0x00;
return;
}