Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

timer interrupt

Status
Not open for further replies.

t.man

New Member
i want to write a code for my LCD to display real time information...i'm considering using a timer1 interrupt to update my display but i have no clue how to achieve that!. any suggestions?
 
Just generate a regular interrupt (I would use tmr2), say every 10mS, and increment a counter in the ISR. When the counter reaches 100, then increment the seconds counter and set a flag to show it's changed. The main program just needs to check the flag, and update the display when the flag is set, then clear the flag again. The ISR obviously keeps a count of minutes and hours as well.
 
Nigel Goodwin said:
Just generate a regular interrupt (I would use tmr2), say every 10mS, and increment a counter in the ISR. When the counter reaches 100, then increment the seconds counter and set a flag to show it's changed. The main program just needs to check the flag, and update the display when the flag is set, then clear the flag again. The ISR obviously keeps a count of minutes and hours as well.

just come a litle slower Nigel, i'm new in LCD interfacing..

what you tell me is, i use timr2overflow interrupt, should i use timr2 async or sync?
should i define my ISR,
Code:
ISR(TIMER2_OVF_vect)
{
     //increment count here and 
    // increment seconds and
    // update my dispaly here
}

can you just clearify your help please!!
i'll b reading ADC values and displaying the readings real time!
 
Flow chart your problem...it invariably leads you to workable ideas :)

The lcd initialisation routine is generally the bit most folks get wrong in my experience (assuming a standard 2*20 type lcd module) but a quick look at any of the datasheets will quickly show you the order of things.

As Nigel pointed out, just set a free running timer, set up for the period you require. Set it up so that it overflows and sets an interrupt flag. Your main body of code then spends it's time reading your ADC and storing the latest values. After each pass, simply check for the interrupt flag having been set, if so send your output to the display routine you are using for output to the lcd, then clear the flag and go back to reading your ADC again etc.
Whatever the period you set your timer for, obviously it has to be long enough for the user to clearly see what is being displayed, no point in it updating faster than you can absorb what you see.

rgds
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top