'Init SSH1106
$lib "i2c_twi.lbx" ' we do not use software emulated I2C but the TWI
$lib "glcdSSD1306-I2C.lib" ' override the default lib with this special one
$regfile = "m328pdef.dat"
$hwstack = 32
$swstack = 32
$framesize = 32
$crystal = 16000000
Config Clockdiv = 1 ' make sure the chip runs at 16 MHz
Config Submode = New
Config Scl = Portc.5 ' used i2c pins
Config Sda = Portc.4
Config Twi = 400000 ' i2c speed
Declare Sub Initssh1106
Declare Sub Xmbyte(byreg R16 As Byte)
I2cinit
$lib "i2c_twi.lbx" ' we do not use software emulated I2C but the TWI
$lib "glcdSSD1306-I2C.lib" ' override the default lib with this special one
Config Graphlcd = Custom , Cols = 128 , Rows = 64 , Lcdname = "SSD1306"
Initssh1106
Waitms 100
'Cls
Setfont Font16x16 ' select font
Lcdat 1 , 3 , " " 'This is Cls for font 16*16
Lcdat 3 , 3 , " "
Lcdat 5 , 3 , " "
Lcdat 7 , 3 , " "
Lcdat 1 , 3 , "BASCOM"
Lcdat 3 , 3 , "1995-"
Setfont Font8x8tt
Lcdat 5 , 3 , "MCS Electronics" , 1
Lcdat 7 , 3 , "MCS Electronics"
End
Sub Initssh1106
Twcr.2 = 0 'Release Twi I/O pin
Portc.4 = 0
Portc.5 = 0
Ddrc.4 = 0
Ddrc.5 = 0
Waitus 500
Ddrc.4 = 1 'Start
Waitus 2
Ddrc.5 = 1
Waitus 10
Xmbyte(&H78)
Xmbyte(&Hae)
Xmbyte(&Hd5)
Xmbyte(&H80)
Xmbyte(&H00)
Xmbyte(&H3f)
Xmbyte(&Hd3)
Xmbyte(&H00)
Xmbyte(&H40)
Xmbyte(&H8d)
Xmbyte(&H14)
Xmbyte(&H20)
Xmbyte(&H00)
Xmbyte(&Ha1)
Xmbyte(&Hc8)
Xmbyte(&Hda)
Xmbyte(&H12)
Xmbyte(&H81)
Xmbyte(&Hff)
Xmbyte(&Hd9)
Xmbyte(&Hf1)
Xmbyte(&Hdb)
Xmbyte(&H40)
Xmbyte(&Ha4)
Xmbyte(&Ha6)
Xmbyte(&Haf)
Ddrc.5 = 0 'clk =1 Stop
Waitus 2
Ddrc.4 = 0 ' Sda=1
Waitms 2
Twcr.2 = 1 'Give I/O back to Twi
Waitus 10
End Sub
Sub Xmbyte(byreg R16 As Byte)
$asm
ldi r17,8
Xmbyte1:
sbrc r16,7
cbi ddrc,4 'sda=1
sbrs r16,7
sbi ddrc,4
rcall waitus2
cbi ddrc,5 'clk high
rcall waitus2
sbi ddrc,5
rcall waitus2
lsl r16 'next bit
dec r17
brne xmbyte1
sbi ddrc,4 'SDat=0 Ack
rcall waitus2
cbi ddrc,5 'clk high
rcall waitus2
sbi ddrc,5
$end Asm
Goto Endxmbyte
Waitus2:
Waitus 2
Return
Endxmbyte:
Waitus 10
End Sub
$include "font16x16.font"
$include "font8x8TT.font"
|