|
本帖最后由 taotie 于 2020-9-3 13:13 編輯
屏幕截圖(41).png (192.45 KB, 下載次數(shù): 106)
下載附件
2020-9-3 13:11 上傳
rem Main.bas file generated by New Project wizard
rem
rem Created: 周二 8月 25 2020 TAOTIE
rem Processor: ATmega8
rem Compiler: BASCOM-AVR
rem Write your code here
$RegFile = "m8def.dat"
$Crystal = 8000000
'$Baud = 19200
$HWstack = 40
$SWstack = 8
$FrameSize = 40
Declare Sub Adc_isr()
'配置單模式和自動預(yù)分頻器設(shè)置
'單模式必須與GETADC()函數(shù)一起使用
'預(yù)分頻器將內(nèi)部時(shí)鐘除以2、4、8、16、32、64或128
'因?yàn)锳DC需要一個(gè)50-200千赫的時(shí)鐘
'自動功能將選擇可能的最高時(shí)鐘頻率
Config Adc = Free , Prescaler = Auto , Reference = avcc 'Internal
'*******************OLED配置*********************************************************************************
Config Scl = Portc.5 ' 用I2C引腳Scl = Portc.5 ,Sda = Portc.4
Config Sda = Portc.4
Config Twi = 400000 ' i2c 的速度
I2cinit
$lib "i2c_twi.lbx" ' 不使用模擬I2c的軟件,而是使用twi
$lib "glcdSSD1306-I2C.lib" ' 用glcdSSD1306-I2C庫替換默認(rèn)庫要添加在bascom avr庫中
#if _build < 20784
Dim ___lcdrow As Byte , ___lcdcol As Byte ' 老版本變量格式進(jìn)行編譯
#endif
Config Graphlcd = Custom , Cols = 128 , Rows = 64 , Lcdname = "SSD1306" '配置圖形顯示器
'*********現(xiàn)在給芯片供電*********************
On ADC Adc_isr Nosave 'Nosave指定的中斷發(fā)生時(shí)執(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值
'閑置將使微型計(jì)算機(jī)進(jìn)入睡眠狀態(tài)。.
'一個(gè)中斷就會喚醒微型計(jì)算機(jī).
Start ADC
Idle
nop
nop
Stop ADC
waitms 10
i=w*5000 '分度轉(zhuǎn)換
i=i/1023
i=i-1250
i=i/5
'**********誤差校準(zhǔn)*************
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ù)值轉(zhuǎn)字符串
d= format(d, "+000") '輸出結(jié)果格式化------覆蓋顯示模式避免顯示跳動
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 '進(jìn)入 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
$include "../Font12x16.font"
|
評分
-
查看全部評分
|