Connect with us

PIC 16F84A program help request.

Discussion in 'Electronic Basics' started by Anthony Fremont, Dec 5, 2004.

Scroll to continue with content
  1. Without a schematic and your source code, it will be quite difficult to
    debug this from here. ;-) However, it sounds from your description
    like the watch-dog timer could possibly be the problem. Make sure that
    it is disabled.
    It won't hurt.
     
  2. Rubicon

    Rubicon Guest

    Hello,

    I'm in the process of learning to program the 16F84A PIC. I understand
    that it's "old hat" but the PIC came with the programmer and they were
    out of stock of the 16F628A PICs. I currently have an old version of
    PicBasic Pro which can handle up to 16F84 PICs but seems to program
    the 16F84A O.K. Once I'm familiar with the basics I'll probably
    upgrade to the Oshon Pic Simulator IDE for the 16F628A.

    I've decided to do a project for someone else to help me learn and so
    far after much effort I'm gotten almost nowhere.

    The project is a 10 LED bargraph indicator timed over 10 seconds. The
    10 LEDs should light or extinguish at one second intervals according
    to the pressing of Button#1 (Down) and Button#2 (Up).

    I have written some code using the PULSIN command and IF-THEN
    statements to light the LEDs but I can only get the first LED lit
    before it has to return to the main loop and start again. Forever
    going through the first If-THEN and no further.

    How do I go about making this work? Does anyone have some sample code
    I could adapt?

    Any help is greatly appreciated here.

    In addition though it's not shown in the schematics I assume that a
    bypass cap is required across a PICs V+/V-. Correct?

    Cheers,

    Andrew.
     
  3. Rubicon

    Rubicon Guest

    Anthony,

    Thanks for the reply.

    The Pic is set up with a 4Mhz crystal with 33pF ceramic caps on
    Pins#15 and 16. A 4K7 resistor from 5V+ goes to a tactile switch to V-
    with a 100ohm resistor at the junction to PIN#4 MCLR. Pin#14 Vdd goes
    to V+ with a 0.1uF ceramic cap to V-. RB0 and RB1 have 10K resistors
    and tactile switches for positive pulses and RB2 is connected directly
    to a small transducer. RB3/4/5/6/7 go to 330ohm resistors and LEDs to
    V-. I haven't connected any more LEDs since I can't get past RB3/LED#1


    The code is almost too embarrassing to post but in my defence it's
    over twenty years since I last tried BASIC and COBOL at school. I
    believe I'm getting better... I would hope so! Can't think of a way
    past the IF_THENs or another way to do it.

    Any advice, pointers appreciated.

    Andrew.



    ''''''''''''''''''''''''''
    ' LED INDICATOR '
    ''''''''''''''''''''''''''
    'Ten second, ten LED, one second increment/decrement incicator.
    'If Button#1 depressed for over 10 seconds the excess is ignored.


    DEFINE LOADER_USED 1


    ''''''''''''''''''''''''''
    ' HARDWARE STARTUP SETUP '
    ''''''''''''''''''''''''''

    TRISA = %00000 'Set PORTA to all output
    PORTA = 0 'PORTA (133) outputs off
    TRISB = %00000011 'Set PORTB to all output but RB0 and RB1
    PORTB = 0 'PORTB (134) outputs off
    CLEAR 'Clear all vairables and buffers


    ''''''''''''''''''''''''
    ' INITIALIZE VAIRABLES '
    ''''''''''''''''''''''''
    W0 VAR WORD '16 bit PULSIN vairable
    W1 VAR WORD '16 bit PULSIN vairable
    W2 VAR WORD '16 bit time vairable


    ''''''''''''''''
    ' STARTUP BEEP '
    ''''''''''''''''
    GOSUB BEEP 'Sound a double beep on PORTB RB2


    ''''''''''''''''
    ' MAIN PROGRAM '
    ''''''''''''''''
    LOOP1:

    W0 = 0 'Zero W0
    PULSIN 0,1,W0 'BUTTON#1 on RB0, measure high pw to W0
    W2 = W2 + W0 'Add W0 to W2

    W1 = 0 'Zero W1
    PULSIN 1,1,W1 'BUTTON#2 on RB1, measure high pw to W1
    W2 = W2 - W1 'Subtract W1 from W2

    IF W2 >= 100 THEN LED1 'One second
    IF W2 >= 200 THEN LED2
    IF W2 >= 300 THEN LED3
    IF W2 >= 400 THEN LED4
    IF W2 >= 500 THEN LED5

    'IF W2 >= 600 THEN LED6
    'IF W2 >= 700 THEN LED7
    'IF W2 >= 800 THEN LED8
    'IF W2 >= 900 THEN LED9
    'IF W2 >= 1000 THEN LED10 'Ten seconds
    GOTO LOOP1


    LED1:
    PORTB.3 = 1 'Light LED1 - 1 sec
    GOTO LOOP1

    LED2:
    PORTB.4 = 1 'Light LED2 - 2 sec
    GOTO LOOP1

    LED3:
    PORTB.5 = 1 'Light LED3 - 3 sec
    GOTO LOOP1

    LED4:
    PORTB.6 = 1 'Light LED4 - 4 sec
    GOTO LOOP1

    LED5:
    PORTB.7 = 1 'Light LED5 - 5 sec
    GOTO LOOP1


    'LED10:
    'PORTA??? 'Light LED10 - 10 sec
    'W2 = 1000 'Set time to 10 seconds
    'GOSUB BEEP 'Max time warning beep
    'GOTO LOOP1


    END


    '''''''''''''''
    ' SUBROUTINES '
    '''''''''''''''

    BEEP:
    SOUND PORTB.2, [120,10,60,10] 'Sound a double beep on PORTB RB2
    RETURN
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-