PDA

View Full Version : for loop high



ilteris
- 17th October 2005, 21:20
hi list I a trying to do a for loop which should light up all the leds in my portC.

If I can manage to do that then I am going to try to control them with my subRoutine, but the problem is when I run this code I have only my last pin at high, I understand it from the only led that lights is that one. I tried this code with pause between the for loops and I have found at for loop is working quite ok but they are getting in high position and then to low position, that is what I didnt get in here, if anyone point me in a right direction, i will be grateful.

ilteris\



k var byte 'loop var
j VAR byte 'loop var
l var byte
tempV var byte
inputPin var portb.0 'define base point for input
outputPin var portc.0 'define base point output
'ADCON1 = 7
'trisa = %00000000
trisb = %11111111
trisc = %00000000
'trisd = %00000000
loop:
'porta = 0
portc = %11111111
'portd = 0

for k = 0 to 7 'this accesses port c
if outputPin(k) = 4 then
outputPin(k) = 0
else
outputPin(k) = 1 ' set pin high

pause 1
endif
next k

for j = 0 to 7
if inputPin(j) = 1 then
tempV = j
'gosub readAround
endif
Next j

goto loop
end


readAround:
for l = 0 to 7
if inputPin(l) = 1 and l!= tempV then
outputPin(l) = 1
endif
next l
return