本帖最后由 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"
|