Knight Rider - LED experiment with a PIC16F628A


The LEDs light up in a sequence that resembles KITT's lights. The code is self-explanatory, but you might read about the rrf and rlf instructions in the datasheet. Note that the Carry bit is set before the rrf instruction is executed.

  Schematic (png)

  Hex file (hex)

; 'Knight-Rider': LED experiment with PIC16F628A
; Revision: July 29th, 2007
; Assembled with MPASM v5.11

list      p=16f628A ; list directive to define processor
  #include <> ; processor specific variable definitions
	errorlevel  -302	; suppress message 302 from list file 
	; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.
	cblock  0x20
org     0x000 ; processor reset vector
goto    main ; go to beginning of program
movlw 0x07 
movwf CMCON ; turn comparators off 
clrf PORTB ; clear PORTB
bsf  STATUS, RP0
clrf TRISB ; all PORTB as output
bcf  STATUS, RP0
	bsf  STATUS, C		; set carry
rrf  PORTB, f ; rotate right (through carry)
call delay ; delay 
btfss PORTB, 0 ; check if RB0 has been reached
goto right
rlf  PORTB, f ; rotate left
call delay ; delay 
btfss PORTB, 7 ; check if RB7 has been reached
goto left
goto right

delay ; 99993 cycles        
movlw 0x1E
movwf v1
movlw 0x4F
movwf v2
decfsz v1, f
goto $+2
decfsz v2, f
goto delay_0
	end			; directive 'end of program' 




Si declina ogni responsabilità per errori ed inesattezze contenute in questa documentazione e per danni di qualsiasi natura derivanti dall'uso dei circuiti e dei programmi descritti. Nomi e marchi citati appartengono ai rispettivi proprietari.