LIST p=16F628 ;tell assembler what chip we are using
include "P16F628.inc" ;include the defaults for the chip
__config 0x3D18 ;sets the configuration settings (oscillator type etc.)
cblock 0x20 ;start of general purpose registers
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
count ;MAIN 14 COUNT
endc
LEDPORT Equ PORTB ;set constant LEDPORT = 'PORTB'
LEDTRIS Equ TRISB ;set constant for TRIS register
SWPORT Equ PORTA
SWTRIS Equ TRISA
SW1 Equ 4 ;set constants for the switches
LED1 Equ 3 ;and for the LED's
LED2 Equ 2
LED3 Equ 1
LED4 Equ 0
org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
;this is where the program starts running
movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)
bsf STATUS, RP0 ;select bank 1
movlw b'00000000' ;set PortB all outputs
movwf LEDTRIS
movlw b'11110000' ;set PortA 4 inputs, 4 outputs
movwf SWTRIS
bcf STATUS, RP0 ;select bank 0
clrf LEDPORT ;set all outputs low
clrf SWPORT ;make sure all LED's are off
BSF SWPORT, LED1
start1 CLRF count
MOVFW count
Start movfw count
btfsc SWPORT, LED1 ;check which LED is lit
call Table1 ;and read the associated table
btfsc SWPORT, LED2
call Table2
btfsc SWPORT, LED3
call Table3
btfsc SWPORT, LED4
call Table4
movwf LEDPORT
incf count, w
xorlw d'14' ;check for last (14th) entry
btfsc STATUS, Z
goto start1 ;if start from beginning
incf count, f
CALL DELAY
GOTO Start
Table1 ADDWF PCL, f ;data table for bit pattern
retlw b'10000000'
retlw b'01000000'
retlw b'00100000'
retlw b'00010000'
retlw b'00001000'
retlw b'00000100'
retlw b'00000010'
retlw b'00000001'
retlw b'00000010'
retlw b'00000100'
retlw b'00001000'
retlw b'00010000'
retlw b'00100000'
retlw b'01000000'
Table2 ADDWF PCL, f ;data table for bit pattern
retlw b'11000000'
retlw b'01100000'
retlw b'00110000'
retlw b'00011000'
retlw b'00001100'
retlw b'00000110'
retlw b'00000011'
retlw b'00000011'
retlw b'00000110'
retlw b'00001100'
retlw b'00011000'
retlw b'00110000'
retlw b'01100000'
retlw b'11000000'
Table3 ADDWF PCL, f ;data table for bit pattern
retlw b'01111111'
retlw b'10111111'
retlw b'11011111'
retlw b'11101111'
retlw b'11110111'
retlw b'11111011'
retlw b'11111101'
retlw b'11111110'
retlw b'11111101'
retlw b'11111011'
retlw b'11110111'
retlw b'11101111'
retlw b'11011111'
retlw b'10111111'
Table4 ADDWF PCL, f ;data table for bit pattern
retlw b'00111111'
retlw b'10011111'
retlw b'11001111'
retlw b'11100111'
retlw b'11110011'
retlw b'11111001'
retlw b'11111100'
retlw b'11111100'
retlw b'11111001'
retlw b'11110011'
retlw b'11100111'
retlw b'11001111'
retlw b'10011111'
retlw b'00111111'
Switch1 BTFSC SWPORT, LED1
GOTO JUMP1
BTFSC SWPORT, LED2
GOTO JUMP2
BTFSC SWPORT, LED3
GOTO JUMP3
BTFSC SWPORT, LED4
GOTO JUMP4
retlw 0x00
JUMP1 BCF SWPORT, LED1
BSF SWPORT, LED2
BCF SWPORT, LED3
BCF SWPORT, LED4
GOTO BACK
JUMP2 BCF SWPORT, LED1
BCF SWPORT, LED2
BSF SWPORT, LED3
BCF SWPORT, LED4
GOTO BACK
JUMP3 BCF SWPORT, LED1
BCF SWPORT, LED2
BCF SWPORT, LED3
BSF SWPORT, LED4
GOTO BACK
JUMP4 BSF SWPORT, LED1
BCF SWPORT, LED2
BCF SWPORT, LED3
BCF SWPORT, LED4
GOTO BACK
DELAY movlw d'250' ;delay 250 ms (4 MHz clock)
movwf count1
d1 call ChkKeys ;check the keys
movlw 0xC7 ;delay 1mS
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0
decfsz count1 ,f
goto d1
retlw 0x00
ChkKeys btfss SWPORT, SW1
call Switch1
BACK
retlw 0x00
end