- 阅读权限
- 200
- UID
- 2
- 帖子
- 343
- 精华
- 0
- 注册时间
- 2013-2-20
- 在线时间
- 368 小时
- UID
- 2
- 帖子
- 343
- 精华
- 0
- 注册时间
- 2013-2-20
- 在线时间
- 368 小时
|
淘了几片COG9616A,Drive IC:ST7549。试着驱动了一下,成功点亮。
<代码>
$regfile = "m48def.dat"
$crystal = 8000000
$hwstack = 40
$swstack = 40
$framesize = 64
'*******************************************************************************
Declare Sub I2c_start()
Declare Sub I2c_stop()
Declare Sub I2c_send_byte(byval Wbyte As Byte)
Declare Sub Lcd_init()
Declare Sub Lcd_cls(byval Cls_byte As Byte)
Declare Sub Lcd_dat(byval Dat_byte As Byte)
Declare Sub Lcd_cmd(byval Cmd_byte As Byte)
Declare Sub Lcd_dis_byte(byval Dx As Byte , Byval Dy As Byte , Byval Dat As Byte)
Declare Sub Lcd_dis_char(byval Dx As Byte , Byval Dy As Byte , Byval Hex_char As String * 1)
Declare Sub Lcd_dis_str(byval Dx As Byte , Byval Dy As Byte , Byval Dis_str As String * 16)
'*******************************************************************************
Config Timer1 = Timer , Prescale = 256
On Timer1 Timer1_int
Const Timer1_preload = 34286 '1000毫秒
'-------------------------------------------------------------------------------
Config Watchdog = 2048 '2048ms
'*******************************************************************************
'引脚定义
Bla Alias Portd.7 : Ddrd.7 = 1
Scl Alias Portd.6 : Ddrd.6 = 1
Sda Alias Portd.5 : Ddrd.5 = 1
Res Alias Portd.4 : Ddrd.4 = 1
Sda_io Alias Ddrd.5
Sda_i Alias Pind.5
Led Alias Portc.0 : Ddrc.0 = 1 : Led = 1
'*******************************************************************************
Dim I As Byte , J As Byte , K As Byte
Dim X As Byte , Y As Byte
Dim Mybyte As Byte , Myword As Word , Mylong As Long
'###############################################################################
Enable Timer1
Enable Interrupts
'*******************************************************************************
Led = 1
Bla = 1
Waitms 500
Lcd_init ' 初始化
Waitms 10
Lcd_cls &H00
'(
Lcd_dis_char 0 , 0 , "A"
Lcd_dis_char 6 , 0 , "B"
Lcd_dis_char 12 , 0 , "C"
Lcd_dis_char 18 , 0 , "D"
Lcd_dis_char 24 , 0 , "E"
Lcd_dis_char 30 , 0 , "F"
Lcd_dis_char 0 , 1 , "1"
Lcd_dis_char 6 , 1 , "2"
Lcd_dis_char 12 , 1 , "3"
Lcd_dis_char 18 , 1 , "4"
Lcd_dis_char 24 , 1 , "5"
Lcd_dis_char 30 , 1 , "6"
Lcd_dis_char 36 , 1 , "7"
Lcd_dis_char 42 , 1 , "8"
Lcd_dis_char 48 , 1 , "9"
Lcd_dis_char 54 , 1 , "0"
')
'Lcd_dis_char 54 , 1 , "0"
Lcd_dis_str 0 , 0 , "ABCDEF12"
Do
Loop
'###############################################################################
Sub Lcd_cls(byval Cls_byte As Byte)
Lcd_cmd &H20
Lcd_cmd &H44 ' // Set Y address=00 page
Lcd_cmd &H80 ' // Set X address=00 colum
For J = 0 To 95
Lcd_dat Cls_byte
Next
Lcd_cmd &H20
Lcd_cmd &H45 ' // Set Y address=00 page
Lcd_cmd &H80 ' // Set X address=00 colum
For K = 0 To 95
Lcd_dat Cls_byte
Next
End Sub
'-------------------------------------------------------------------------------
Sub Lcd_dis_byte(byval Dx As Byte , Byval Dy As Byte , Byval Dat As Byte)
If Dx < 45 Then
Dx = &HB3 + Dx
Else
Dx = &HDF - Dx
End If
Dy = Dy + &H44
Lcd_cmd &H20
Lcd_cmd Dy
Lcd_cmd Dx
Lcd_dat Dat
End Sub
'-------------------------------------------------------------------------------
Sub Lcd_dis_char(byval Dx As Byte , Byval Dy As Byte , Byval Hex_char As String * 1)
Local Dat_hex As String * 8
Local Dat_chr As String * 1
Mybyte = Hexval(hex_char)
Myword = Mybyte * 6
For J = 0 To 5 '6X8点阵
Mybyte = Lookup(myword , Digit_lattice)
Lcd_dis_byte Dx , Dy , Mybyte
Dx = Dx + 1
Myword = Myword + 1
Next
End Sub
'-------------------------------------------------------------------------------
Sub Lcd_dis_str(byval Dx As Byte , Byval Dy As Byte , Byval Dis_str As String * 16)
Local Chr_str As String * 1
Local Len_str As Byte
Local Sx As Byte
Local Index As Byte
Len_str = Len(dis_str)
For Index = 1 To Len_str
Chr_str = Mid(dis_str , Index , 1)
Mybyte = Hexval(chr_str)
Myword = Mybyte * 24
Sx = Dx
For J = 1 To 12 '12X16点阵
Mybyte = Lookup(myword , Font12x16)
Lcd_dis_byte Sx , 0 , Mybyte
Sx = Sx + 1
Myword = Myword + 1
Next
Sx = Dx
For J = 1 To 12 '12X16点阵
Mybyte = Lookup(myword , Font12x16)
Lcd_dis_byte Sx , 1 , Mybyte
Sx = Sx + 1
Myword = Myword + 1
Next
Dx = Dx + 12
Next
End Sub
'-------------------------------------------------------------------------------
Sub Lcd_init()
Res = 0
Waitms 10
Res = 1
Waitms 10
Lcd_cmd &H21
Lcd_cmd &H16 'bias = 1/5
Lcd_cmd &H21
Lcd_cmd &H0C
Lcd_cmd &H23
Lcd_cmd &H0B
Lcd_cmd &H20
Lcd_cmd &H05
Lcd_cmd &H21
Lcd_cmd &HD0
Lcd_cmd &H20
Lcd_cmd &H0C
End Sub
'-------------------------------------------------------------------------------
Sub Lcd_cmd(byval Cmd_byte As Byte)
I2c_start
'发送总线上器件的SLAVE Address
I2c_send_byte &H78 '01111(SA1)(SA0)(RW) 'SA1=0 SA0=0 RW=0写
'发送Control Byte
' (Co)(A0)000000(A) Co=0 A0=0指令
'Co=0是表示这是最后一个指令
'后面要Stop总线再重新开始的
I2c_send_byte &H00
'发送数据(对于芯片是指令,所有的字节都是作为数据发送)
I2c_send_byte Cmd_byte
I2c_stop
End Sub
'-------------------------------------------------------------------------------
Sub Lcd_dat(byval Dat_byte As Byte)
I2c_start
'发送总线上器件的SLAVE Address
'01111(SA1)(SA0)(RW) 'SA1=0 SA0=0 RW=0写
I2c_send_byte &H78
'检测ACK应答信号
'发送Control Byte
' (Co)(A0)000000(A) Co=0 A0=1数据
'Co=0是表示这是最后一个指令
'后面要Stop总线再从新开始的
I2c_send_byte &H40
'发送数据(所有发送过去的Byte都作为数据发送)
I2c_send_byte Dat_byte
I2c_stop
End Sub
'-------------------------------------------------------------------------------
Sub I2c_start()
'启动I2C
Sda = 1
Scl = 1
nop
Sda = 0
nop
End Sub
'-------------------------------------------------------------------------------
Sub I2c_stop()
'停止I2C
Sda = 0
Scl = 1
nop
Sda = 1
nop
End Sub
'-------------------------------------------------------------------------------
Sub I2c_send_byte(byval Wbyte As Byte)
Sda = 1
Scl = 0
For I = 7 To 0 Step -1
Sda = Wbyte.i
Scl = 1
nop
Scl = 0
nop
Next
'Check ack
Scl = 1
Sda = 1
nop
Scl = 0
End Sub
'*******************************************************************************
Digit_lattice:
Data 0 , 62 , 81 , 73 , 69 , 62 ' 0
Data 0 , 0 , 66 , 127 , 64 , 0 ' 1
Data 0 , 98 , 81 , 73 , 73 , 70 ' 2
Data 0 , 34 , 73 , 73 , 73 , 54 ' 3
Data 0 , 24 , 20 , 18 , 127 , 16 ' 4
Data 0 , 47 , 73 , 73 , 73 , 49 ' 5
Data 0 , 60 , 74 , 73 , 73 , 48 ' 6
Data 0 , 1 , 113 , 9 , 5 , 3 ' 7
Data 0 , 54 , 73 , 73 , 73 , 54 ' 8
Data 0 , 6 , 73 , 73 , 41 , 30 ' 9
Data 0 , 126 , 17 , 17 , 17 , 126 ' A
Data 0 , 127 , 73 , 73 , 73 , 54 ' B
Data 0 , 62 , 65 , 65 , 65 , 34 ' C
Data 0 , 127 , 65 , 65 , 65 , 62 ' D
Data 0 , 127 , 73 , 73 , 73 , 65 ' E
Data 0 , 127 , 9 , 9 , 9 , 1 ' F
'-------------------------------------------------------------------------------
Font12x16:
Data 0 , 0 , 248 , 254 , 6 , 131 , 195 , 99 , 51 , 30 , 254 , 248 , 0 , 0 , 7 , 31 , 27 , 49 , 48 , 48 , 48 , 24 , 31 , 7 ' 0
Data 0 , 0 , 0 , 12 , 12 , 14 , 255 , 255 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 48 , 48 , 48 , 63 , 63 , 48 , 48 , 48 , 0 ' 1
Data 0 , 0 , 28 , 30 , 7 , 3 , 131 , 195 , 227 , 119 , 62 , 28 , 0 , 0 , 56 , 60 , 62 , 55 , 51 , 49 , 48 , 48 , 48 , 48 ' 2
Data 0 , 0 , 12 , 14 , 7 , 195 , 195 , 195 , 195 , 231 , 126 , 60 , 0 , 0 , 12 , 28 , 56 , 48 , 48 , 48 , 48 , 57 , 31 , 14 ' 3
Data 0 , 0 , 192 , 224 , 112 , 56 , 28 , 14 , 255 , 255 , 0 , 0 , 0 , 0 , 7 , 7 , 6 , 6 , 6 , 6 , 63 , 63 , 6 , 6 ' 4
Data 0 , 0 , 120 , 127 , 103 , 99 , 99 , 99 , 99 , 227 , 195 , 131 , 0 , 0 , 12 , 28 , 56 , 48 , 48 , 48 , 48 , 56 , 31 , 15 ' 5
Data 0 , 0 , 192 , 240 , 248 , 220 , 206 , 199 , 195 , 195 , 128 , 0 , 0 , 0 , 15 , 31 , 57 , 48 , 48 , 48 , 48 , 57 , 31 , 15 ' 6
Data 0 , 0 , 3 , 3 , 3 , 3 , 3 , 195 , 243 , 63 , 15 , 3 , 0 , 0 , 0 , 0 , 48 , 60 , 15 , 3 , 0 , 0 , 0 , 0 ' 7
Data 0 , 0 , 0 , 188 , 254 , 231 , 195 , 195 , 231 , 254 , 188 , 0 , 0 , 0 , 15 , 31 , 57 , 48 , 48 , 48 , 48 , 57 , 31 , 15 ' 8
Data 0 , 0 , 60 , 126 , 231 , 195 , 195 , 195 , 195 , 231 , 254 , 252 , 0 , 0 , 0 , 48 , 48 , 48 , 56 , 28 , 14 , 7 , 3 , 0 ' 9
Data 0 , 0 , 0 , 0 , 224 , 252 , 31 , 31 , 252 , 224 , 0 , 0 , 0 , 0 , 56 , 63 , 7 , 6 , 6 , 6 , 6 , 7 , 63 , 56 ' A
Data 0 , 0 , 255 , 255 , 195 , 195 , 195 , 195 , 231 , 254 , 188 , 0 , 0 , 0 , 63 , 63 , 48 , 48 , 48 , 48 , 48 , 57 , 31 , 15 ' B
Data 0 , 0 , 240 , 252 , 14 , 7 , 3 , 3 , 3 , 7 , 14 , 12 , 0 , 0 , 3 , 15 , 28 , 56 , 48 , 48 , 48 , 56 , 28 , 12 ' C
Data 0 , 0 , 255 , 255 , 3 , 3 , 3 , 3 , 7 , 14 , 252 , 240 , 0 , 0 , 63 , 63 , 48 , 48 , 48 , 48 , 56 , 28 , 15 , 3 ' D
Data 0 , 0 , 255 , 255 , 195 , 195 , 195 , 195 , 195 , 195 , 3 , 3 , 0 , 0 , 63 , 63 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 ' E
Data 0 , 0 , 255 , 255 , 195 , 195 , 195 , 195 , 195 , 195 , 3 , 3 , 0 , 0 , 63 , 63 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ' F
'===============================================================================
Timer1_int:
Timer1 = Timer1_preload '1000毫秒
Toggle Led
Return
'*******************************************************************************
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
|