PDA

View Full Version : Programming TMR0 Interrupt in PICBasic



emavil
- 30th August 2006, 02:06
Hi. I really had a hard time understanding the TMR0 interrupt of PIC16F84A (4MHz crystal). I'm using PICBasic. Is there anyone who could give just a simple demonstration on how to program interrupts, including the prescaler configurations. I'm building a simple digital clock with 6 multiplexed CA 7-segment displays, with 3 buttons. I'm very much curious about the accuracy of the clock, especially the 1 second generation. What is the right refresh rate of the 7-segments? Which part of the program do I have to process the incrementing of seconds, minutes & hours?

RussMartin
- 30th August 2006, 06:45
I can't say much about the PIC side of the question, since I'm new to them (or they're new to me), but, assuming you're talking about multiplexing 6 separate 7-segment LED displays (and assuming I understood your question correctly), I think you need to refresh them at about 30 Hz.

Russ

ra68gi
- 6th September 2006, 16:14
Hi ,
I have done a similar RTC with 89c2051 microcontroller using BASCOM compiler. Its a basic compiler for the 8051 core. The clk will display seconds minutes and hours on 6 seven segment display, which are multiplixed and i have not used any driver/ latch ics. I have used timer0 in mode2( 8 bit auto reload). i have also provided 2 switches to set hours and minutes.
If you are interested let me know.
Free Demo version of bascom is available with which you can write upto 2k code. The clk program took around 1300 words if i remember it right.
Raghunathan

paul borgmeier
- 6th September 2006, 17:06
Although it does not use LEDs, I posted clock code that keeps excellent time (without the need for a RTC) based on TMRO here

http://www.picbasic.co.uk/forum/showthread.php?t=2129

You could use the time keeping part of the code for your clock time and change the display updates as required for your LED display. Reply back if you need more information.

sayzer
- 6th September 2006, 18:22
For the display part, I would like to make a suggestion.

Since you will need to drive say PORTB with a HEX number to display a digit on the LED display, I would recommend storing HEX values in EEPROM.





EEPROM 0,[$c0,$F9,$A4,$B0,$99,$92,$82,$F8,$80,$90]


Incoming = 5
'from 0 to 9


READ Incoming, PORTB





So that you won't need to use a lookup table.


'==Display Configuration==

A PORTB.0
B PORTB.1
C PORTB.2
D PORTB.3
E PORTB.4
F PORTB.5
G PORTB.6
Dt PORTB.7

'NUMBER - HEX on Portb
'high pin turns off the led.
'low pin turns on the led.

0= $c0
1= $F9
2= $A4
3= $B0
4= $99
5= $92
6= $82
7= $F8
8= $80
9= $90
-= $BF
C= $C6




- This configuration was for 4x7 Segment LED display.


________________________--

mister_e
- 6th September 2006, 22:39
maybe this could be handy
http://www.picbasic.co.uk/forum/showthread.php?t=1044

paul borgmeier
- 11th September 2006, 16:10
(In response to a PM from the OP.)

For Multiplexing LEDs, I like the refresh rate to be at least 40 Hz or higher. Some use lower but 40+ Hz is rather safe (“normal intensity”red LED flicker fusion frequency in the normal human eye is in the mid 30s). You can chose to multiplex each segment or each digit – most multiplex each digit because it is easier to do and gives more brightness options. For six 7 segment displays, this means your display refresh rate must be 6*40 = 240 Hz minimum. With a 4.000MHz Xtal, my choice would be 244.14 Hz for the refresh rate. This gives 4096 uS per required refresh. 4096 = 256 * 16, which works out well for TMR0 use (use prescale of 16). You can poll the overflow or set up the interrupts. My clock routines noted above can be adjusted around this prescale as well.

Six displays will require 8 pins for the segments (usually an entire port) (seven if you do not need the decimal point) and 6 lines for the anodes. With this approach, you just update each 7-segment display in turn and all six will look lite.

Some people like to drive displays like yours with drivers. The MAX7219 is really common for this and works great. You also can buy serial LED clock displays. Bruce (big contributer here) at www.rentron.com sells what looks like a nice one (it was featured in Nuts and Volts not too long back).

Lastly, Les Johnson's book “Experimenting with PicBasic Pro” (or some title like that) has a worked out example of multiplexing 7-segment LEDs. I hope this helps and respond if you want more.

precision
- 12th September 2006, 02:56
hi emavil, You can understand in simple way how interrupt usein picbasic pro. read this

http://www.precision.net.in/picbasic/PIC_INT.PDF