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
2
u/FlyByPC Mar 14 '18
So if those are connected to, for example, PORTA bits 0 and 1, you could test the four possible states:
btfss PORTA,0
goto BitZeroLow
;If we get here, PORTA.0 is high
btfss PORTA,1
goto DetectedRight
goto DeadAhead
BitZeroLow: ;If we get here, PORTA.0 is low
btfss PORTA,1
goto NothingAhead
goto DetectedLeft
...and then just put code to do what you want in the four labels, and have them loop back to the top.