Dual 7-segment LED display counter


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2008
    Posts
    6

    Default Dual 7-segment LED display counter

    hello,
    i'm a newbie in programming pic. I want make a dual 7-segment LED display counter and update it every 1 sec for show i the display 00 , 01 , 02 ecc. The code that i use found it in internet and is make for a 16F627 , i try this
    code with my 16F88 but the display update is very slow abuot every 2.5 sec
    and not every 1 sec. Why happened this?. I use a 4MHz external crystal like
    for the 16F627.

    please help me
    Thank


    Cnt VAR Byte ' Cnt is a byte variable
    Digit VAR Byte ' Digit is a byte variable
    Pattern VAR Byte ' Pattern is a byte variable
    Digit1 VAR PORTA.0 '' Digit 1 enable bit
    Digit2 VAR PORTA.1 ' Digit 2 enable bit
    First VAR Byte ' First is a byte variable
    Second VAR Byte ' Second is a byte variable
    i VAR Word ' i is a word variable



    CMCON = 7 ' RA0-RA3 are digital I/O
    TRISA = 0 ' Set PORTA as output
    TRISB = 0 ' Set all PORTB pins as outputs

    ' Enable TMR0 timer interrupts

    INTCON = %00100000 ' Enable TMR0 interrupts
    OPTION_REG = %00000111 ' Initialise the prescale

    TMR0 = 217 ' Load TMR0 register

    ON INTERRUPT GOTO ISR
    INTCON = %10100000 ' Enable Interrupts

    LOOP:

    Cnt = 0 ' Initialise Cnt to 0
    NXT:
    Digit = Cnt DIG 0 ' Get 10s digit
    GOSUB CONVERT ' Get segments to turn on
    First = Pattern ' Display 10s digit
    Digit = Cnt DIG 1 ' Get 1s digit
    GOSUB CONVERT ' Get segments to turn on
    Second = Pattern ' Display 1s digit


    FOR i = 1 to 1000
    Pause 1 ' Wait 1 second
    NEXT i

    Cnt = Cnt + 1 ' Increment Cnt
    IF Cnt > 99 THEN LOOP ' If Cnt > 99 then goto LOOP
    GOTO NXT ' Continue

    '
    ' This is the Interrupt Service Routine (ISR). The program jumps to this
    ' routine whenever a timer interrupt is generated.
    '
    DISABLE ' Disable further interrupts

    ISR:
    TMR0 = 217

    PORTB = First

    Digit2 = 0
    Digit1 = 1
    PAUSE 5

    Digit1 = 0
    PORTB = Second
    Digit2 = 1

    PAUSE 1

    INTCON.2 = 0 ' Re-enable TMR0 interrupts
    RESUME ' Return to main program
    ENABLE 'Enable interrupts

    CONVERT:

    LOOKUP Digit, [$01,$4f,$12,$06,$4c,$24,$60,$0f,$00,$0c], Pattern

    RETURN
    END ' End of program

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Read and understand this thread:http://www.picbasic.co.uk/forum/showthread.php?t=543
    The PIC you have chosen has a fail safe oscillator which works when the primary osc fails, like when it is not configured properly. Download the data sheets and study.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Default

    Certainely not a bad idea to begin with a LED blink to see if it's only a crystal or config fuses setting problem.

    This PIC also have Analog to Digital converter, which needs to be disabled prior to use I/Os.

    Check the datasheet
    Code:
    ANSEL=0
    Steve

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

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Certainly not a bad idea to begin with a LED blink to see if it's only a crystal or config fuses setting problem.

    This PIC also have Analog to Digital converter, which needs to be disabled prior to use I/Os.

    Check the datasheet
    Code:
    ANSEL=0
    Yup! , he did say it was working, so I didn't look any farther, those are the problems you encounter when you copy / paste without any experience, GOOD IDEA to write a blinky.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Apr 2008
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    thank for help me!

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 07:14
  2. Single digit 7 Seg LED clock - PIC16F88
    By thirsty in forum Code Examples
    Replies: 4
    Last Post: - 17th July 2009, 09:42
  3. Weird compile issue 7 segment LED display
    By George in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st June 2006, 03:12
  4. 7 segment digit problem (using Mister E's code)
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 9th September 2005, 21:25
  5. WRITE not working
    By servo260 in forum mel PIC BASIC Pro
    Replies: 31
    Last Post: - 29th December 2004, 03:02

Members who have read this thread : 1

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