list F=inhx8m, P=16F886, R=hex, N=0
#include <P16F886.INC> ; PIC definitions
__config _config1,_INTOSCIO & _WDT_OFF & _LVP_OFF & _PWRTE_OFF & _MCLRE_OFF & _BOREN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF & _CP_OFF
__config _config2,_IESO_OFF & _FCMEN_OFF
Errorlevel -302 ; switches off Message [302]: Register in operand not in bank 0.
; RAM preserved -----------------------------------------------------------
cblock 0x20
WaitCounter,WaitCounter2
d1,d2,d3
endc
; Program Memory ----------------------------------------------------------
org 0
goto Init
; Interrupt Service Routine -----------------------------------------------
org 4 ; ISR beginning
; Microcontroller initialization
Init
; include init_normal.inc ;Include the PIC Initialization routine
banksel OSCCON
movlw b'01100000'
movwf OSCCON
WaitForStableOscillator
btfss OSCCON,HTS
goto WaitForStableOscillator
movlw b'11111000' ; OPTION_REG setup
movwf option_reg
clrf pie1 ;
clrf pie2 ; No peripherial interrupt
clrf txsta ;Disable AUSART
;PSA must be to WDA (bsf OPTION_REG,psa)
bcf OPTION_REG,PS2
bcf OPTION_REG,PS1
bsf OPTION_REG,PS0
clrf adcon1 ;No analog to digital conversion
bankSEL ANSEL
clrf ansel ; No analog to digital conversion
clrf anselh ; No analog to digital conversion
bankSEL CM1CON0
clrf CM1CON0 ;disable Comparator
clrf CM2CON0 ;disable Comparator
clrf CM2CON1 ;disable Comparator
banksel 0
;General
clrf rcsta ;Disable AUSART receive
clrf adcon0 ;No analog to digital conversion
;I am
; Main Program ------------------------------------------------------------
Start
banksel TRISA
movlw b'11111111' ;Set the port pin types of the RA
movwf TRISA ;All RA ports are inputs
movlw b'11111110' ;Set the port pin types of the RB
movwf TRISB ;All RB ports are input except RB0 that is output
banksel 0 ;Go to bank 0
MainLoop
bsf PORTB,0 ;Set RB0 output LOW
call Delay
bcf PORTB,0 ;Set RB0 output HIGH
call Delay
goto MainLoop ;And go back to the Main Loop
; Delay = 0.5 seconds
; Clock frequency = 4 MHz
; Actual delay = 0.5 seconds = 500000 cycles
; Error = 0 %
Delay
;499994 cycles
movlw 0x03
movwf d1
movlw 0x18
movwf d2
movlw 0x02
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0
;2 cycles
goto $+1
;4 cycles (including call)
return
Fins
end ; end of program