;
;---------------------------------------------------------------
.sect "MAIN",Main
;---------------------------------------------------------------
RESET mov #Stack,SP ; Initialize Stackpointer
call #Init_Sys ; Setup Peripherals
; Mainloop of Program
Loop
bis.b #LPM3, SR
jmp Loop ; endless loop,
; core is sleeping until interrupts from
; from BT and Port0 wake it up
;
;---------------------------------------------------------------
Init_Sys ; Subroutine: Setup MSP430 Peripherals For Operation
;---------------------------------------------------------------
clr.b &IFG1 ; clear all interrupt flags
clr.b &IFG2
clr.b &IE1 ; disable all interrupts
clr.b &IE2
BT_INIT
mov.b #(IP0+IP1+IP2+DIV), &BTCTL ; set BT to 0.5Hz(2sec)
bis.b #BTIE, &IE2 ; enable BT interrupt
clr sec_counter ; make sec_counter = 0
P0_INIT
mov.b #000h, &P0DIR ; P0.3 and P0.4 work as inputs
mov.b #018h, &P0IES ; P0.3 and P0.4 hi/lo transition
mov.b #01Ch, &P0IE ; P0.2,P0.3,P0.4 interrupt enable
bis.b #008h, &IE1 ; P0.1 interrupt enable
clr N1_LSB ; clear impulses counters for
clr N1_MSB ; P0.3
clr N2_LSB ; and P0.4
clr N2_MSB
eint ; set GIE bit in Status Register
ret ; return from Init_Sys subroutine
;
;---------------------------------------------------------------
BT_ISR ; Interrupt Service Routine for Basic Timer
;---------------------------------------------------------------
inc sec_counter ; add number of seconds elapsed
cmp #50, sec_counter ; check if 100sec have elapsed
jne RETURN
pop R10 ; pop SR from stack
pop R11 ; pop PC from stack
clr R10
clr R11
push N1_LSB ; save impulse counts
push N1_MSB ; in stack
push N2_LSB
push N2_MSB
jmp RESET ; start new frequency measurement
RETURN reti
;
;---------------------------------------------------------------
P0.34_ISR ; Interrupt Service Routine for P0.3 and P0.4
;---------------------------------------------------------------
IntP03
bit #P0IFG3, P0IFG ; Is interrupt flag for P0.3 set?
jz IntP04 ; If no, go to Int Service for P0.4
; If yes, proceed
clrc ; clear Carry flag C in SR
add #1, N1_LSB ; increment counter of
adc N1_MSB ; impulses at line P0.3
and.b #0F7h, P0IFG ; Reset P0IFG.3 flag
eint ; enable interrupts
IntP04
bit #P0IFG4, P0IFG ; Is interrupt flag for P0.4 set?
jz RETURN0 ; If no, go to Int Service for P0.3
; If yes, proceed
clrc
add #1, N2_LSB ; increment counter of
adc N2_MSB ; impulses at line P0.4
and.b #0EFh, P0IFG ; Reset P0IFG.4 flag
eint
RETURN0 reti
;
;---------------------------------------------------------------
.sect "Int_Vect",I_vectors-31
;---------------------------------------------------------------
.word P0.34_ISR ; Port0, bit 2 to bit 7
.word BT_ISR ; Basic Timer
.word RESET ; no source
.word RESET ; no source
.word RESET ; Timer Port
.word RESET ; EOC from ADC
.word RESET ; no source
.word RESET ; no source
.word RESET ; no source
.word RESET ; no source
.word RESET ; Watchdog Timer, Timer mode
.word RESET ; no source
.word RESET ; P0.1 or 8-bit T/C
.word RESET ; P0.0
.word RESET ; NMI, Osc. fault
.word RESET ; POR, ext. Reset, Watchdog
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.