-1

How can I read the first 2 bits from PORTA (RA0, RA1) and then work with them ? I have a switch connected to each one of them, and I want to output a 1 on RB1 when both RA0, RA1 are 1.

I have configured PORTA as input and PORTB as output

MOVLW 0xF 
MOVWF TRISA,0 ;PORTA IN

And then in a loop, I continuously read PORTA values and I want to check if the two lowest bits are at 1. To do so I compare value PORTA with 0x03 after moving PORTA to the WREG.

MOVF PORTA, 0, 0 ;W<--PORTA
CPFSLT 0x20, 0
MOVWF PORTB,0 ;PORTB<--W

In address 0x02 I have previously stored the value 0x03

But it doesn't work, I don't know why.

thanks a lot

sjagr
  • 15,983
  • 5
  • 40
  • 67
Ruben
  • 203
  • 2
  • 9

1 Answers1

0

PORTA bits 0..3 are being configured as inputs but configuring PORTB pins as outputs is not shown. I/O pins are inputs at power up so you must explicitly make them outputs. You say you are continuously looping but don’t show a branch instruction after moving W into PORTB to loop back to read PORTA. And CPFSLT compares to whatever is in 0x20, you have stored 3 in 0x02.

jolati
  • 700
  • 11
  • 19