本帖最后由 taotie 于 2019-12-11 17:36 編輯
' test OLED display 128*64 with glcdSSD1306-I2C.lib
' bascom 2.0.7.8
$regfile = "m8def.dat"
$hwstack = 32
$swstack = 32
$framesize = 32
$crystal = 8000000
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庫替換默認庫
'#if _build < 20784
'Dim ___lcdrow As Byte , ___lcdcol As Byte ' 老版本變量格式進行編譯
'#endif
Config Graphlcd = Custom , Cols = 128 , Rows = 64 , Lcdname = "SSD1306" '配置圖形液晶顯示器
Showpic 0 , 0 , Plaatje '在液晶顯示器0,0展示128x64圖片
Wait 3
Config Adc = Single , Prescaler = Auto '定義ADC為單次運行模式,轉換時鐘-自動,未使用內部參考電壓 Reference = Internal
Start Adc 'ATmega88可以不要Start Adc語句,ATmega8就一定要這個語句
Dim W As WORD, Channel As Byte, D as string*5, C As Byte
Channel = 0 '現在從通道0讀取A/D值
'C = 1
Cls
Setfont font12x16
Lcdat 1, 16 , chr(128);chr(129);chr(130);chr(131)
Do
'Cls
W = Getadc(Channel)
W = W*5
D=str(w)
D= format(d, "0.000")
wait 1 '設置字體
Setfont font8x8tt
Lcdat 4, 8 , "AD =" '在液晶顯示器顯示字符串
Lcdat 4, 42 , Channel '在液晶顯示器顯示AD通道號
Lcdat 4, 56, "#"
'wait 1
Setfont Font12x16
Lcdat 6, 1 , d '在液晶顯示器顯示ad采樣值
Lcdat 6 , 56 ,"V" '在液晶顯示器顯示字符串v
wait 2
Incr Channel
if Channel=4 then Channel=6
If Channel > 7 Then Channel = 0
Loop
$include "../font12x16.font" '包含的字體文件
$include "../font8x8tt.font" '包含的字體文件
Plaatje:
$bgf "../picture.bgf"
|