PDA

View Full Version : Code Issue? - Pin Labels



jamie_s
- 12th July 2006, 08:50
For some reason the following code has no effect on outputs due to the pin labels:


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:






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?

mister_e
- 12th July 2006, 15:24
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?

paul borgmeier
- 12th July 2006, 16:14
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


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

mister_e
- 12th July 2006, 16:19
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 ;)

paul borgmeier
- 12th July 2006, 16:28
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