IGIF16
Junior Member level 2
hi every one
i have wrote this simple code for two photo sensors to give logic 1 (5V) to Pic16f877 or Pic16f84A every thing is good but my problem if any one of the sensors still given 1 the X or Y will increase by 1 each cycle as the code please help me to overcome on this problem.
the advantage of the two sensor to detect and count the human enter and out a room to switch on or off the lighting.
dim x as short
dim y as short
dim a as byte
dim b as byte
sub procedure interrupt
portb.5 = 1
delay_ms (200)
portb.5 = 0
delay_ms (200)
TMr0 = 0
intcon = $20
end sub
main:
OPTION_REG = $80
trisb = $00
trisa = $FF
x = 0
y = 0
portb.1 = 1
portb.2 = 1
igi:
if porta.0 = 1 then
x = x + 1
y = y - 1
portb.2 = 0
delay_ms (100)
portb.2 = 1
end if
if y < 0 then
y = 0
end if
if porta.3 = 1 then
y = y + 1
x = x - 1
portb.1 = 0
delay_ms (100)
portb.1 = 1
end if
if x < 0 then
x = 0
end if
if x > 0 then
portb.4 = 1
else
portb.4 = 0
end if
if y > 0 then
portb.6 = 1
else
portb.6 = 0
end if
if porta.1 = 1 then
TMR0 = 0
INTCON = $A0
while true
nop
wend
end if
goto igi
end.
the code was written for Pic16f84A8)
i have wrote this simple code for two photo sensors to give logic 1 (5V) to Pic16f877 or Pic16f84A every thing is good but my problem if any one of the sensors still given 1 the X or Y will increase by 1 each cycle as the code please help me to overcome on this problem.
the advantage of the two sensor to detect and count the human enter and out a room to switch on or off the lighting.
dim x as short
dim y as short
dim a as byte
dim b as byte
sub procedure interrupt
portb.5 = 1
delay_ms (200)
portb.5 = 0
delay_ms (200)
TMr0 = 0
intcon = $20
end sub
main:
OPTION_REG = $80
trisb = $00
trisa = $FF
x = 0
y = 0
portb.1 = 1
portb.2 = 1
igi:
if porta.0 = 1 then
x = x + 1
y = y - 1
portb.2 = 0
delay_ms (100)
portb.2 = 1
end if
if y < 0 then
y = 0
end if
if porta.3 = 1 then
y = y + 1
x = x - 1
portb.1 = 0
delay_ms (100)
portb.1 = 1
end if
if x < 0 then
x = 0
end if
if x > 0 then
portb.4 = 1
else
portb.4 = 0
end if
if y > 0 then
portb.6 = 1
else
portb.6 = 0
end if
if porta.1 = 1 then
TMR0 = 0
INTCON = $A0
while true
nop
wend
end if
goto igi
end.
the code was written for Pic16f84A8)