im trying to design a program for a pic 16f628 which will read five switches from portB (RB0 - RB4) and then output the binary equivalent to 3 leds on portb (RB5 - RB7). Eg, if switch 5 was high then the output would be 101.
I have written this program but have no equipment to test it at the moment. Im Just wondering if anyone can look it over and see whether im on the right track. Thanks.
I have written this program but have no equipment to test it at the moment. Im Just wondering if anyone can look it over and see whether im on the right track. Thanks.
Code:
;*************************************************************
;SETUP PROCEDURE
ORG 0X000
BANK1
MOVLW 0XE0
MOVWF TRISB ;SET PORTB I/O PINS TO 5 INPUTS (RB0 - RB4) AND 3 OUTPUTS (RB5 - RB7)
BANK0
;************************************************************
;MAINLINE PROCEDURE
MAIN
MOVF PORTB,0 ;GET DATA ON PORTB
ANDLW 0X1F ;MASK LAST 3 BITS OF PORTB (RB5 - RB7)
CALL TABLE ;CALL TABLE AND GET BINARY VALUE
MOVWF PORTB ;MOVE VALE RETURNED FROM TABLE TO PORTB
GOTO MAIN ;START AGAIN
;*************************************************************
;LOOK UP TABLE PROCEDURE
TABLE
ADDWF PCL ;ADD VALUE FROM PORTB TO PROGRAM COUNTER
RETLW 0XFF
RETLW 0X20 ;VALUE FOR 001
RETLW 0X40 ;VALUE FOR 010
RETLW 0XFF
RETLW 0X60 ;VALUE FOR 011
RETLW 0XFF
RETLW 0XFF
RETLW 0XFF
RETLW 0X80 ;VALUE FOR 100
RETLW 0XFF
RETLW 0XFF
RETLW 0XFF
RETLW 0XFF
RETLW 0XFF
RETLW 0XFF
RETLW 0XFF
RETLW 0XA0 ;VALUE FOR 101
END