Hasher
Junior Member level 1
Hello!
I'm using PIC18F2420 with HiTech C compiler.
I want to build a running clock using Timer 2.
The seconds to be displayed on Port B using two 7-segments display.
The minuets to be displayed on Port C using two 7-segments display.
Note==>
I have to use the same values for the timer2 bcs I'm using this configuration for other parts of my program. Also, I'm not allowed to use other timers.
Problem==>
I got no o/p on the 7-segments at all!
Program==>
volatile unsigned char clkTecs,hours, mins, secs,old_secs;
// interrupted every second
void interrupt timer_isr(void)
{
if (TMR2IF)
{
TMR2IF = 0;
clkTecs++;
if (clkTecs == 15625)
{
secs++;
if (secs == 60)
{
secs = 0;
mins++;
if (mins == 60)
{
mins = 0;
hours++;
if (hours == 24)
{
hours = 0;
}
}
}
}
}
}
void main(void)
{
//Timer 2 Configuration
//-------------------------------------------------
// post scale of 16
TOUTPS3 = 1; TOUTPS2 = 1;
TOUTPS1 = 1; TOUTPS0 = 1;
// pre scale of 16
T2CKPS1 = 1; T2CKPS0 = 1;
// start timer 2
TMR2ON = 1 ;
IPEN = 0;
TMR2IF = 0;
TMR2IE = 1;
PEIE = 1;
GIE = 1;
// set timer2 PR register
PR2 = 1;
TRISB = 0;
PORTB=0x00;
TRISC = 0;
PORTC=0x00;
old_secs = secs;
while(1)
{
while(secs == old_secs);
old_secs = secs;
PORTB = old_secs;
PORTC = mins;
}
I'm using PIC18F2420 with HiTech C compiler.
I want to build a running clock using Timer 2.
The seconds to be displayed on Port B using two 7-segments display.
The minuets to be displayed on Port C using two 7-segments display.
Note==>
I have to use the same values for the timer2 bcs I'm using this configuration for other parts of my program. Also, I'm not allowed to use other timers.
Problem==>
I got no o/p on the 7-segments at all!
Program==>
volatile unsigned char clkTecs,hours, mins, secs,old_secs;
// interrupted every second
void interrupt timer_isr(void)
{
if (TMR2IF)
{
TMR2IF = 0;
clkTecs++;
if (clkTecs == 15625)
{
secs++;
if (secs == 60)
{
secs = 0;
mins++;
if (mins == 60)
{
mins = 0;
hours++;
if (hours == 24)
{
hours = 0;
}
}
}
}
}
}
void main(void)
{
//Timer 2 Configuration
//-------------------------------------------------
// post scale of 16
TOUTPS3 = 1; TOUTPS2 = 1;
TOUTPS1 = 1; TOUTPS0 = 1;
// pre scale of 16
T2CKPS1 = 1; T2CKPS0 = 1;
// start timer 2
TMR2ON = 1 ;
IPEN = 0;
TMR2IF = 0;
TMR2IE = 1;
PEIE = 1;
GIE = 1;
// set timer2 PR register
PR2 = 1;
TRISB = 0;
PORTB=0x00;
TRISC = 0;
PORTC=0x00;
old_secs = secs;
while(1)
{
while(secs == old_secs);
old_secs = secs;
PORTB = old_secs;
PORTC = mins;
}