First time I'm using this chip.I need to verify the initialisation part.The wiered thing that I noticed is.. before I write to a register everytime I have to call BANKSEL directive.Then what's the point of BSR core register?Is my code ok?
Code:
List P=16F1827
#include <P16F1827.INC>
errorlevel -302
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF
org 0000h
goto Initialise_Ports
org 0004h
retfie
Initialise_Ports
BANKSEL PORTA
clrf PORTA
BANKSEL LATA
clrf LATA
BANKSEL ANSELA
clrf ANSELA
BANKSEL TRISA
clrf TRISA
;
BANKSEL PORTB
clrf PORTB
BANKSEL LATB
clrf LATB
BANKSEL ANSELB
clrf ANSELB
BANKSEL TRISB
clrf TRISB
Setup_TMR2
BANKSEL T2CON
movlw b'00011101' ; pre scaler = 1:4,Post Scaller = 1:4
movwf T2CON
movlw .249
movwf PR2
BANKSEL PIE1
bsf PIE1,TMR2IE
movlw b'11000000' ; turn on GIE & PEIE
movwf INTCON
BANKSEL PORTA
bcf PIR1,TMR2IF
goto Clear_Registers