Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pico-micropython-grove
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Embeded
pico-micropython-grove
Commits
69436a06
提交
69436a06
authored
2月 03, 2021
作者:
唐睿骞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add lcd1602 lib and demo
上级
d0198040
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
214 行增加
和
0 行删除
+214
-0
lcd1602.py
I2C/lcd1602.py
+199
-0
lcd1602.py
example/lcd1602.py
+15
-0
没有找到文件。
I2C/lcd1602.py
0 → 100644
浏览文件 @
69436a06
from
machine
import
I2C
,
Pin
import
time
class
Display
(
object
):
# color define
WHITE
=
0
RED
=
1
GREEN
=
2
BLUE
=
3
REG_RED
=
0x04
# pwm2
REG_GREEN
=
0x03
# pwm1
REG_BLUE
=
0x02
# pwm0
REG_MODE1
=
0x00
REG_MODE2
=
0x01
REG_OUTPUT
=
0x08
#commands
LCD_CLEARDISPLAY
=
0x01
LCD_RETURNHOME
=
0x02
LCD_ENTRYMODESET
=
0x04
LCD_DISPLAYCONTROL
=
0x08
LCD_CURSORSHIFT
=
0x10
LCD_FUNCTIONSET
=
0x20
LCD_SETCGRAMADDR
=
0x40
LCD_SETDDRAMADDR
=
0x80
#flags for display entry mode
LCD_ENTRYRIGHT
=
0x00
LCD_ENTRYLEFT
=
0x02
LCD_ENTRYSHIFTINCREMENT
=
0x01
LCD_ENTRYSHIFTDECREMENT
=
0x00
#flags for display on/off control
LCD_DISPLAYON
=
0x04
LCD_DISPLAYOFF
=
0x00
LCD_CURSORON
=
0x02
LCD_CURSOROFF
=
0x00
LCD_BLINKON
=
0x01
LCD_BLINKOFF
=
0x00
#flags for display/cursor shift
LCD_DISPLAYMOVE
=
0x08
LCD_CURSORMOVE
=
0x00
LCD_MOVERIGHT
=
0x04
LCD_MOVELEFT
=
0x00
#flags for function set
LCD_8BITMODE
=
0x10
LCD_4BITMODE
=
0x00
LCD_2LINE
=
0x08
LCD_1LINE
=
0x00
LCD_5x10DOTS
=
0x04
LCD_5x8DOTS
=
0x00
def
__init__
(
self
,
i2c
,
lines
,
dotsize
,
lcd_addr
=
0x3E
,
rgb_addr
=
0x62
):
self
.
i2c
=
i2c
self
.
lcd_address
=
lcd_addr
self
.
rgb_address
=
rgb_addr
self
.
line
=
lines
self
.
currline
=
0
;
self
.
display_control
=
self
.
LCD_DISPLAYON
if
(
lines
>
1
):
self
.
display_control
|=
self
.
LCD_2LINE
#for some 1 line displays you can select a 10 pixel high font
if
(
dotsize
!=
0
&
lines
==
1
):
self
.
display_control
|=
self
.
LCD_5x10DOTS
#SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
#according to datasheet, we need at least 40ms after power rises above 2.7V
#before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
time
.
sleep_ms
(
50
)
#this is according to the hitachi HD44780 datasheet
#page 45 figure 23
#Send function set command sequence
self
.
command
(
self
.
LCD_FUNCTIONSET
|
self
.
display_control
)
time
.
sleep_us
(
4500
)
#wait more than 4.1ms
#second try
self
.
command
(
self
.
LCD_FUNCTIONSET
|
self
.
display_control
)
time
.
sleep_us
(
150
)
#third go
self
.
command
(
self
.
LCD_FUNCTIONSET
|
self
.
display_control
)
#finally, set # lines, font size, etc.
self
.
command
(
self
.
LCD_FUNCTIONSET
|
self
.
display_control
)
#turn the display on with no cursor or blinking default
self
.
display_mode
=
self
.
LCD_DISPLAYON
|
self
.
LCD_CURSOROFF
|
self
.
LCD_BLINKOFF
self
.
display
()
#clear it off
self
.
clear
()
#Initialize to default text direction (for romance languages)
self
.
display_mode
=
self
.
LCD_ENTRYLEFT
|
self
.
LCD_ENTRYSHIFTDECREMENT
#set the entry mode
self
.
command
(
self
.
LCD_ENTRYMODESET
|
self
.
display_mode
)
#backlight init
self
.
set_reg
(
0
,
0
)
self
.
set_reg
(
1
,
0
)
self
.
set_reg
(
0x08
,
0xAA
)
#all led control by pwm
self
.
set_rgb
(
255
,
255
,
255
)
def
clear
(
self
):
self
.
command
(
self
.
LCD_CLEARDISPLAY
)
#clear display, set cursor position to zero
time
.
sleep_ms
(
2
)
#this command takes a long time!
def
home
(
self
):
self
.
command
(
self
.
LCD_RETURNHOME
)
#set cursor position to zero
time
.
sleep_ms
(
2
)
#this command takes a long time!
def
setCursor
(
self
,
col
,
row
):
col
=
(
col
|
0x80
)
if
row
==
0
else
(
col
|
0xc0
)
self
.
command
(
col
)
#Turn the display on/off (quickly)
def
no_display
(
self
):
self
.
display_control
&=
~
self
.
LCD_DISPLAYON
self
.
command
(
self
.
LCD_DISPLAYCONTROL
|
self
.
display_control
)
def
display
(
self
):
self
.
display_control
|=
self
.
LCD_DISPLAYON
self
.
command
(
self
.
LCD_DISPLAYCONTROL
|
self
.
display_control
)
#Turns the underline cursor on/off
def
no_cursor
(
self
):
self
.
display_control
&=
~
self
.
LCD_CURSORON
self
.
command
(
self
.
LCD_DISPLAYCONTROL
|
self
.
display_control
)
def
cursor
(
self
):
self
.
display_control
|=
self
.
LCD_CURSORON
self
.
command
(
self
.
LCD_DISPLAYCONTROL
|
self
.
display_control
)
#Turn on and off the blinking cursor
def
no_blink
(
self
):
self
.
display_control
&=
~
self
.
LCD_BLINKON
self
.
command
(
self
.
LCD_DISPLAYCONTROL
|
self
.
display_control
)
def
blink
(
self
):
self
.
display_control
|=
self
.
LCD_BLINKON
self
.
command
(
self
.
LCD_DISPLAYCONTROL
|
self
.
display_control
)
def
autoscroll
(
self
):
self
.
display_control
|=
self
.
LCD_ENTRYSHIFTINCREMENT
self
.
command
(
self
.
LCD_DISPLAYCONTROL
|
self
.
display_control
)
def
no_autoscroll
(
self
):
self
.
display_control
&=
~
self
.
LCD_ENTRYSHIFTINCREMENT
self
.
command
(
self
.
LCD_DISPLAYCONTROL
|
self
.
display_control
)
def
create_char
(
self
,
location
,
charmap
):
location
&=
0x07
self
.
command
(
LCD_SETCGRAMADDR
|
(
location
<<
3
))
dta
=
bytearray
([
charmap
])
self
.
i2c
.
writeto_mem
(
self
.
address
,
0x40
,
dta
)
def
command
(
self
,
command
):
command
=
bytearray
([
command
])
self
.
i2c
.
writeto_mem
(
self
.
lcd_address
,
0x80
,
command
)
def
write
(
self
,
command
):
command
=
bytearray
([
command
])
self
.
i2c
.
writeto_mem
(
self
.
lcd_address
,
0x40
,
command
)
def
print
(
self
,
text
):
for
char
in
text
:
self
.
write
(
ord
(
char
))
def
set_reg
(
self
,
addr
,
value
):
value
=
bytearray
([
value
])
self
.
i2c
.
writeto_mem
(
self
.
rgb_address
,
addr
,
bytearray
([]))
self
.
i2c
.
writeto_mem
(
self
.
rgb_address
,
addr
,
value
)
def
set_rgb
(
self
,
red
,
green
,
blue
):
r
=
int
(
red
)
g
=
int
(
green
)
b
=
int
(
blue
)
self
.
set_reg
(
self
.
REG_RED
,
r
)
self
.
set_reg
(
self
.
REG_GREEN
,
g
)
self
.
set_reg
(
self
.
REG_BLUE
,
b
)
def
set_color
(
self
,
color
):
if
(
color
==
0
):
self
.
set_rgb
(
255
,
255
,
255
)
elif
(
color
==
1
):
self
.
set_rgb
(
255
,
0
,
0
)
elif
(
color
==
2
):
self
.
set_rgb
(
0
,
255
,
0
)
elif
(
color
==
3
):
self
.
set_rgb
(
0
,
0
,
255
)
else
:
return
\ No newline at end of file
example/lcd1602.py
0 → 100644
浏览文件 @
69436a06
import
lcd1602
from
machine
import
I2C
,
Pin
from
time
import
sleep
i2c
=
I2C
(
1
,
scl
=
Pin
(
7
),
sda
=
Pin
(
6
),
freq
=
400000
)
d
=
lcd1602
.
Display
(
i2c
,
2
,
16
)
d
.
set_rgb
(
255
,
0
,
0
)
sleep
(
1
)
d
.
home
()
d
.
print
(
'Hello '
)
d
.
set_rgb
(
0
,
255
,
0
)
sleep
(
1
)
d
.
setCursor
(
0
,
1
)
d
.
print
(
'word '
)
d
.
set_rgb
(
0
,
0
,
255
)
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论