; 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. ; CPU equates: LIST p=16F737 ;Tell the assembler to use 16F737 include "P16F737.INC" ;Tell the compiler to include defaults for 16F737 __config 0x3F18 ;Assign these fuses to the program cblock 0x20 ;Beginning of 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 ;Get out of there INPORT Equ PORTA ;Set constant INPORT = portA OUTPORT Equ PORTB ;Set constant OUTPORT = portB LEDARRAY Equ PORTC ;Set constant LEDARRAY = portC ; Tri-state I/O PRLED0 Equ 0 ;Set constant PRLED0 = portB, bit0 PRLED1 Equ 7 ;Set constant PRLED1 = portC, bit7 PRLED2 Equ 6 ;Set constant PRLED2 = portC, bit6 PRLED3 Equ 5 ;Set constant PRLED3 = portC, bit5 PRLED4 Equ 4 ;Set constant PRLED4 = portC, bit4 PRLED5 Equ 3 ;Set constant PRLED5 = portC, bit3 PRLED6 Equ 2 ;Set constant PRLED6 = portC, bit2 PRLED7 Equ 1 ;Set constant PRLED7 = portC, bit1 PRLED8 Equ 0 ;Set constant PRLED8 = portC, bit0 UPPLED Equ 7 ;Set constant UPPLED = portB, bit7 (PGD) SOLENOID Equ 6 ;Set constant SOLENOID = portB, bit6 (PGC) SPEAKER Equ 2 ;Set constant SPEAKER = portB, bit2 RF Equ 3 ;Set constant RF = portB, bit3 EYESIG Equ 0 ;Set constant EYESIG = portA, bit0 TRIG Equ 1 ;Set constant TRIG = portA, bit1 PWRSW Equ 2 ;Set constant PWRSW = portA, bit2 EYEGND Equ 3 ;Set constant EYEGND = portA, bit3 PRSWDN Equ 4 ;Set constant PRSWDN = portA, bit4 PRSWUP Equ 5 ;Set constant PRSWUP = portA, bit5 BATTPWR Equ 6 ;Set constant BATTPWR = portA, bit6 ; housekeeping org 0x0000 ;Start 0x0000 (PIC16F737) movlw 0x07 ;Set CMCON status= b'111' movwf CMCON ;Turn comparators off (allow for general purpose I/O) bsf STATUS, RP0 movlw b'11111111' ;Full binary (all inputs) movwf TRISA movlw b'00000000' ;Null binary all outputs) movwf TRISB movwf TRISC movlw 0x6E ;Set OSCCON = b'1101110' movwf OSCCON ;Designate the oscillator frequency bcf STATUS, RP0 ;Deselect bank 1. ; START PROGRAM bsf OUTPORT, PRLED0 ; Keep this on continuously Start clrf count ;Initialize counter register Read movf count, W call Table ;Check the table - return with a binary movwf LEDARRAY ;Move the binary into the outputs call Delay ;Wait a bit incf count, W ;Increment the counter xorlw d'20' ;XorL the W register - set Zero flag if =19 btfsc STATUS, Z ;Bit check Zero flag; skip next if set goto Start ;Reset and do it again incf count, f ;Increment counter goto Read ;Loop and read next table line Table addwf PCL, f ;Add W to the value in the Program Counter - goto that line retlw b'10000000' 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 Delay movlw d'75' ;Begin Delay 75-ms (4-MHz clock) movwf count1 ;Move Delay into count1 d1 movlw 0xC7 ;small delay movwf counta ;Assign 1mS to counta movlw 0x01 ;Delay 1 muS movwf countb ;Assign 1 muS to countB Delay_0 decfsz counta, f ;Decrement counta - skip next line if =0 goto $+2 ;Do it again decfsz countb, f ;Decrement countb - skip next line if =0 goto Delay_0 ;If count up, test again decfsz count1 ,f ;Decrement total count - skip next line if =0 goto d1 ;Return and decrement retlw 0x00 ;If count1=0, exit subroutine end ; END