|
Все лишнее можно выбросить, это как пример.
;__CONFIG _CONFIG1L, _CP_OFF_1L ; ........................ ORG 0x0000 ......................... ;==_Interupts_== ;очистка регистров. ;==_Timer_0_== ;==_Interupts_== ;-------------------------------; movff fl_ih,FSR0L ; btfsc PIR3,ERRIF ; movff fl_il,FSR0L ; обработчик таймера ;==================_TIMER_0_===============================
E-mail:
info@telesys.ru
list p=18f258 ; list directive to define processor
#include
#include
__CONFIG _CONFIG1H, _ECIO_OSC_1H & _OSCS_ON_1H ;
__CONFIG _CONFIG2L, _BOR_OFF_2L & _PWRT_ON_2L & _BORV_27_2L;_BORV_42_2L ;_BORV_25_2L ;_BORV_27_2L ;_BORV_42_2
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H ;
__CONFIG _CONFIG4L, _STVR_ON_4L ;& _LVPEN_OFF_4L & _BKBUG_OFF_4L ;
start: clrf PCLATH
clrf PCLATU
goto main
ORG 0x0008
inth: bra inthg
ORG 0x0018
intl: bra intlo
;-------------------------------;
инициализация
clrf INTCON
clrf INTCON2
clrf INTCON3
clrf PIE1
clrf PIE2
clrf PIE3
clrf BSR ;
clrf FSR0H ;
clrf FSR0L ;
bcf INTCON2,TMR0IP ;low prioriti.
bsf INTCON,TMR0IE ;enable TMR0 interrupt
clrf TMR0L ; = 0 clear timer
movlw 0xC7 ;En, 8bit, Fosc/4,x,PSA,/256.
movwf T0CON ;
bsf RCON,IPEN ;enable prioriti
bsf INTCON,GIEH ;enable interrupts High
bsf INTCON,GIEL ;enable interrupts Low
Обработчики прерываний
inthg: movwf w_ih ;
movff STATUS,s_ih ;
movff BSR,b_ih ;
movff FSR0H,fh_ih ;
movff FSR0L,fl_ih ;
inthgc:
movlb 0x00 ;
btfsc PIR1,TMR2IF ;
bra int_tmr2 ;
btfsc PIR2,LVDIF ;clear LVD int
bra intlvd ;
movff fh_ih,FSR0H ;
movff b_ih,BSR ;
movf w_ih,W ;
movff s_ih,STATUS ;
retfie ;
;-------------------------------;
intlo:
movwf w_il ;
movff STATUS,s_il ;
movff BSR,b_il ;
movff FSR0H,fh_il ;
movff FSR0L,fl_il ;
intloc:
movlb 0x00 ;
btfsc INTCON,TMR0IF ;Timer 0
bra int_tmr0 ;/
btfsc PIR1,RCIF ;UART Recive
bra int_URC ;/
btfss PIE1,TXIE ;\
bra nourttx ; \
btfsc PIR1,TXIF ;UART Transmit
bra int_UTR ;/
nourttx:
;CAN_Interrupt
movff CANCON,tcancon ;
movff CANSTAT,tcanstat ;
interrupt
bra intcanerr ;
btfsc PIR3,RXB0IF ;
bra intcanrxb0 ;
btfsc PIR3,RXB1IF ;
bra intcanrxb1 ;
btfsc PIR3,TXB0IF ;
bra intcantxb0 ;
nointtx:
movff fh_il,FSR0H ;
movff b_il,BSR ;
movf w_il,W ;
movff s_il,STATUS ;
retfie ;
int_tmr0:
clrf BSR ;
movlw 0xE0 ;\
addwf TMR0L,F ;для 1КГц.
;-------------------------------;
bcf INTCON,TMR0IF ;
;-------------------------------;Часы.
incf clock+0,F ;
clrf WREG ;
addwfc clock+1,F ;
addwfc clock+2,F ;
addwfc clock+3,F ;
addwfc clock+4,F ;
;-------------------------------;
goto intloc ;
;-------------------------------;
Ответы