Code Issue? - Pin Labels


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2005
    Posts
    44

    Default Code Issue? - Pin Labels

    For some reason the following code has no effect on outputs due to the pin labels:
    Code:
    InpA				VAR	PortB.4
    InpB				VAR PortB.5
    InpC				VAR PortB.6
    InpD				VAR PortB.7
    
    LedA				VAR PortA.2
    LedB				VAR PortA.3
    LedC				VAR PortA.4
    LedD				VAR PortA.5
    
    RlyA				VAR	PortA.6
    RlyB				VAR PortA.7
    RlyC				VAR PortA.0
    RlyD				VAR PortA.1
    
    StatusA				VAR byte		' Port A Status Flag
    StatusB				VAR byte		' Port B Status Flag
    StatusC				VAR byte		' Port C Status Flag
    StatusD				VAR byte		' Port D Status Flag
    
    CurrentPort			VAR byte		' Current Port
    
    StatusA = 0
    StatusB = 0
    StatusC = 0
    StatusD = 0
    
    LedA = 0
    LedB = 0
    LedC = 0 
    LedD = 0
    
    CurrentPort = 1
    
    Goto SetActivePort
    
    checkports:
    
    If InpA = 0 then
    	pause 50
    		If InpA = 0 then
    			StatusA = 0
    			Low LedA
    		endif
    Else
    	StatusA = 1
    	High LedA
    endif
    
    
    If InpB = 0 then
    	pause 50
    		If InpB = 0 then
    			StatusB = 0
    			Low LedB
    		endif
    Else
    	StatusB = 1
    	High LedB
    endif
    
    
    
    If InpC = 0 then
    	pause 50
    		If InpC = 0 then
    			StatusC = 0
    			Low LedC
    		endif
    Else
    	StatusC = 1
    	High LedC
    endif
    
    
    
    If InpD = 0 then
    	pause 50
    		If InpD = 0 then
    			StatusD = 0	
    			Low LedD
    		endif
    Else
    	StatusD = 1
    	High LedD
    endif
    If i Use the following:

    Code:
    
    
    Goto SetActivePort
    
    checkports:
    
    If portb.4 = 0 then
    	pause 50
    		If portb.4 = 0 then
    			StatusA = 0
    			Low PORTB.3
    		endif
    Else
    	StatusA = 1
    	High PORTB.3
    endif
    
    
    If PORTB.5 = 0 then
    	pause 50
    		If PORTB.5 = 0 then
    			StatusB = 0
    			Low PORTB.2
    		endif
    Else
    	StatusB = 1
    	High PORTB.2
    endif
    
    
    
    If PORTB.6 = 0 then
    	pause 50
    		If PORTB.6 = 0 then
    			StatusC = 0
    			Low PORTB.1
    		endif
    Else
    	StatusC = 1
    	High PORTB.1
    endif
    
    
    
    If PORTB.7 = 0 then
    	pause 50
    		If PORTB.7 = 0 then
    			StatusD = 0	
    			Low PORTB.0
    		endif
    Else
    	StatusD = 1
    	High PORTB.0
    endif
    it seems to work fine,
    is there anything obvious that i have missed?

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


    Did you find this post helpful? Yes | No

    Default

    Or i'm Blind OR i'm stupid.. i don't see any reason why it shouldn't work. I use PORT alias every day and never had issue with.

    what are you using
    PIC:
    PBP version:

    what else is bellow your code, you use a goto at the top. How you acces to the Checkports?
    Steve

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

  3. #3
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    In the second program, the HIGH and LOW commands automatically make the pins outputs – you have not set them in the first to output. Add

    Code:
    TRISA = 0 ' make all PORTA output that can be outputs 
              ' (check datasheet depending on your PIC)
    to the first.

    In the second program, you are changing PORTB pins and in the first, PORTA pins. Most PICs default PORTB to digital but many default PORTA to analog. Without knowing what PIC you are using, it is hard to say if this is the issue. Look at this link from MELABS for help on this latter issue. (Pins must be set digital to use them in your manner)

    http://www.melabs.com/support/mcu_hints.htm

    Good Luck,
    Paul Borgmeier
    Salt Lake City, Utah
    USA

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


    Did you find this post helpful? Yes | No

    Default

    yeah but.. Both code use the High LOW statement... one use the PIN alias, not the other.

    I agree with the possibility of the analog stuff on every port, but.. it doesn't explain why the PIN alias don't work but the direct HIGH PORTB.x work ... at least it doesn't make sense to me...

    OK at the begining is the TRIS is not set, the following lines..
    LedA = 0
    LedB = 0
    LedC = 0
    LedD = 0
    won't do anything for sure unless LOW LEDx is used.

    Also we don't know if external pull-up resistor are used.. so that may cause some oddity, and so on
    Last edited by mister_e; - 12th July 2006 at 16:25.
    Steve

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

  5. #5
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Red face

    Quote Originally Posted by mister_e
    Both code use the High LOW statement...
    Wow, coffee please, I missed the scroll bar his code insert on the first program and had not scrolled down to see the rest of his code.

    You are right, we are left with the analog issue as a possible problem. As Steve asked, what PIC and what PBP version?

    Paul

Similar Threads

  1. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 17:11
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  3. Code Issue - select case or 'if' issue - not sure why
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th October 2007, 08:52
  4. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23
  5. Keypad unlock (as in garage door possibly)
    By Fred in forum Code Examples
    Replies: 5
    Last Post: - 2nd April 2006, 04:26

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