NOOB in need of help


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2009
    Posts
    14

    Default NOOB in need of help

    Hi -
    I am new to PICBasic and to the forums. I have PICBasic Pro if that matters, I am unsure. I am having few problems.

    I want to control few servos based on if this button is pressed etc... To start figure I would use either buttons or switches (same thing) and light up LED's based on if pressed then do kind of thing. Simple enough but for some reason my LED's blink and not just stay lit and trying to figure out why. Attached is an image of my electronics setup and here is my code. Also I am using a PIC16F84A chip and all the examples in books show an external crystal. If anyone knows how to do this without using the external crystal, that would be nice too.

    Please tell me what I am doing wrong and how to do this better. Many thanks!


    main

    if portb.0 = 1 then gosub pressed0
    if portb.0 = 0 then gosub npressed0
    if portb.1 = 1 then gosub pressed1
    if portb.1 = 0 then gosub npressed1
    if portb.2 = 1 then gosub pressed2
    if portb.2 = 0 then gosub npressed2
    if portb.3 = 1 then gosub pressed3
    if portb.3 = 0 then gosub npressed3
    goto main

    pressed0:
    high portb.4
    pause 200
    return

    npressed0:
    low portb.4
    pause 200
    return

    pressed1:
    high portb.5
    pause 200
    return

    npressed1:
    low portb.5
    pause 200
    return

    pressed2:
    high portb.6
    pause 200
    return

    npressed2:
    low portb.6
    pause 200
    return

    pressed3:
    high portb.7
    pause 200
    return

    npressed3:
    low portb.7
    pause 200
    return
    Attached Images Attached Images  

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Welcome.

    Looks like your code is working fine, the LEDs blink because if a button is not pressed it GOSUBs to an LED low command.

    To make all of the LEDs light, get rid of all
    Code:
    if portb.0 = 0 then gosub npressed0
    Make a button when presses GOSUB to an LED_ALL_LOW block.


    To run without a crystal you need a chip with a built in OSC like a 16F676.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jan 2009
    Posts
    14


    Did you find this post helpful? Yes | No

    Red face

    Sounds good.

    How do you make it do one thing when the button is pressed and another when it is not? Like while pressed make a motor run and then stop when not pressed without it being a seprate button?

    Thanks for the help

  4. #4
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Code:
    main:
    
    Pause 200
    
    if portb.0 = 1 then gosub pressed0
    
    if portb.1 = 1 then gosub pressed1
    
    if portb.2 = 1 then gosub pressed2
    
    if portb.3 = 1 then gosub pressed3
    
    goto main
    
    pressed0:
    toggle portb.4
    return
    
    pressed1:
    toggle portb.5
    return
    
    pressed2:
    toggle portb.6
    return
    
    pressed3:
    toggle portb.7
    return
    
    end
    Try this way it should do what you need.

    See TOGGLE command on manual.

    Al.
    Last edited by aratti; - 25th January 2009 at 00:53.
    All progress began with an idea

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by studysession View Post
    Sounds good.

    How do you make it do one thing when the button is pressed and another when it is not? Like while pressed make a motor run and then stop when not pressed without it being a seprate button?

    Thanks for the help
    Your posted code should do that.???
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Dave, let him discover the Toggle instruction.

    Al.
    All progress began with an idea

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by aratti View Post
    Dave, let him discover the Toggle instruction.

    Al.
    Okie Doki
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Jan 2009
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    The toggle wasn't waht I was looking for. I did try it. When you hold down the button and the toggle was going - on/off/on/off etc.....

    Thanks for all the help. I am sure I will be posting more questions as I move forward.

    Thanks again -
    Keith

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


    Did you find this post helpful? Yes | No

    Default Sec.5.36

    Hi Keith,
    Looks like a classic IF THEN ELSE to me.
    Code:
    TRISB = %00001111    ' 4 upper as outputs 4 lower as inputs
    IF  PortB.0 = 1 THEN ' if true then goto next statement
    PortB.4 = 1          ' turn on this port 
    ELSE                 ' goes to here if false
    PortB.4 = 0          ' Turns this port off
    ENDIF                ' ends the if then test for true / false and allows code to continue
    make sure to use resistors pulling down if you close switches to activate or pulling up if you open switches to activate.
    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.

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


    Did you find this post helpful? Yes | No

    Default

    Not sure at all but...
    Code:
            TRISB=%00001111
            PORTB=0
    
    Loop:
            PORTB=(PORTB<<4)
            PAUSE 200
            GOTO Loop
    Steve

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

Similar Threads

  1. LCD_AnyPin.pbp
    By Darrel Taylor in forum PBP Extensions
    Replies: 112
    Last Post: - 23rd September 2024, 18:06
  2. Replies: 2
    Last Post: - 7th March 2008, 02:16
  3. Help a noob out?
    By yasiryassin in forum mel PIC BASIC
    Replies: 2
    Last Post: - 15th January 2008, 06:37
  4. Crystals & Caps - Super noob question??
    By kevj in forum General
    Replies: 4
    Last Post: - 24th September 2007, 17:11
  5. Uber noob needs clarity!
    By bill12780 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 23rd July 2007, 21: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