chip sn8p2711A
.data
adc_buf ds 1
acc_buf ds 1
pflag_buf ds 1
.code
org 00h
jmp main
org 08h
jmp isr
org 10h
main:
b0bset fadenb // Enable ADC circuit
call delay100us // Delay 100us
mov a,#0feh
b0mov p4ur,a // Disable P4.0 pull-up resistor
b0bclr fp40m // Set P40 as input pin
mov a,#01h
b0mov p4con,a // Set P40 as pure analog input
mov a,#40h // To set 8-bit and Fcpu/1.
b0mov adr,a
mov a,#90h // Enable ADC and set AIN0 input
b0mov adm,a
b0bset fadcien // Enable ADC interrupt service
b0bclr fadcirq // Clear ADC interrupt request flag
b0bset fgie // Enable GIE
b0bset fads // To start conversion
//===============================================================
//
// User code
//
//===============================================================
jmp main
//======================================================
// interrupt code
//======================================================
isr:
mov acc_buf,a // Push ACC to buffer
mov a,pflag
b0mov pflag_buf,a // Push PFLAG to buffer
isr_adc:
b0bts1 fadcien // Check adcien
jmp isr90
b0bts1 fadcirq // Check adcirp
jmp isr90
b0bclr fadcirq
b0mov a,adb // To get AIN0 input data
b0mov adc_buf,a
isr90:
mov a,pflag_buf
b0mov pflag,a // Pop pflag_buf to pflag
mov a,acc_buf // Pop acc_buf to acc
reti
ADC 检测 SONIX 中断方式
最新推荐文章于 2023-12-07 22:49:31 发布