title "asmPKLED 3 - PICkit Running LED"
;
; This program copies the operation of cPKLED.c and Flashes the 8 LEDs
; on the PICkit 1 PCB in Sequence by Storing the Values for the LEDs
; and the TRIS registers in Arrays
;
; Hardware Notes:
; PIC16F684 running at 4 MHz Using the Internal Clock
; Circuit Runs on PICkit 1 PCB
;
; Original Code:
;
; int i, j, k;
; char LEDValue[8] = {0b010000, 0b100000, 0b010000, 0b000100,
; 0b100000, 0b000100, 0b000100, 0b000010};
; char TRISValue[8] = {0b001111, 0b001111, 0b101011, 0b101011,
; 0b011011, 0b011011, 0b111001, 0b111001};
;
; main()
; {
;
; PORTA = 0;
; CMCON0 = 7; // Turn off Comparators
; ANSEL = 0; // Turn off ADC
;
; k = 0; // Start at LED 0
;
; while(1 == 1) // Loop Forever
; {
; for (i = 0; i < 255; i++) // Simple Delay Loop
; for (j = 0; j < 129; j++);
;
; PORTA = LEDValue[k]; // Specify LED Output
; TRISA = TRISValue[k];
;
; k = (k + 1) % 8; // Increment k within range of 0-7
;
; } // elihw
; } // End cPKLED
;
;
;
; Myke Predko
; 04.11.07
;
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 0x20
LEDValue:8, TRISValue:8
Dlay
k
ENDC
PAGE
; Mainline of asmPKLED
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 ^ 0x80 ; All Bits are Digital
bcf STATUS, RP0
clrf k ; Start with D0
movlw b'010000' ; Load LEDValue Explicitly
movwf LEDValue
movlw b'100000'
movwf LEDValue + 1
movlw b'010000'
movwf LEDValue + 2
movlw b'000100'
movwf LEDValue + 3
movlw b'100000'
movwf LEDValue + 4
movlw b'000100'
movwf LEDValue + 5
movlw b'000100'
movwf LEDValue + 6
movlw b'000010'
movwf LEDValue + 7
movlw b'001111' ; Load TRISValue Explicitly
movwf TRISValue
movwf TRISValue + 1 ; NOTE: LEDs are in Pairs
movlw b'101011'
movwf TRISValue + 2
movwf TRISValue + 3
movlw b'011011'
movwf TRISValue + 4
movwf TRISValue + 5
movlw b'111001'
movwf TRISValue + 6
movwf TRISValue + 7
Loop: ; Return Here after Delay and RB0 Toggle
clrf Dlay ; High 8 Bits for Delay
clrw
goto $ + 1
goto $ + 1
addlw -1 ; Decrement the contents of WREG
btfss STATUS, Z ; 256x
goto $ - 4
decfsz Dlay, f ; Repeate 255x
goto $ - 6
; PORTA = LEDValue[k]
movf k, w ; Load the Offset for LEDValue
addlw LEDValue ; Add to Start of LEDValue Array
movwf FSR ; Store Address in Index Register
movf INDF, w ; Get LEDValue[k]
movwf PORTA ; Save in PORTA Register
; TRISA = TRISValue[k]
movf k, w ; Get the Offset for TRISValue
addlw TRISValue ; Add to the Start of Array
movwf FSR ; Store Address in Index Register
movf INDF, w ; Get TRISValue[k]
bsf STATUS, RP0 ; Save in TRISA Register
movwf TRISA ^ 0x80
bcf STATUS, RP0
incf k, w ; Increment the Active LED
andlw 7 ; Keep Within range of 0-7
movwf k
goto Loop ; Repeat
end