Reading if Pin is High or Low?


Closed Thread
Results 1 to 30 of 30

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Code:
    CMCON = 7         ' Disable analog comparator
    TRISA = %11110110 ' set PORTA to input
    TRISB = %11110000 ' set PORTB to output
    
    UP   VAR PORTB.5
    DOWN var PORTB.7
    FM   VAR PORTB.2 
    
    POSITION var word    'Position value 
    VELOCITY var word    'Average velocity value 
    FUNCTION var word    'Function register 
    I        var byte    'Loop variable
    T9600    con 2 ' <== Baudrate definition in case you don't use
                   ' INCLUDE "modedefs.bas" line
    
    MAIN:
        if UP THen
           serout FM, T9600 ,["W01 01 200", CR, LF] 'Write velocity limit value 
           serout FM,T9600,["P01 270000", CR, LF]   'Send MOVETO_ABSOLUTE command
        
           for I = 1 to 100
               pause 25
               serout FM,T9600,["R01 00",CR,LF]
               serout FM,T9600,["R01 14",CR,LF]
               next 
           endif
        
        if DOWN THEN
           serout FM, T9600 ,["W01 01 200", CR, LF] 'Write velocity limit value 
           serout FM,T9600,["P01 0", CR, LF]        'Send MOVETO_ABSOLUTE command
        
           for I = 1 to 100
               pause 25
               serout FM,T9600,["R01 00",CR,LF]
               serout FM,T9600,["R01 14",CR,LF]
               next 
           endif
        
        goto MAIN
    The DEFINE HSER_BAUD 9600 'send serial data at 2400 baud have nothing to do with SEROUT, AND i don't see any crystal speed declaration. @9600 bauds with SEROUT, 8MHZ or higher is highely recommended.
    Last edited by mister_e; - 31st July 2005 at 09:30.
    Steve

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

  2. #2
    Spindle's Avatar
    Spindle Guest


    Did you find this post helpful? Yes | No

    Default

    I am using a PIC16F628 if that helps. It still isn't working for some reason. When i flip the switch nothing happend, but then the motor starts turning in like 30-40 secs. Its weird hehe. Its also 3:40am and getting late. I'll look at it again with fresh eyes in the morning but any more help is still apreciated.

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


    Did you find this post helpful? Yes | No

    Default

    well i don't see any line that show you send any kind of signal to your motor... can you post your whole new and fresh code???

    With fresh eyes... do you see your pull-down resistor attach to the UP, DOWN pins???
    Steve

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

  4. #4
    Spindle's Avatar
    Spindle Guest


    Did you find this post helpful? Yes | No

    Default

    No resisters are attached to the UP and DOWN pins. Does that mean their value is just floating? What value should these resistors be?

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


    Did you find this post helpful? Yes | No

    Default

    YEAH the value is floating and your PIC is between two value, and he see some pink elephant around and he's afraid of.

    Value should be bellow 10K.
    Steve

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

  6. #6
    Spindle's Avatar
    Spindle Guest


    Did you find this post helpful? Yes | No

    Default

    lol alright thanks. I really apreciate your help mister_e. I must have missed your post about the resistors when I was responding. I'll try it in the morning. Thanks again.

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


    Did you find this post helpful? Yes | No

    Default

    No problem. Good night !!!
    Steve

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

Similar Threads

  1. SERIN MIDI out of Synch?
    By jncortes in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 9th June 2009, 20:08
  2. Old and beyond help ?
    By DavidFMarks in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 11th December 2008, 15:23
  3. Pic16f84 and RC5 kode
    By terminator in forum Bluetooth
    Replies: 5
    Last Post: - 18th June 2007, 21:40
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. sample code for M25P32
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th January 2007, 02:37

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