;;; Introduction to LEDs ; ; Written by: Nora Znotinas ; Last modified: January 12, 2005 ; ; Light the 'Left LED', connected to port A pin RA3, with an equal interval pattern. ; Timing accomplished using a delay routine. ; ;;; assembler directives LIST P=PIC18F452, F=INHX32, C=160, N=0, ST=OFF, MM=OFF, X=ON #include P18F452.INC CONFIG OSC=HS ;select HS oscillator CONFIG PWRT=ON, BOR=ON, BORV=42 CONFIG WDT=OFF, LVP=OFF ;disable watchdog timer ; and low voltage power ;;; variables cblock 0x000 max_loops ;number of loops max_count ;delay loop counter endc ;;; macro definitions ; movlf - command to move a literal value into a file register movlf macro imm,dest movlw imm movwf dest endm ;;; vectors org 0x0000 ;reset vector goto start ;start of program org 0x0008 ;high priority interrupt vector goto $ ;none for now org 0x0018 ;low priority interrupt vector goto $ ;none for now ;;; the actual program start ; initialize PORT A registers movlf b'01100001',TRISA ;set data direction movlf b'10001110',ADCON1 ;set digital/analog functions clrf PORTA ;initialize L, C, R LEDs to off main_l rcall delay ;wait bsf LATA,3 ;turn left LED on rcall delay ;wait btg LATA,3 ;turn left LED off bra main_l ;;; delay subroutine delay setf max_loops ;initialize number of loops del_out setf max_count ;initialize loop counter del_in nop ;kill some time decfsz max_count ;decrement count bra del_in ;loop if not zero decfsz max_loops ; else decrement loop number bra del_out ;loop if not zero return ; else return end