Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with running clock using Timer2

Status
Not open for further replies.

Hasher

Junior Member level 1
Joined
Apr 14, 2009
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,458
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;
}
:cry::cry:
 

For each number you have to configure port, by enabling the pins to switc on the apropriate led.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top