Marami nga yan sa net, ito nakita ko
title "asmPKLED - PICkit Running LED"
;
; This program copies the function of cPKLED.c and Flashes the 8 LEDs
; on the PICkit 1 PCB in Sequence.
;
; Hardware Notes:
; PIC16F684 running at 4 MHz Using the Internal Clock
; External Reset is Used
; Circuit Runs on PICkit 1 PCB
;
; LED Defines:
#define D0Anode PORTA, 4
#define D0Cathode PORTA, 5
#define D1Anode PORTA, 5
#define D1Cathode PORTA, 4
#define D2Anode PORTA, 4
#define D2Cathode PORTA, 2
#define D3Anode PORTA, 2
#define D3Cathode PORTA, 4
#define D4Anode PORTA, 5
#define D4Cathode PORTA, 2
#define D5Anode PORTA, 2
#define D5Cathode PORTA, 5
#define D6Anode PORTA, 2
#define D6Cathode PORTA, 1
#define D7Anode PORTA, 1
#define D7Cathode PORTA, 2
;
;
; Myke Predko
; 04.10.04
;
LIST R=DEC
INCLUDE "p16f684.inc"
__CONFIG _FCMEN_OFF & _IESO_OFF & _BOD_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTOSCIO
; Variables
CBLOCK 0x020
Dlay
ActiveBit ; Record the Active Bit
ENDC
PAGE
; Mainline
org 0
nop ; For ICD Debug
clrf PORTA ; Initialize I/O Bits to Off
movlw 7 ; Turn off Comparators
movwf CMCON0
bsf STATUS, RP0
clrf ANSEL ^ 0x080 ; All Bits are Digital
bcf STATUS, RP0
clrf ActiveBit ; Start with D0
Loop: ; Return Here after Delay and RB0 Toggle
incf ActiveBit, w ; Load the Bit Number
addlw -1 ; Start with D0
btfss STATUS, Z
goto TryD1
bsf STATUS, RP0
bsf D7Anode ; Turn OFF Previously Displayed LED
bsf D7Cathode
bcf D0Anode ; Enable D0 LEDs
bcf D0Cathode
bcf STATUS, RP0
bsf D0Anode
bcf D0Cathode
goto LEDDlay ; Finished, Repeat
TryD1: ; Display D1?
addlw -1
btfss STATUS, Z
goto TryD2
bsf STATUS, RP0
bsf D0Anode ; Turn OFF Previously Displayed LED
bsf D0Cathode
bcf D1Anode ; Enable D0 LEDs
bcf D1Cathode
bcf STATUS, RP0
bsf D1Anode
bcf D1Cathode
goto LEDDlay ; Finished, Repeat
TryD2: ; Display D2?
addlw -1
btfss STATUS, Z
goto TryD3
bsf STATUS, RP0
bsf D1Anode ; Turn OFF Previously Displayed LED
bsf D1Cathode
bcf D2Anode ; Enable D0 LEDs
bcf D2Cathode
bcf STATUS, RP0
bsf D2Anode
bcf D2Cathode
goto LEDDlay ; Finished, Repeat
TryD3: ; Display D3?
addlw -1
btfss STATUS, Z
goto TryD4
bsf STATUS, RP0
bsf D2Anode ; Turn OFF Previously Displayed LED
bsf D2Cathode
bcf D3Anode ; Enable D0 LEDs
bcf D3Cathode
bcf STATUS, RP0
bsf D3Anode
bcf D3Cathode
goto LEDDlay ; Finished, Repeat
TryD4: ; Display D4?
addlw -1
btfss STATUS, Z
goto TryD5
bsf STATUS, RP0
bsf D3Anode ; Turn OFF Previously Displayed LED
bsf D3Cathode
bcf D4Anode ; Enable D0 LEDs
bcf D4Cathode
bcf STATUS, RP0
bsf D4Anode
bcf D4Cathode
goto LEDDlay ; Finished, Repeat
TryD5: ; Display D5?
addlw -1
btfss STATUS, Z
goto TryD6
bsf STATUS, RP0
bsf D4Anode ; Turn OFF Previously Displayed LED
bsf D4Cathode
bcf D5Anode ; Enable D0 LEDs
bcf D5Cathode
bcf STATUS, RP0
bsf D5Anode
bcf D5Cathode
goto LEDDlay ; Finished, Repeat
TryD6: ; Display D6?
addlw -1
btfss STATUS, Z
goto TryD7
bsf STATUS, RP0
bsf D5Anode ; Turn OFF Previously Displayed LED
bsf D5Cathode
bcf D6Anode ; Enable D0 LEDs
bcf D6Cathode
bcf STATUS, RP0
bsf D6Anode
bcf D6Cathode
goto LEDDlay ; Finished, Repeat
TryD7: ; Display D7?
addlw -1
btfss STATUS, Z
goto LEDDlay
bsf STATUS, RP0
bsf D6Anode ; Turn OFF Previously Displayed LED
bsf D6Cathode
bcf D7Anode ; Enable D0 LEDs
bcf D7Cathode
bcf STATUS, RP0
bsf D7Anode
bcf D7Cathode
goto LEDDlay ; Finished, Repeat
LEDDlay: ;
clrf Dlay ; High 8 Bits for Delay
clrw
addlw -1 ; Decrement the contents of WREG
btfss STATUS, Z ; 256x
goto $ - 2
decfsz Dlay, f ; Repeate 255x
goto $ - 4
clrf Dlay ; Repeat Again for ~ 400 ms total Delay
clrw
addlw -1 ; Decrement the contents of WREG
btfss STATUS, Z ; 256x
goto $ - 2
decfsz Dlay, f ; Repeate 255x
goto $ - 4
incf ActiveBit, w ; Increment the Active LED
andlw 7 ; Keep Within range of 0-7
movwf ActiveBit
goto Loop ; Repeat
end