PicBasic code problems with a 16F84A


Closed Thread
Results 1 to 4 of 4
  1. #1
    Lauren Barta's Avatar
    Lauren Barta Guest

    Default PicBasic code problems with a 16F84A

    Hi Group,

    I'm fairly new at PIC programming and I'm having a problem writing correct
    PicBasic code.
    If someone would be so kind as to tell me what I've done wrong, I'd be
    totally greatful!

    This is how it should work:

    I'm using PortB to read 8 switches. If any of these switches are closed (5
    volts on any PortB pin)
    I want to put 5 volts out on PortA pin 0. This part of my program seems to
    be ok.

    Now, after any or all of the PortB inputs have been high and ALL have gone
    low, I want
    to put 5 volts out on PortA pin 1 for 3 seconds. This part of my program
    seems to fail often!

    Thanks for any help you may be!

    Below, is the code I'm trying to use:

    'The new Komatsu water truck at Wyodak has a serious problem.
    'Drivers have left the water pump switch on with no spray heads
    'turned on. This severly overheats the hydraulic system resulting
    'in pump and valve failures.
    'I've been asked to come up with a fix for it!
    'This device was designed to allow the water pump to only run
    'when at least one of the spray heads is turned on. There is
    'only one exception to this rule. At times, there may be the
    'need to run the pump for fire control. In this case an
    'input from a switch on the console will act as a spray head switch
    'allowing the pump to run.
    'We must provide two outputs, one to turn the pump on (RA0)and another
    'to turn the pump off (RA1 High for 3 seconds)!
    '
    'Designed and Programmed for: Wyodak's Water Truck
    'Code Author: Lauren Barta
    'Designed and edited with: PicBasic
    'Started On: 04/06/2006
    'Modified On: 05/18/2006
    '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''
    Symbol TRISB = 134 'Symbol For TrisB Is Decimal 134
    Symbol TRISA = 133 'Symbol For TrisA Is Decimal 133
    Symbol PORTB = 6 'Symbol For PortB Is Decimal 6
    Symbol PORTA = 5 'Symbol For PortA Is Decimal 5


    Poke 134, 255 'Makes All PortB Pins Inputs
    Poke 133, 0 'Makes All PortA Pins Outputs

    Start:

    Poke 5, 0 'Makes PortA Pins Low
    Pause 10 'Short Pause

    Run:
    LET B2 = 0 'Making B2 a zero
    Pause 10 'Short Pause
    Peek PortB, B0 'Look at PortB, put results in B0
    IF B0 = 0 Then Start 'If all PortB pins are low, go to Start

    Run2: 'Or Run2 if B0 is not equal to zero

    Poke 5, 1 'Makes PortA Pin (RA0) High and will turn the pump on!
    Pause 10 'Short Pause
    Peek PortB, B2 'Look at PortB again, put contents in B2
    Pause 10 'Short Pause
    IF B2 > 0 Then Run 'If B2 is greater than 0, go to run

    Run3: 'Or Run3 if B2 is equal to zero

    Pause 10 'Short Pause
    Poke 5, 2 'Makes RA0 Low and RA1 High and turns the pump off!
    Pause 3000 'Wait 3 seconds
    Call Start 'Start all over again!

    End

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


    Did you find this post helpful? Yes | No

    Exclamation

    Hi Lauren,

    In your code, "Call Start" calls the "start" infinite number of times. In other words, your "call start" calls start inside "start" again and again.

    You might be having problems there (assuming you have no errors in your code).

    There should be a restriction of calling subroutines. Four levels deep for "Gosub", but how many for Call, I am not sure.

    Also, why don't you use "goto start" instead of "call start" ?



    --------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    timmoore47's Avatar
    timmoore47 Guest


    Did you find this post helpful? Yes | No

    Default

    This code is exactly what I needed right now. Whilst I wrote a very longwinded alternate, this is very much smaller and neater!

    Thank you!



    Tim

  4. #4
    mramos's Avatar
    mramos Guest


    Did you find this post helpful? Yes | No

    Default

    Lauren,

    You need to use goto start not call start.

    Call is for assembler calls in PBASIC, I am surpise that the compiler did not throw off an error as _start should not be in the code, but looks like they use it (the _ ) for the goto and calls labels when they build the actually code during compiling...

Similar Threads

  1. PROBLEMS ORDERING PICBASIC PRO mechanique.co.uk
    By Michael Wakileh in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 27th September 2009, 19:11
  2. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. Replies: 6
    Last Post: - 4th April 2007, 07:33
  5. Problems with 16F877A code
    By NightHawk2 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th August 2003, 01:36

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