Programming TMR0 Interrupt in PICBasic


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2006
    Posts
    31

    Question Programming TMR0 Interrupt in PICBasic

    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?

  2. #2
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3
    ra68gi's Avatar
    ra68gi Guest


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    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.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  5. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Display Example, to drive LED displays

    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.


    Code:
    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.


    ________________________--
    Last edited by sayzer; - 6th September 2006 at 19:22.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    (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.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  8. #8
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    89


    Did you find this post helpful? Yes | No

    Default

    hi emavil, You can understand in simple way how interrupt usein picbasic pro. read this

    http://www.precision.net.in/picbasic/PIC_INT.PDF
    Last edited by precision; - 12th September 2006 at 04:18.

Similar Threads

  1. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  2. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  3. TMR0 interrupt and HSERIN
    By boban in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd September 2008, 11:48
  4. help: TMR0 interrupts disabling PORTAchange interrupts???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th August 2008, 15:10
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts