16f628, please help with the code

Thread Starter

Gag14

Joined Jan 23, 2018
23
Hi all
I trying to build a receiver with a pass code, a simple one .
The transmitter sends the code , and the receiver has dip switches to put the code .
I stuck on dip switches, how to put data from the switches? please help
here is a part of the code ,where I need help .

receive
btfss PIR1,RCIF; check for received data
goto receive
movf RCREG,W
ANDLW 0x0F ; mask out 4 upper bits
CALL CHK
BTFSS STATUS, Z ;
GOTO receive; keep recieving
PASS
BSF PORTA,7 ; pass ok
GOTO PASS
;--------------------------------
CHK
XORLW B'00000101' ; PASSCODE
RETURN

How put data from from the switches to PASSCODE
I have the switches on PORTA 0,1,2,3
Thank you
 

Thread Starter

Gag14

Joined Jan 23, 2018
23
movf PORTA, w
andlw 0x0F
movwf PASSCODE
thank you , maybe I didnt explain it correctly .
RCREG,W has 8 bit info , the first 4 is the pass code .
so I masked the 4 upper bits , and now I need to check if the code from transmitter match the dip switches on the receiver .
so I am using XOR instruction to check . the question is how to put data from the switches to this line XORLW B'0000xxxx ;

CHK
XORLW B'0000xxxx ; PASSCODE
RETURN
 

Thread Starter

Gag14

Joined Jan 23, 2018
23
movf PASSCODE, w
xorwf RCREG, w
thanks I will try right now

Here is how I put it together , doesnt work ...

receive
btfss PIR1,RCIF; check for received data
goto receive
movf RCREG,W
ANDLW 0x0F ; mask out 4 upper bits
CALL CHK
xorwf RCREG,W
BTFSS STATUS, Z ;
GOTO receive; keep recieving
PASS
BSF PORTA,7 ; pass ok
GOTO PASS
;--------------------------------
CHK
movf PORTA, w; READ SWITCHES
andlw 0x0F
movwf PASSCODE
movf PASSCODE,W

RETURN
 
Last edited by a moderator:

AlbertHall

Joined Jun 4, 2014
12,625
Delete the four marked lines and three new ones:

receive
btfss PIR1,RCIF; check for received data
goto receive
movf RCREG,W <= delete this line
ANDLW 0x0F ; mask out 4 upper bits <= delete this line
CALL CHK
xorwf RCREG,W <= delete this line

; add these lines
movf RCREG, w
andlw 0x0F
xorwf PASSCODE
;
BTFSS STATUS, Z ;
GOTO receive; keep recieving
PASS
BSF PORTA,7 ; pass ok
GOTO PASS
;--------------------------------
CHK
movf PORTA, w; READ SWITCHES
andlw 0x0F
movwf PASSCODE
movf PASSCODE,W <= delete this line

RETURN
 

Thread Starter

Gag14

Joined Jan 23, 2018
23
hi Gag,
Think what the Op code XORLW means,, literal ?

E

EDIT:
http://microcontrollerslab.com/pic-microcontroller-assembly-language/
THANK YOU

AlbertHall
Thank you very much for help !
You gave me the idea , I modified your code and it did work .thanks again

Delete the four marked lines and three new ones:

receive
btfss PIR1,RCIF; check for received data
goto receive
movf RCREG,W <= delete this line
ANDLW 0x0F ; mask out 4 upper bits <= delete this line
CALL CHK
xorwf RCREG,W <= delete this line


; add these lines
movf RCREG, w
andlw 0x0F
xorwf PASSCODE
;
BTFSS STATUS, Z ;
GOTO receive; keep recieving
PASS
BSF PORTA,7 ; pass ok
GOTO PASS
;--------------------------------
CHK
movf PORTA, w; READ SWITCHES
andlw 0x0F
movwf PASSCODE
movf PASSCODE,W <= delete this line

RETURN
thanks I will try this part too

I tried this part and it works too .Great help, thanks
 
Last edited by a moderator:

Thread Starter

Gag14

Joined Jan 23, 2018
23
Now the tricky question. Do you understand why it didn't work and why it does now?
sure I do ,
when it didnt work , I modified it in my way , it did work too ,
but I think I am going to use your version .

I see you dont mind to help , some people here just point on Google search , which means no help
 
Top