list p=16f628A ; list directive to define processor
#include <p16F628A.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_OFF & _INTOSC_OSC_NOCLKOUT
cblock 0x20 ;start of general purpose registers
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
endc
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 TRISB
movwf TRISA ;set PortA all outputs
bcf STATUS, RP0 ;select bank 0
clrf PORTA
main:
banksel PORTA
bsf PORTA,7 ;turn on top
call blinkleds ; blink your leds
bcf PORTA,7 ;turn off top
bsf PORTA,6 ;turn on middle
call blinkleds ; blink your leds
bcf PORTA,6 ;turn off middle
bsf PORTA,5 ;turn on bottom
call blinkleds ; blink your leds
bcf PORTA,5 ;turn off bottom
goto main ;go back and keep doing it
blinkleds:
banksel PORTB
bsf PORTB,0
call delay
bcf PORTB,0
call delay
bsf PORTB,1
call delay
bcf PORTB,1
call delay
bsf PORTB,2
call delay
bcf PORTB,2
call delay
bsf PORTB,3
call delay
bcf PORTB,3
call delay
bsf PORTB,4
call delay
bcf PORTB,4
call delay
bsf PORTB,5
call delay
bcf PORTB,5
call delay
bsf PORTB,6
call delay
bcf PORTB,6
call delay
bsf PORTB,7
call delay
bcf PORTB,7
call delay
banksel PORTA
bsf PORTA,2
call delay
bcf PORTA,2
call delay
goto main
delay
movlw d'50' ;delay 250 ms (4 MHz clock)
movwf count1
d1
movlw 0xC7
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
end