New to PICBASIC Pro and have simple question


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Jan 2008
    Location
    Vassar, Michigan USA
    Posts
    9


    Did you find this post helpful? Yes | No

    Default RE: Relay

    I would probably just turn the port on, wait and then turn if off:

    if portb.0 = 1 then
    portd.0 = 1 'turn on port d bit 0
    PAUSE 100
    portd.0 = 0 'turn it back off after 100 ms
    endif

    modifiying this idea with my variable makes it a one-shot deal, so the output only pulses once on the low-going transistion, but does nothing when the user releases the button.

    buttonState VAR BIT

    START:
    if portb.0 <> buttonState then
    buttonState = portb.0
    if buttonState = 0 then 'user is pushing on button
    portd.0 = 1
    PAUSE 100
    portd.0 = 0
    endif
    endif

    Unfortunately all of the bits on a PIC are latching. So if you want them to be a one-shot blink, then you have to code them to do it. I would try to avoid using the HIGH and LOW commands, unless you intend to use the basic stamp compatability files. These can add some overhead to your compiled program that goes onto your chip.

    The pause command also affects how the PIC performs in real-time as the world has to stop inside the pic for this command to execute.
    Last edited by Jasonce65; - 22nd January 2008 at 01:12. Reason: update

  2. #2
    Join Date
    Nov 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default Thanks,

    That's what I thought the best option would be but wanted to make sure.

    Yeah I alway's use it by bit and create variables because sometimes Mouser runs out of chips I need and I have to get a near compatible one.

    I also only use the PAUSEUS so that the pic doesn't go to sleep.

    Thank you for your help. I will try and do it this way and maybe, just maybe, it will function as desired.

  3. #3
    Join Date
    Jan 2008
    Location
    Vassar, Michigan USA
    Posts
    9


    Did you find this post helpful? Yes | No

    Default logical operators

    keep in mind that if your're working with more than one input, one that is an "enable", for example, that you can use a logical operator to make some magic...


    if portb.0 <> buttonState AND portd.3 = 1 THEN... etc.

    In one case I needed to validate what was going on with a variable that came from the HSERIN and had to use some intense logic...

    If (BtVar = 48 AND porte = 0) OR (BtVar = 49 AND porte = 1) OR (BtVar = 50 AND porte = 2) ... THEN...

    This let me match the port e value to the character that came in on the serial port. Since Port e on an 16F877A is 3 bits, I needed to compare for all 8 values using this if-then. It's incredible what tis complier and the chips, for that matter can do!

    good luck.
    J.-

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