PIC16F84(A) counter


Closed Thread
Results 1 to 3 of 3
  1. #1
    nmmr's Avatar
    nmmr Guest

    Unhappy PIC16F84(A) counter

    Hi there to you all

    I've a question, that maybe anyone can help...

    I want to make a counter/display, that has to be able to display a number from 1 to 512, at users choice, store it on eeprom, for later use and if the user wants, he can make it go up or down, by a push button.
    Ex. it is displaying "050" and when we push the up button it should show "051", or in the other way "049", flash 4 or 5 times, and then show it continuasly, and storing it for later. For now, for testing I'm using a constant value.

    I had read that in 16F84 I can use the EREAD and EWRITE to store my variable in the eeprom, so that when I power off the circuit, it stays there for later reading it.

    I already try to display some digits to 3 - 7 segment displays, using 4 data lines through a 4511, and 3 transistors for multiplexing, and I'm using the folowing sub-routine code to do that:

    DEVICE = 16F84a
    XTAL = 4

    DIM ST_ADRESS AS WORD
    DIM N_CHANS AS BYTE
    DIM VEZ AS BYTE
    DIM CENTENAS AS BYTE
    DIM DEZENAS AS BYTE
    DIM UNIDADES AS BYTE
    DIM DIGIT AS BYTE
    SYMBOL UP_ADRESS PORTA.1
    SYMBOL DW_ADRESS PORTA.0


    DELAYMS 600 'ESPERAR POR ESTABILIZAÇÃO DO PIC
    GOSUB TESTE_DISPLAY
    ST_ADRESS = 95 'EREAD 0
    N_CHANS = 1
    IF ST_ADRESS > 512 - N_CHANS THEN
    ST_ADRESS = 512 - N_CHANS
    END IF

    DELAYMS 1500


    TEST_ADRESS:
    IF UP_ADRESS = 1 OR DW_ADRESS = 1 THEN
    STOP
    ELSE
    GOSUB MOSTRA_DISP
    GOTO TEST_ADRESS
    END IF

    STOP

    TESTE_DISPLAY:
    FOR VEZ = 1 TO 4
    CLEAR PORTB 'LIMPAR PORTA
    DELAYMS 500
    HIGH PORTB.4 'ACTIVAR DISPLAYS
    HIGH PORTB.5
    HIGH PORTB.6
    LOW PORTB.0 'ESCREVER 888s
    LOW PORTB.1
    LOW PORTB.2
    HIGH PORTB.3
    NEXT
    RETURN

    MOSTRA_DISP:
    IF ST_ADRESS < 100 THEN
    CENTENAS = 0
    DEZENAS = ST_ADRESS DIG 1
    UNIDADES = ST_ADRESS DIG 0
    ELSEIF ST_ADRESS < 10 THEN
    CENTENAS = 0
    DEZENAS =0
    UNIDADES = ST_ADRESS
    ELSE
    CENTENAS = ST_ADRESS DIG 2
    DEZENAS = ST_ADRESS DIG 1
    UNIDADES = ST_ADRESS DIG 0
    END IF

    FOR VEZ = 1 TO 3
    IF VEZ = 1 THEN
    HIGH PORTB.4
    DIGIT = CENTENAS
    ELSEIF VEZ = 2 THEN
    HIGH PORTB.5
    DIGIT = DEZENAS
    ELSE
    HIGH PORTB.6
    DIGIT = UNIDADES
    END IF
    SELECT DIGIT
    CASE 0
    LOW PORTB.0
    LOW PORTB.1
    LOW PORTB.2
    LOW PORTB.3
    CASE 1
    HIGH PORTB.0
    LOW PORTB.1
    LOW PORTB.2
    LOW PORTB.3
    CASE 2
    LOW PORTB.0
    HIGH PORTB.1
    LOW PORTB.2
    LOW PORTB.3
    CASE 3
    HIGH PORTB.0
    HIGH PORTB.1
    LOW PORTB.2
    LOW PORTB.3
    CASE 4
    LOW PORTB.0
    LOW PORTB.1
    HIGH PORTB.2
    LOW PORTB.3
    CASE 5
    HIGH PORTB.0
    LOW PORTB.1
    HIGH PORTB.2
    LOW PORTB.3
    CASE 6
    LOW PORTB.0
    HIGH PORTB.1
    HIGH PORTB.2
    LOW PORTB.3
    CASE 7
    HIGH PORTB.0
    HIGH PORTB.1
    HIGH PORTB.2
    LOW PORTB.3
    CASE 8
    LOW PORTB.0
    LOW PORTB.1
    LOW PORTB.2
    HIGH PORTB.3
    CASE 9
    HIGH PORTB.0
    LOW PORTB.1
    LOW PORTB.2
    HIGH PORTB.3
    END SELECT
    NEXT
    RETURN

    I know, that there is some things left to do, but i'm trying one thing at time.

    My problem is, how do I do the flashing of the user set number, and always showing/flashing it, and then go back again to normal mode... Do I have to use timers or something?

    Any help will be good

    Nuno

  2. #2
    nmmr's Avatar
    nmmr Guest


    Did you find this post helpful? Yes | No

    Lightbulb I forgot one thing

    For all of you to understand

    CENTENAS - hundreds, holds the hundred digit of the number
    DEZENAS - sets of tens
    UNIDADES - units

    Sorry, I'm from Portugal...

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


    Did you find this post helpful? Yes | No

    Default

    Hi,
    we can for sure help you if you're using Melabs PICBASIC PRO. BUT in your case, you should post your question Here
    Steve

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

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. Counter not counting !!!
    By lerameur in forum mel PIC BASIC Pro
    Replies: 24
    Last Post: - 20th February 2009, 22:15
  3. 20 Digit Virtual LED Counter
    By T.Jackson in forum Code Examples
    Replies: 9
    Last Post: - 19th November 2007, 05:02
  4. Replies: 3
    Last Post: - 17th August 2007, 20:39
  5. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27

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