vinhove
Newbie level 4
Hello !!!
I am using PIC18F4550 for generating a real time clock by using timer0 interrupt. I have the following code which compiles successfully on MikroC compiler but on testing on proteus it is not giving any results. I have tried to change a lot of things and I have tried to research on how to solve this problem but am still facing the same problem. So can someone help me with this...
unsigned int counter;
unsigned int sec;
unsigned int mins;
unsigned int hour;
unsigned int day;
void interrupt() {
if(INTCON.TMR0IF) { // if timer 0 overflow
counter++ ;
if(counter==3907) { // one second has elapsed
counter = 0 ;
sec++ ;
if(sec == 60) { // one minute has alapsed
sec = 0 ;
mins++ ;
if(mins == 60) { // one hour has elapsed
mins = 0 ;
hour++ ;
if(hour == 24) { // one day has elapsed
hour = 0 ;
day++;
if(day ==8) { // beginning a new week
day =1;
}
}
}
}
}
}
INTCON.TMR0IF = 0 ;
TMR0L=0xFF;
T0CON.TMR0ON=1; //START TIMER
}//
void main() {
INTCON = 0xE0;
T0CON = 0x48;
INTCON2 = 0x04;
RCON = 0x80;
TMR0L=0xFF;
TRISB = 0b00000000;
PORTB = 0b00000000;
TRISD = 0x00;
PORTD = 0x00;
T0CON.TMR0ON=1; //START TIMER
while(1)
{
if (sec==20)
{
PORTD = 0xFF;
}
}
}
I am using PIC18F4550 for generating a real time clock by using timer0 interrupt. I have the following code which compiles successfully on MikroC compiler but on testing on proteus it is not giving any results. I have tried to change a lot of things and I have tried to research on how to solve this problem but am still facing the same problem. So can someone help me with this...
unsigned int counter;
unsigned int sec;
unsigned int mins;
unsigned int hour;
unsigned int day;
void interrupt() {
if(INTCON.TMR0IF) { // if timer 0 overflow
counter++ ;
if(counter==3907) { // one second has elapsed
counter = 0 ;
sec++ ;
if(sec == 60) { // one minute has alapsed
sec = 0 ;
mins++ ;
if(mins == 60) { // one hour has elapsed
mins = 0 ;
hour++ ;
if(hour == 24) { // one day has elapsed
hour = 0 ;
day++;
if(day ==8) { // beginning a new week
day =1;
}
}
}
}
}
}
INTCON.TMR0IF = 0 ;
TMR0L=0xFF;
T0CON.TMR0ON=1; //START TIMER
}//
void main() {
INTCON = 0xE0;
T0CON = 0x48;
INTCON2 = 0x04;
RCON = 0x80;
TMR0L=0xFF;
TRISB = 0b00000000;
PORTB = 0b00000000;
TRISD = 0x00;
PORTD = 0x00;
T0CON.TMR0ON=1; //START TIMER
while(1)
{
if (sec==20)
{
PORTD = 0xFF;
}
}
}