'*********现在给芯片供电*********************
On ADC Adc_isr Nosave 'Nosave指定的中断发生时执行子程序。
Enable ADC
Enable Interrupts
'*******变量***********************
Dim W As long , Channel As Byte
Dim i As long
Dim d As string*5
Channel = 0
'************主程序************************
Do
Channel = 0 '现在从通道0读取A/D值
'闲置将使微型计算机进入睡眠状态。.
'一个中断就会唤醒微型计算机.
Start ADC
Idle
nop
nop
Stop ADC
waitms 10
i=w*5000 '分度转换
i=i/1023
i=i-1250
i=i/5
'**********误差校准*************
i=i-1
if i>10 then i=i+1
if i>73 then i=i-1
if i>124 then i=i-1
if i>139 then i=i+1
if i>=183 then i=i+1
if i>221 then i=i-1
if i>226 then i=i+1
if i>267 then i=i-1
if i>269 then i=i+1
if i>296 then i=i-1
if i>314 then i=i+1'太烦。。。后面不管了
'************************************
d=str(i) '数值转字符串
d= format(d, "+000") '输出结果格式化------覆盖显示模式避免显示跳动
Setfont Font12x16
Lcdat 2, 2 , "Channel " ;": "; Channel
Lcdat 6, 2 ,"value";": "; d
Loop
End
Sub Adc_isr()
$asm
push r26 '在堆栈上推送寄存器 STACK ← Rr
push r27
push r24
in r24,SREG '进入 Por Rd ← P
push r24
push r25
$End Asm
W = GetADC(Channel)
$Asm
pop r25 '从堆栈弹出寄存器 Rd ← STACK
pop r24
Out SREG,r24
pop r24
pop r27
pop r26
$end Asm
End Sub