Accessing I/O from Chuck Hellebuycks book


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Feb 2008
    Posts
    8

    Default Accessing I/O from Chuck Hellebuycks book

    I have problems making this programme work. It is from Chuck Hellebuycks book which I am learning from. When I press the switch both leds go off. I have tried leaving adcon1 = 6 off
    I am using 16f84a instead of 16f876
    Init:
    adcon1 = 6 ' Set all PortA to digital I/O
    trisa = %00000001 ' set PortA RA4-RA1 to outputs, RA0 input
    porta = %00000010 ' Set PortA RA1 high to turn on LED1

    Main:
    ' *** Test the switch state ***
    if portA.0 = 0 then led2 'If switch is pressed then jump to LED2 routine

    PortA.1 = 1 ' Turn LED1 on
    portA.2 = 0 ' Turn LED2 off
    goto Main ' Jump to the top of the main loop

    LED2:
    '*** Turn LED2 on ***
    porta.2 = 1 ' LED2 on
    porta.1 = 0 ' LED1 off
    goto Main ' Jump to the top of the main loop

    Thanks to anybody who can help.

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


    Did you find this post helpful? Yes | No

    Default

    Well sure you have few compilation errors right?

    For a 16F84.. i would check if you have placed some pull-up or pull-down resistor on your push button. Seems you pick up some noise.
    Last edited by mister_e; - 29th March 2008 at 00:28.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Hi quester,
    After installing the pullups, I would put a short pause in the main and in the sub routine just before the goto main statements, to slow down what's happening enough to see it .
    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.

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


    Did you find this post helpful? Yes | No

    Default

    Not a bad idea... but here, as long as the switch will remain at x level, LEDs will remain the same same level too. It's more like a Toggle switch monitor rather than a PushButton monitor... or toggle LEDs each time you press on a PushButtons.

    Nothing critical in this one, no debouncing, nothing fancy.
    Steve

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

  5. #5
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Now works but with 16f876 not 16f84a

    I have now used 16f876 ( it works ok) instead of 16f84a I did try your sugestions but with no luck so I am going to rebuild with 16f84a again and try another pic.
    Thanks for the help.
    Quester.


    NEW MESSAGE: I have now got it working! I rebuilt the circuit and it worked OK but one of the LEDs wasnt quite going off but I was working from the book PIC in Practice and the circuit did not show a wire to ground from Vss I fitted that and it is now OK.
    Last edited by quester; - 29th March 2008 at 20:31. Reason: Make it clear. plus new message

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40

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