;****************************************************************************** ; This file is a basic code template for code generation on the * ; PIC12F519. This file contains the basic code building blocks to build * ; upon. * ; * ; Refer to the MPASM User's Guide for additional information on features * ; of the assembler. * ; * ; Refer to the respective data sheet for additional information on the * ; instruction set. * ; * ;****************************************************************************** ; * ; Filename: Larson Scanner.asm * ; Date: 10/20/09 * ; File Version: V0.1 * ; Author: Ronald C. Barnes * ; Company: KA1KJZ * ; * ;****************************************************************************** ; * ; Files Required: P12F519.INC * ; * ;****************************************************************************** ; * ; Features of the 12F519: * ; * ; 64 Bytes of Flash Data Memory (non-volatile data storage) * ; Precision 4/8 MHz internal oscillator * ; Baseline Core with 33 Instructions, 2 Stack Levels * ; All Single-Cycle Instructions (except program branches which use 2) * ; 12-bit wide instructions * ; 8-bit wide data pathistors (D+/D-) * ; 25 mA source/sink current I/O * ; Low power (100 nA) slep current * ; One 8-bit Timer TMR0 * ; Watchdog Timer (WDT) * ; In Circuit Serial Programming (ICSP) capability * ; In Circuit Debugging Support * ; Programmable code protection * ; * ;****************************************************************************** ; * ; Notes: * ; * ; The 12F519 does not have interrupts * ; * ; * ;****************************************************************************** ; * ; Revision History: * ; * ;****************************************************************************** ;------------------------------------------------------------------------------ ; PROCESSOR DECLARATION ;------------------------------------------------------------------------------ LIST p=12F519 ; list directive to define processor #INCLUDE ; processor specific variable definitions ;------------------------------------------------------------------------------ ; ; CONFIGURATION WORD SETUP ; ; The 'CONFIG' directive is used to embed the configuration word within the ; .asm file. The lables following the directive are located in the respective ; .inc file. See the data sheet for additional information on configuration ; word settings. ; ;------------------------------------------------------------------------------ __CONFIG _CPDF_OFF & _IOSCFS_8MHz & _MCLRE_ON & _CP_OFF & _WDTE_OFF & _IntRC_OSC ;------------------------------------------------------------------------------ ; ; VARIABLE DEFINITIONS ; ; Available Data Memory divided into Bank 0 and Bank 1. Each Bank contains ; Special Function Registers and General Purpose Registers at the locations ; below: ; ; SFR OVERLAPPING GPR SEPERATE GPR ; Bank 0 0x00-0x06 0x07-0x0F 0x10-0x1F ; Bank 1 0x20-0x26 0x27-0x2F 0x30-0x3F ; ;------------------------------------------------------------------------------ CBLOCK 0x07 ; Sample user GPR registers allocated contiguously sGPIO ;shadow copy of GPIO dlycnt ;delay counter ENDC ;------------------------------------------------------------------------------ ; RESET VECTOR ;------------------------------------------------------------------------------ OSC ORG 0x3FF ; store move instruction here ; Internal RC calibration value is placed at location 0x3FF by Microchip as ; a MOVLW K instruction, where the K is a literal value to be loaded into ; the OSCCAL register. ;------------------------------------------------------------------------------ ; RESTORE OSCILLATOR CALIBRATION VALUE ;------------------------------------------------------------------------------ RESET ORG 0x0000 ; processor reset vector banksel OSCCAL ; select data memory bank of OSCCAL MOVWF OSCCAL ; set oscillator tuning value pagesel START ; select page of beginning of program GOTO START ; go to beginning of program ;------------------------------------------------------------------------------ ; MAIN PROGRAM ;------------------------------------------------------------------------------ START ;initialization movlw b'111111' ;configure GPIOs as inputs initially tris PORTB ; (GP3 is input only) movlw b'11010100' ;select Timer0: timer mode, prescale = 32 option ; (increment every 32uS) clrf PORTB ;start with all LEDs off bsf PORTB,2 ;set PortB,2 initially on clrf sGPIO ;update shadow bsf sGPIO,2 ; ;********************* ;***** MAIN LOOP ***** ;********************* ;******************* loop ;*** delay 100mS *** ;******************* banksel dlycnt ; movlw .20 ;repeat 125 times movwf dlycnt ;-> 125 x 4mS = 500mS ;***************** ;*** SCAN LEDS *** ;***************** begin movlw b'111100' ;configure GP0 & 1 as outputs tris PORTB ; bsf PORTB, 0 ;turn on GP0 bcf PORTB, 1 ;be sure GP1 is off call dly500 ;go away for 500ms bcf PORTB, 0 ; turn off GP0 bsf PORTB, 1 ; turn on GP1 call dly500 ;go away for 500ms bcf PORTB, 1 ; turn off GP1 movlw b'111001' ;configure GP1 & 2 as outputs tris PORTB ; bsf PORTB, 1 ;turn on GP1 bcf PORTB, 2 ;be sure GP2 is off call dly500 ;go away for 500ms bcf PORTB, 1 ; turn off GP1 bsf PORTB, 2 ; turn on GP2 call dly500 ;go away for 500ms bcf PORTB, 2 ; turn off GP2 movlw b'111010' ;configure GP0 & 2 as outputs tris PORTB ; bsf PORTB, 0 ;turn on GP0 bcf PORTB, 2 ;be sure GP2 is off call dly500 ;go away for 500ms bcf PORTB, 0 ; turn off GP0 bsf PORTB, 2 ; turn on GP2 call dly500 ;go away for 500ms bcf PORTB, 2 ; turn off GP2 movlw b'101011' ;configure GP2 & 4 as outputs tris PORTB ; bsf PORTB, 2 ;turn on GP2 bcf PORTB, 4 ;be sure GP4 is off call dly500 ;go away for 500ms bcf PORTB, 2 ; turn off GP2 bsf PORTB, 4 ; turn on GP4 call dly500 ;go away for 500ms bcf PORTB, 4 ; turn off GP4 bsf PORTB, 2 ;turn on GP2 bcf PORTB, 4 ;be sure GP4 is off call dly500 ;go away for 500ms bcf PORTB, 2 ; turn off GP2 movlw b'111010' ;configure GP0 & 2 as outputs tris PORTB ; bsf PORTB, 2 ;turn on GP2 bcf PORTB, 0 ;be sure GP0 is off call dly500 ;go away for 500ms bcf PORTB, 2 ; turn off GP2 bsf PORTB, 0 ; turn on GP0 call dly500 ;go away for 500ms bcf PORTB, 0 ; turn off GP0 movlw b'111001' ;configure GP1 & 2 as outputs tris PORTB ; bsf PORTB, 2 ;turn on GP2 bcf PORTB, 1 ;be sure GP1 is off call dly500 ;go away for 500ms bcf PORTB, 2 ; turn off GP2 bsf PORTB, 1 ; turn on GP1 call dly500 ;go away for 500ms bcf PORTB, 1 ; turn off GP1 movlw b'111100' ;configure GP0 & 1 as outputs tris PORTB ; bsf PORTB, 1 ;turn on GP1 bcf PORTB, 0 ;be sure GP0 is off call dly500 ;go away for 500ms bcf PORTB, 1 ; turn off GP1 ;bsf PORTB, 0 ; turn on GP0 ;call dly500 ;go away for 500ms ;bcf PORTB, 0 ; turn off GP0 goto begin ;****************************** dly500 ;*** 500ms delay loop *** ;****************************** clrf TMR0 ;clear timer0 w_tmr0 movf TMR0,w ;check timer value xorlw .18 ;wait for 4ms (125 x 32us) btfss STATUS,Z ;is it zero? goto w_tmr0 ;no do it again decfsz dlycnt,f ;decrement dlycnt, is it zero? goto dly500 ;no, do it all again retlw 0 ;done! ; goto dly500 end GOTO $ END