? on code


Closed Thread
Results 1 to 11 of 11

Thread: ? on code

  1. #1
    Join Date
    Mar 2004
    Posts
    92

    Unhappy ? on code

    Hi all,
    I just started with PBP and an EPIC.

    I'm using a 16f84a and I need to have it go high on b.0 for say 1 minute and then go low. All this needs to happen after b.1 goes high and stays high.

    Can someone please give me an example code on how to do this?

    Thanks,
    Sam

  2. #2
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    i Var Byte

    Loop:

    If PortB.1=1 Then

    Hgh PortB.0

    for i=1 to 60
    Pause 1000
    next

    Low PortB.0

    EndIf

    Goto Loop

  3. #3
    Join Date
    Mar 2004
    Posts
    92


    Did you find this post helpful? Yes | No

    Thumbs up

    That did it !

    Thank you very much NavMicroSystems.

    I'm sure I'll have more ?.

    Thanks again,
    Sam

  4. #4
    Join Date
    Mar 2004
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    Well,
    I thought that did it.
    Only problem is that the 60 second timing starts (after) high is removed from B.1.

    As long as B.1 is high, B.0 stays high.

    I've tried modifying but haven't got it yet.

    Any suggestions ?

    Sam

  5. #5
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    There are many ways, here is one:

    this variant sets PortB.0 High for 60 secs. after PortB.1 has gone High.
    Then it loops in the DoNothing loop until PortB.1 has gone low again.
    Setting PortB.1 high again restarts the process.



    i Var Byte

    Loop:

    If PortB.1=1 Then

    High PortB.0

    for i=1 to 60
    Pause 1000
    next

    Low PortB.0

    EndIf


    DoNothing:
    If PortB.1=1 Then
    Goto DoNothing
    EndiF

    Goto Loop
    Last edited by NavMicroSystems; - 7th March 2004 at 17:45.

  6. #6
    Join Date
    Mar 2004
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    OK,
    That "almost" does it. But when B.1 goes low again,B.0 reruns the same routine as it does when B.1 goes high.

    I tried more code variations on my own and have been through the manual several more times and I've not got it figured out.

    Please be patient with me,I WILL learn this.

    Your help is much appreciated,
    Sam

    EDIT: I got b.0 to stay low when B.1 went low by looping IF B.0=0
    But, now when B.1 goes high again,B.0 stays low. I need it to re-run each time B.1 goes high.

    Thanks
    Last edited by Sam; - 7th March 2004 at 19:07.

  7. #7
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    How are you setting B.1 low or high ?
    are you using a button?

    It looks like your "Switch" bounces when toggling.
    means it very quickly changes between on and off before it reaches its final position.

    The program is that fast that it detects this change.

    you need to eliminate that "Key-bounce"

    here is one possible way:

    i Var Byte

    Loop:

    If PortB.1=1 Then 'Check HIGH on B.1
    Pause 500 ' wait 500ms (you can certainly decrease the Pause time

    If PortB.1=1 Then ' Is B1 still HIGH ?

    High PortB.0

    for i=1 to 60
    Pause 1000
    next

    Low PortB.0

    EndIf
    EndIf


    DoNothing:
    If PortB.1=1 Then
    Goto DoNothing
    EndiF

    Goto Loop


    Key bounce is actually a "mechanical" problem you have to think of when working with buttons.

    Your other questions were regarding basic BASIC stuff.

    Now that you have got some examples try to modify the code.
    i.e. use the BUTTON statement.
    Last edited by NavMicroSystems; - 7th March 2004 at 20:33.

  8. #8
    Join Date
    Mar 2004
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    I'm setting B.1 low with a 5k resistor to gnd. and high with wire inserted into breadboard.I'm sure the wire is far worse than a button. I had just tried this:


    i Var Byte

    Loop:

    If PortB.1=1 Then

    High PortB.0

    for i=1 to 60
    Pause 1000
    next

    Low PortB.0

    EndIf


    DoNothing:
    If PortB.1=1 Then
    Goto DoNothing
    EndiF

    low 0 }I added this
    pause 500 } "

    if portb.0=0 then} "
    Goto Loop

    endif

    I'm sure you're right about the "bounce" as this fixed the problem.
    I'll try your code instead though.
    The high to B.1 will actually come from an optoisolator in the final stage. I've got alot more code to figure out on this project and if you or anyone can recomend a book that would help,please do.
    Thanks,
    Sam

    NavMicroSystems,I just sent you a PM.
    Last edited by Sam; - 7th March 2004 at 22:12.

  9. #9
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    You could try the following books:

    Programming PIC Microcontrollers With PicBasic by: by Chuck Hellebuyck
    Experimenting with the PicBasic Pro Compiler by: Les Johnson

    I have read about them, but I haven't read the books themselves.
    (some people may say: it would have been better I had read the books)

    Another way of learnig is once you have got a bit familiar with PBP and the PIC Hardware:
    look at the many code examples available and try to understand what they are doing (or are supposed to do) rather than just copying them into into your project.

    Adittional recommendations:

    Try MicroCode Studio http://www.mecanique.co.uk
    This is really a great Product and the "Plus" version is worth the money.
    The ICD Feature saves a lot of time when debugging.

    For small projects try the 16F628 (or even smaller: 12F675)
    The 16F628 has more features than the 16F84 and is even cheaper!
    And it does not need external parts like a crystal.

    If you need more I/O Pins go for the 16F868 / 16F877.

    Take care with the 18F series, they appear to be a bit "tricky"
    (I'm currently struggling to migrate one of my projects from 16F876 to 18F252.)

  10. #10
    Join Date
    Mar 2004
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    Thank you very much,You've been a big help.
    I'm sure I'll have more questions though.And I'll check out your recomendations.

    Sam

  11. #11
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    SAM, check PM

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23

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