'*********現(xiàn)在給芯片供電*********************
On ADC Adc_isr Nosave 'Nosave指定的中斷發(fā)生時執(zhí)行子程序。
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 '現(xiàn)在從通道0讀取A/D值
'閑置將使微型計算機進入睡眠狀態(tài)。.
'一個中斷就會喚醒微型計算機.
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) '數(shù)值轉字符串
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