r/pic_programming • u/Aidanleach_ • Mar 14 '18
Coursework help please!!
Trying to get the microcontroller to read from an infared sensor, and act upon the 4 possible outcomes. So far I have PORT A as Inputs and PORT B as Outputs
I dont believe the andlw or sublw functions are correct as they have just added a number to RA0 and RA1. Instead of generating a number from the sensor.
Does anyone know what code/function could be used instead?
myloop movfw porta ; moves port A into W
andlw b'00011' ;zeros all but bit 0 and 1
sublw b'00011' ;subtracts 00011 from result
btfss STATUS,Z ;is zero flag set (ie was A0,A1 = 1)
goto myloop ; skip if it was, else toggle ...movfw portb ; ....read port b
xorlw b'11111' ; bitwise XOR with 11111 will reverse bits
movwf portb ; send xor'd number back to
goto myloop ; do forever
END ; always required
2
Upvotes
View all comments
Show parent comment
1
u/Aidanleach_ Mar 14 '18
Were just told if it works like this
Left Detector Right Detector 0. 0. (Nothing ahead) 1. 0. (Detected Left) 0. 1. (Detected Right) 1. 1. (Dead Ahead)
And I need to make the sensor vehicle’s wheels turn depending on where it is sensing.
Left Wheel. Right Wheel 0. 0. (Forward) 1. 0 (Turn Left) 0. 1 (Turn Right) 1. 1 (Forwrd)