NJU6450+PCF8574T+手搓I2C Tinygo点量LCD 180X32屏幕
咸鱼上淘来的工业LCD屏幕 三个 ic驱动的 nju6450 (同款式的有sed1520 、ks0108) 180*32像素显示屏
共有20个引脚,引脚定义为:
vled- vled+ NC E3 E2 RST D7 D6 D5 D4 D3 D2 D1 D0 E1 RW A0 FR VDD VSS
灰色引脚接地 gnd 红色标记的 接+5v
PCF8574T 引脚定义:
pcf8574T esp8266
----------------------
A0 vdd------3.3vd
A1 sda------D4
A2 scl-------D2
P0 int
P1 P7
P2 P6
P3 P5
GND P4
代码如下有点凌乱
package main
import (
"machine"
"time"
//"strconv"
"tinygo.org/x/drivers/delay"
)
var font= []byte{
0x00, 0x00, 0x00, 0x00, 0x00,// (spacja)
0x00, 0x00, 0x5F, 0x00, 0x00,// !
0x00, 0x07, 0x00, 0x07, 0x00,// "
0x14, 0x7F, 0x14, 0x7F, 0x14,// #
0x24, 0x2A, 0x7F, 0x2A, 0x12,// $
0x23, 0x13, 0x08, 0x64, 0x62,// %
0x36, 0x49, 0x55, 0x22, 0x50,// &
0x00, 0x05, 0x03, 0x00, 0x00,// '
0x00, 0x1C, 0x22, 0x41, 0x00,// (
0x00, 0x41, 0x22, 0x1C, 0x00,// )
0x08, 0x2A, 0x1C, 0x2A, 0x08,// *
0x08, 0x08, 0x3E, 0x08, 0x08,// +
0x00, 0x50, 0x30, 0x00, 0x00,// ,
0x08, 0x08, 0x08, 0x08, 0x08,// -
0x00, 0x30, 0x30, 0x00, 0x00,// .
0x20, 0x10, 0x08, 0x04, 0x02,// /
0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
0x00, 0x42, 0x7F, 0x40, 0x00,// 1
0x42, 0x61, 0x51, 0x49, 0x46,// 2
0x21, 0x41, 0x45, 0x4B, 0x31,// 3
0x18, 0x14, 0x12, 0x7F, 0x10,// 4
0x27, 0x45, 0x45, 0x45, 0x39,// 5
0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
0x01, 0x71, 0x09, 0x05, 0x03,// 7
0x36, 0x49, 0x49, 0x49, 0x36,// 8
0x06, 0x49, 0x49, 0x29, 0x1E,// 9
0x00, 0x36, 0x36, 0x00, 0x00,// :
0x00, 0x56, 0x36, 0x00, 0x00,// ;
0x00, 0x08, 0x14, 0x22, 0x41,// <
0x14, 0x14, 0x14, 0x14, 0x14,// =
0x41, 0x22, 0x14, 0x08, 0x00,// >
0x02, 0x01, 0x51, 0x09, 0x06,// ?
0x32, 0x49, 0x79, 0x41, 0x3E,// @
0x7E, 0x11, 0x11, 0x11, 0x7E,// A
0x7F, 0x49, 0x49, 0x49, 0x36,// B
0x3E, 0x41, 0x41, 0x41, 0x22,// C
0x7F, 0x41, 0x41, 0x22, 0x1C,// D
0x7F, 0x49, 0x49, 0x49, 0x41,// E
0x7F, 0x09, 0x09, 0x01, 0x01,// F
0x3E, 0x41, 0x41, 0x51, 0x32,// G
0x7F, 0x08, 0x08, 0x08, 0x7F,// H
0x00, 0x41, 0x7F, 0x41, 0x00,// I
0x20, 0x40, 0x41, 0x3F, 0x01,// J
0x7F, 0x08, 0x14, 0x22, 0x41,// K
0x7F, 0x40, 0x40, 0x40, 0x40,// L
0x7F, 0x02, 0x04, 0x02, 0x7F,// M
0x7F, 0x04, 0x08, 0x10, 0x7F,// N
0x3E, 0x41, 0x41, 0x41, 0x3E,// O
0x7F, 0x09, 0x09, 0x09, 0x06,// P
0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
0x7F, 0x09, 0x19, 0x29, 0x46,// R
0x46, 0x49, 0x49, 0x49, 0x31,// S
0x01, 0x01, 0x7F, 0x01, 0x01,// T
0x3F, 0x40, 0x40, 0x40, 0x3F,// U
0x1F, 0x20, 0x40, 0x20, 0x1F,// V
0x7F, 0x20, 0x18, 0x20, 0x7F,// W
0x63, 0x14, 0x08, 0x14, 0x63,// X
0x03, 0x04, 0x78, 0x04, 0x03,// Y
0x61, 0x51, 0x49, 0x45, 0x43,// Z
0x00, 0x00, 0x7F, 0x41, 0x41,// [
0x02, 0x04, 0x08, 0x10, 0x20,// "\"
0x41, 0x41, 0x7F, 0x00, 0x00,// ]
0x04, 0x02, 0x01, 0x02, 0x04,// ^
0x40, 0x40, 0x40, 0x40, 0x40,// _
0x00, 0x01, 0x02, 0x04, 0x00,// `
0x20, 0x54, 0x54, 0x54, 0x78,// a
0x7F, 0x48, 0x44, 0x44, 0x38,// b
0x38, 0x44, 0x44, 0x44, 0x20,// c
0x38, 0x44, 0x44, 0x48, 0x7F,// d
0x38, 0x54, 0x54, 0x54, 0x18,// e
0x08, 0x7E, 0x09, 0x01, 0x02,// f
0x08, 0x14, 0x54, 0x54, 0x3C,// g
0x7F, 0x08, 0x04, 0x04, 0x78,// h
0x00, 0x44, 0x7D, 0x40, 0x00,// i
0x20, 0x40, 0x44, 0x3D, 0x00,// j
0x00, 0x7F, 0x10, 0x28, 0x44,// k
0x00, 0x41, 0x7F, 0x40, 0x00,// l
0x7C, 0x04, 0x18, 0x04, 0x78,// m
0x7C, 0x08, 0x04, 0x04, 0x78,// n
0x38, 0x44, 0x44, 0x44, 0x38,// o
0x7C, 0x14, 0x14, 0x14, 0x08,// p
0x08, 0x14, 0x14, 0x18, 0x7C,// q
0x7C, 0x08, 0x04, 0x04, 0x08,// r
0x48, 0x54, 0x54, 0x54, 0x20,// s
0x04, 0x3F, 0x44, 0x40, 0x20,// t
0x3C, 0x40, 0x40, 0x20, 0x7C,// u
0x1C, 0x20, 0x40, 0x20, 0x1C,// v
0x3C, 0x40, 0x30, 0x40, 0x3C,// w
0x44, 0x28, 0x10, 0x28, 0x44,// x
0x0C, 0x50, 0x50, 0x50, 0x3C,// y
0x44, 0x64, 0x54, 0x4C, 0x44,// z
0x00, 0x08, 0x36, 0x41, 0x00,// {
0x00, 0x00, 0x7F, 0x00, 0x00,// |
0x00, 0x41, 0x36, 0x08, 0x00,// }
0x08, 0x08, 0x2A, 0x1C, 0x08,// ->
0x08, 0x1C, 0x2A, 0x08, 0x08} // <-
const(
DISPLAY_ON=0xAF
DISPLAY_OFF=0xAE
DISPLAY_START_LINE=0xC0
PAGE_ADDRESS_SET=0xB8
COLUMN_ADDRESS_SET=0x00
ADC_CLOCKWISE=0xA0
ADC_COUNTERCLOCKWISE=0xA1
STATIC_DRIVE_ON=0xA5
STATIC_DRIVE_OFF=0xA4
DUTY_RATIO_16=0xA8
DUTY_RATIO_32=0xA9
READ_MODIFY_WRITE=0xE0
END_READ_MODIFY=0xEE
RESET=0xE2
SCREEN_WIDTH=180 //for DIP180
SCREEN_HEIGHT=32 //for DIP180
CTRL_ADC_CW=0x40
CTRL_DISPLAY_ON=0x20
CTRL_RESET_ON=0x10
left=48
middle=141
A0=machine.D8
RW=machine.D7
E1=machine.D6
E2=machine.D5
E3=machine.D1
RST=machine.D3
WRITE=0x27<<1
READ=0x27<<1|0x01
)
var scl=machine.D2 //SCL SDA
var sda=machine.D4 //SCL SDA
var lcd_x,lcd_y uint8=0,0
var r=[]byte{0x00}
func main() {
scl.Configure(machine.PinConfig{Mode: machine.PinOutput})
A0.Configure(machine.PinConfig{Mode: machine.PinOutput})
RW.Configure(machine.PinConfig{Mode: machine.PinOutput})
E1.Configure(machine.PinConfig{Mode: machine.PinOutput})
E2.Configure(machine.PinConfig{Mode: machine.PinOutput})
E3.Configure(machine.PinConfig{Mode: machine.PinOutput})
RST.Configure(machine.PinConfig{Mode: machine.PinOutput})
GLCD_Init()
GLCD_ClearScreen(0x00)
for {
for i:=0;i<180;i++{
//GLCD_ClearScreen(0x00)
if(i>0){
GLCD_GoTo(i-1,0)
GLCD_WriteData(0x00)
GLCD_GoTo(i-1,1)
GLCD_WriteData(0x00)
GLCD_GoTo(i-1,2)
GLCD_WriteData(0x00)
GLCD_GoTo(i-1,3)
GLCD_WriteData(0x00)
}
GLCD_GoTo(i,0)
GLCD_WriteString("Hello world!")
GLCD_GoTo(i,1)
GLCD_WriteString("Hello world!")
GLCD_GoTo(i,2)
GLCD_WriteString("Hello world!")
GLCD_GoTo(i,3)
GLCD_WriteString("Hello world!")
time.Sleep(time.Millisecond * 400)
}
}
}
func GLCD_WriteCommand(commandToWrite uint8,ctrl uint8){
A0.Low()
RW.Low()
if ctrl==0{
E1.High()
writeone(commandToWrite)
E1.Low()
E1.High()
}
if ctrl==1{
E2.High()
writeone(commandToWrite)
E2.Low()
E2.High()
}
if ctrl==2{
E3.High()
writeone(commandToWrite)
E3.Low()
E3.High()
}
}
func GLCD_WriteData(dataToWrite uint8){
A0.High()
RW.Low()
writeone(dataToWrite) //put Data on Dataport
if lcd_x < left {
E1.Low()
E1.High()
}
if lcd_x>=left && lcd_x<middle{
E2.Low()
E2.High()
}
if lcd_x >=middle{
E3.Low()
E3.High()
}
lcd_x=lcd_x+1
if lcd_x >= SCREEN_WIDTH{
lcd_x = 0
}
}
func GLCD_GoTo(x int,y int){
lcd_x = uint8(x)
lcd_y = uint8(y)
if x < left{
GLCD_WriteCommand(COLUMN_ADDRESS_SET | lcd_x, 0)
GLCD_WriteCommand(PAGE_ADDRESS_SET | lcd_y, 0)
GLCD_WriteCommand(COLUMN_ADDRESS_SET | 0, 1)
GLCD_WriteCommand(PAGE_ADDRESS_SET | lcd_y, 1)
GLCD_WriteCommand(COLUMN_ADDRESS_SET | 0, 2)
GLCD_WriteCommand(PAGE_ADDRESS_SET | lcd_y, 2)
}
if x >= left && (x < middle){
GLCD_WriteCommand(COLUMN_ADDRESS_SET | (lcd_x - 61), 1)
GLCD_WriteCommand(PAGE_ADDRESS_SET | lcd_y, 1)
GLCD_WriteCommand(COLUMN_ADDRESS_SET | 0, 2)
GLCD_WriteCommand(PAGE_ADDRESS_SET | lcd_y, 2)
}
if x >= middle{
GLCD_WriteCommand(COLUMN_ADDRESS_SET | (lcd_x - 141), 2)
GLCD_WriteCommand(PAGE_ADDRESS_SET | lcd_y, 2)
}
}
func GLCD_WriteChar(x string){
b:=int(x[0])-32
for i:= 0;i<5;i++{
GLCD_WriteData(font[(5*b)+i])
}
GLCD_WriteData(0x00)
}
func GLCD_WriteString(sss string){
for _,v:=range sss{
GLCD_WriteChar(string(v))
}
}
func GLCD_ClearScreen(data uint8){
for j:=0;j<4;j++{
GLCD_GoTo(0, j)
for i:=0;i<180;i++{
GLCD_WriteData(data)
}
}
GLCD_GoTo(0, 0)
}
func GLCD_Init(){
writeone(0xff)
RST.High()
time.Sleep(time.Millisecond * 2)
RST.Low()
time.Sleep(time.Millisecond * 2)
RST.High()
GLCD_WriteCommand(RESET, 0)
GLCD_WriteCommand(RESET, 1)
GLCD_WriteCommand(RESET, 2)
GLCD_WriteCommand(STATIC_DRIVE_OFF, 0)
GLCD_WriteCommand(STATIC_DRIVE_OFF, 1)
GLCD_WriteCommand(STATIC_DRIVE_OFF, 2)
GLCD_WriteCommand(DUTY_RATIO_32, 0)
GLCD_WriteCommand(DUTY_RATIO_32, 1)
GLCD_WriteCommand(DUTY_RATIO_32, 2)
GLCD_WriteCommand(DISPLAY_START_LINE | 0, 0)
GLCD_WriteCommand(DISPLAY_START_LINE | 0, 1)
GLCD_WriteCommand(DISPLAY_START_LINE | 0, 2)
GLCD_WriteCommand(DISPLAY_ON, 0)
GLCD_WriteCommand(DISPLAY_ON, 1)
GLCD_WriteCommand(DISPLAY_ON, 2)
}
//读取一个字节
func readone() uint8{
var data uint8
IC_start()
IC_WriteByte(READ)
IC_wait_ack()
data=IC_ReadByte()
IC_nack()
IC_stop()
return data
}
//写一个字节
func writeone(addr uint8) int8{
IC_start()
IC_WriteByte(WRITE)
IC_wait_ack()
IC_WriteByte(addr)
IC_wait_ack()
IC_stop()
return 0
}
func wait(){
delay.Sleep(1* time.Microsecond)
}
//开始信号
func IC_start(){
sda.Configure(machine.PinConfig{Mode: machine.PinOutput})
sda.High() //==>0
wait()
scl.High() /** Send Start **/
wait()
sda.Low() //==>1
wait()
scl.Low() //===>0
wait()
}
//停止信号
func IC_stop(){
sda.Configure(machine.PinConfig{Mode: machine.PinOutput})
sda.Low()
wait()
scl.High()
wait()
sda.High()
}
//等待反馈
func IC_wait_ack() uint8{
var r uint8
//sda.High()
sda.Configure(machine.PinConfig{Mode: machine.PinInput})
scl.High()
wait()
if sda.Get(){r=0}else{r=1}
scl.Low()
wait()
return r
}
//反馈信号
func IC_ack(){
sda.Configure(machine.PinConfig{Mode: machine.PinOutput})
sda.Low()
scl.High()
wait()
scl.Low()
wait()
}
//无反馈
func IC_nack(){
sda.Configure(machine.PinConfig{Mode: machine.PinOutput})
sda.High()
wait()
scl.High()
wait()
scl.Low()
}
//写字节
func IC_WriteByte(wdata uint8){
var i uint8
sda.Configure(machine.PinConfig{Mode: machine.PinOutput})
for i=0;i<8;i++ {
if (wdata&0x80)>0 {sda.High()}else{sda.Low()}
scl.High()
wait()
scl.Low()
wait()
wdata<<=1
}
}
//读
func IC_ReadByte() uint8{
var i,IC_data uint8
IC_data=0
for i=0;i<8;i++ {
scl.High()
wait()
IC_data<<=1
sda.Configure(machine.PinConfig{Mode: machine.PinInput})
if sda.Get() {
IC_data++
}
scl.Low()
wait()
}
return IC_data
}
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。