;******************************************************************* ; LED TEST PROGRAM 3-3 ; The LED array runs up and down using a table of binaries. ; Dictated by the 4-MHz subroutine "Delay". ; Included are the new schematic CPU Equates. ;When programming, DISABLE MASTERCLEAR AND WDT. ;******************************************************************* ; ;==========CPU EQUATES SECTION===================================== LIST p=16F737 ;Tell the assembler to use 16F737 include "P16F737.INC" ;Tell the compiler to include defaults for 16F737 cblock 0x20 ;Prepare the general purpose registers count ;Used in table read routine count1 ;Used in delay routine counta ;Used in delay routine countb ;Used in delay routine endc INPORT Equ PORTA ;Set constant for portA = INPORT OUTPORT Equ PORTB ;Set constant for portB = OUTPORT LEDARRAY Equ PORTC ;Set constant for portC = LEDARRAY ;==========Outputs:========== PRLED0 Equ 0 ;Set constant for portB, bit0 = PRLED0 PRLED1 Equ 7 ;Set constant for portC, bit7 = PRLED1 PRLED2 Equ 6 ;Set constant for portC, bit6 = PRLED2 PRLED3 Equ 5 ;Set constant for portC, bit5 = PRLED3 PRLED4 Equ 4 ;Set constant for portC, bit4 = PRLED4 PRLED5 Equ 3 ;Set constant for portC, bit3 = PRLED5 PRLED6 Equ 2 ;Set constant for portC, bit2 = PRLED6 PRLED7 Equ 1 ;Set constant for portC, bit1 = PRLED7 PRLED8 Equ 0 ;Set constant for portC, bit0 = PRLED8 UPPLED Equ 7 ;Set constant for portB, bit7 (PGD) = UPPLED SOLENOID Equ 6 ;Set constant for portB, bit6 (PGC) = SOLENOID SPEAKER Equ 2 ;Set constant for portB, bit2 = SPEAKER RF Equ 3 ;Set constant for portB, bit3 = RF ;========Inputs:======== EYESIG Equ 0 ;Set constant for portA, bit0 = EYESIG TRIG Equ 1 ;Set constant for portA, bit1 = TRIG PWRSW Equ 2 ;Set constant for portA, bit2 = PWRSW EYEGND Equ 3 ;Set constant for portA, bit3 = EYEGND PRSWDN Equ 4 ;Set constant for portA, bit4 = PRSWDN PRSWUP Equ 5 ;Set constant for portA, bit5 = PRSWUP BATTPWR Equ 6 ;Set constant for portA, bit6 = BATTPWR ; ;===========HOUSEKEEPING============================================= org 0x0000 ;Start program movlw 0x07 ;Prepare binary 111 for CMCON movwf CMCON ;Turn comparators off, allow for general I/O. bsf STATUS, RP0 ;Select bank 1 to edit tri-state assignments movlw b'11111111' ;Move full binary into W register (all inputs) movwf TRISA ;Move W into tristate-portA movlw b'00000000' ;Move null binary into W register (all outputs) movwf TRISB ;Move W into tristate-portB movwf TRISC ;Move W into tristate-portC movlw 0x6E ;Prepare binary 1101110 for OSCCON movwf OSCCON ;Set the oscillator frequency sucka bcf STATUS, RP0 ;Deselect bank 1, autoselect bank 0. ;============MAIN PROGRAM;=========================================== bsf OUTPORT, PRLED0 ;Activate bottom programming LED and keep it on continuously. Start clrf count ;Set the counter register to 0 Read movf count, W ;Move counter file into W register call Table ;Check the table and come back with a binary movwf LEDARRAY ;Put the binary into the LEDARRAY call Delay ;Wait for the Delay subroutine incf count, W ;Increment the count, put it in the W-register xorlw d'20' ;XorL literal:W (set zero flag if W=19) btfsc STATUS, Z ;Check the zero flag; skip next if set goto Start ;If zero=1, count is up - reset program and start over. incf count, f ;If zero=0, count stil going - increment counter value... goto Read ;...and loop to continue counting ;========Table:======== Table addwf PCL, f ;Add W to the value in the Program Counter and goto that line retlw b'10000000' ;Turn this output on. retlw b'11000000' ;... retlw b'01100000' retlw b'00110000' retlw b'00011000' retlw b'00001100' retlw b'00000110' retlw b'00000011' retlw b'00000001' retlw b'00000011' retlw b'00000110' retlw b'00001100' retlw b'00011000' retlw b'00110000' retlw b'01100000' retlw b'11000000' retlw b'10000000' retlw b'00000000' retlw b'00000000' retlw b'00000000' ;========COUNTER SUBROUTINE======== Delay movlw d'75' ;Begin Delay 75-ms (4-MHz clock) subroutine movwf count1 ;Move Delay setting into count1 d1 movlw 0xC7 ;delay 1mS movwf counta ;Assign 1mS to counta movlw 0x01 ;Delay 1µS movwf countb ;Assign 1µS to countB Delay_0 decfsz counta, f ;Decrement counta and skip next line if at 0 goto $+2 ;If >0, do it again decfsz countb, f ;If 0, decrement countb and skip next line if at 0 goto Delay_0 ;If 1mS count is up, test again decfsz count1 ,f ;Decrement total count and skip next line if at 0 goto d1 ;Return and decrease the counts retlw 0x00 ;If count1=0, exit subroutine end ;==============END=================================================