#define uchar unsigned char
#define uint unsigned int
uchar rebuf[11]
uchar tembuf[2]={28,20}
sbitsce = P0^0 //片选
sbitres = P0^1 //复位,0复位
sbitdc = P0^2 //1写数据,0写指令
sbitsdin = P0^3 //数据
sbitsclk = P0^4 //时钟
sbiten = P3^2
sbitkey1 = P1^0
sbitkey2 = P1^1
sbitkey3 = P1^2
sbitkey4 = P1^3
sbitkey5 = P1^4
sbitkey6 = P1^5
sbitalarm = P2^7
uchar dp=0,re_data,keynum = 0
bit full=0,f_alarm=0,m_alarm = 0
unsigned char code shuzi[]={
/*-- 文字: 0 --*/
/*-- 宋体12 此字凳裤体下对应的点阵为:宽x高=8x16 --*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
/*-- 文字: 1 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高尺消=8x16 --*/
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,
/*-- 文字: 2 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,
/枣困简*-- 文字: 3 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,
/*-- 文字: 4 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,
/*-- 文字: 5 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,
/*-- 文字: 6 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,
/*-- 文字: 7 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,
/*-- 文字: 8 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,
/*-- 文字: 9 --*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,
/*-- 文字: . --10*/
/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: : --11*/
/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,
/*-- 调入了一幅图像:这是您新建的图像 --12*/
/*-- 宽度x高度=8x16 --*/
0x0C,0x12,0x0C,0x80,0x40,0x20,0x20,0x20,0x00,0x00,0x00,0x0F,0x10,0x20,0x20,0x20,
}
unsigned char code hanzi[]=
{
/*-- 文字: 光 0--*/
/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x40,0x42,0x44,0x5C,0xC8,0x40,0x7F,0x40,0xC0,0x50,0x4E,0x44,0x60,0x40,0x00,
0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x78,0x00,
/*-- 空白 1--*/
/*-- 宽度x高度=16x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 一级光 2--*/
/*-- 宽度x高度=16x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xF0,0xF0,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 二级光 3--*/
/*-- 宽度x高度=16x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xF0,0xF0,0xF0,0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 三级光 4--*/
/*-- 宽度x高度=16x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xF0,0xF0,0x00,0x00,0x00,0x00,0x00,
0xF0,0xF0,0xF0,0x00,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,
/*-- 四级光 5--*/
/*-- 宽度x高度=16x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xF0,0xF0,0x00,0xFF,0xFF,0xFF,0x00,
0xF0,0xF0,0xF0,0x00,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0x00,
/*-- 文字: 报 6--*/
/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/
0x08,0x08,0x88,0xFF,0x48,0x28,0x00,0xFF,0xC1,0x41,0x41,0x49,0x51,0xCF,0x00,0x00,
0x01,0x41,0x80,0x7F,0x00,0x00,0x00,0xFF,0x40,0x23,0x14,0x1C,0x33,0x60,0x20,0x00,
/*-- 文字: 警 7--*/
/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/
0x20,0x1A,0xFA,0xAF,0xAA,0xEF,0x0A,0xFA,0x10,0x8F,0x54,0x24,0x5C,0x84,0x04,0x00,
0x02,0x02,0x02,0xEA,0xAA,0xAA,0xAB,0xAA,0xAB,0xAA,0xAA,0xEA,0x02,0x02,0x03,0x00,
/*-- 文字: 温 8--*/
/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/
0x10,0x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00,
0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00,
/*-- 文字: 度 9--*/
/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5,0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00,
0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A,0x12,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00,
/*-- 文字: 高 10--*/
/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/
0x04,0x04,0x04,0x04,0x74,0x54,0x55,0x56,0x54,0x54,0x74,0x04,0x04,0x04,0x04,0x00,
0x00,0xFF,0x01,0x01,0x3D,0x25,0x25,0x25,0x25,0x25,0x3D,0x41,0x81,0x7F,0x00,0x00,
/*-- 文字: 低 11--*/
/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/
0x40,0x20,0xF0,0x0C,0x07,0x02,0xFC,0x44,0x44,0x42,0xFE,0x43,0x43,0x42,0x40,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x7F,0x20,0x10,0x28,0x43,0x0C,0x10,0x20,0x78,0x00,
}
/************************************************************
延迟函数
函数原型:void delay(uint z)
函数功能:延迟z毫秒
*************************************************************/
void delay(uint z)
{
uint x,y
for(x=zx>0x--)
for(y=110y>0y--)
}
/*--------------------------------------------
LCD_write_byte: 使用SPI接口写数据到LCD
输入参数:dt:写入的数据;
command :写数据/命令选择;
编写日期:20080918
----------------------------------------------*/
void LCD_write_byte(unsigned char dt, unsigned char command)
{
unsigned char i
sce=0
dc=command
for(i=0i<8i++)
{
if(dt&0x80)
sdin=1
else
sdin=0
dt=dt<<1
sclk=0
sclk=1
}
dc=1
sce=1
sdin=1
}
/*---------------------------------------
LCD_init: 3310LCD初始化
编写日期:20080918
----------------------------------------- */
void LCD_init(void)
{
res=0
delay(1)
res=1
LCD_write_byte(0x21,0)//初始化Lcd,功能设定使用扩充指令
LCD_write_byte(0xd0,0)//设定液晶偏置电压
LCD_write_byte(0x20,0)//使用基本指令
LCD_write_byte(0x0C,0)//设定显示模式,正常显示
}
/*-------------------------------------------
LCD_set_XY: 设置LCD坐标函数
输入参数:X:0-83 Y:0-5
编写日期:20080918
---------------------------------------------*/
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_byte(0x40 | Y, 0)// column
LCD_write_byte(0x80 | X, 0)// row
}
/*------------------------------------------
LCD_clear: LCD清屏函数
编写日期:20080918
--------------------------------------------*/
void LCD_clear(void)
{
unsigned char t
unsigned char k
LCD_set_XY(0,0)
for(t=0t<6t++)
{
for(k=0k<84k++)
{
LCD_write_byte(0x00,1)
}
}
}
/*---------------------------------------------
LCD_write_shu: 显示8(宽)*16(高)点阵列数字字母符号等半角类
输入参数:c:显示的字符;
编写日期:20080918
-----------------------------------------------*/
void LCD_write_shu(unsigned char row, unsigned char page,unsigned char c) //row:列 page:页 dd:字符
{
unsigned char i
LCD_set_XY(row*8, page)// 列,页
for(i=0i<8i++)
{
LCD_write_byte(shuzi[c*16+i],1)
}
LCD_set_XY(row*8, page+1)// 列,页
for(i=8i<16i++)
{
LCD_write_byte(shuzi[c*16+i],1)
}
}
/*---------------------------------------------
LCD_write_hanzi: 显示16(宽)*16(高)点阵列汉字等半角类
输入参数:c:显示的字符;
编写日期:20080918
-----------------------------------------------*/
void LCD_write_hanzi(unsigned char row, unsigned char page,unsigned char c) //row:列 page:页 dd:字符
{
unsigned char i
LCD_set_XY(row*8, page)// 列,页
for(i=0i<16i++)
{
LCD_write_byte(hanzi[c*32+i],1)
}
LCD_set_XY(row*8, page+1)// 列,页
for(i=16i<32i++)
{
LCD_write_byte(hanzi[c*32+i],1)
}
}
/*---------------------------------------------
void display(): 显示函数
输入参数:无;
编写日期:2009,10
-----------------------------------------------*/
void display()
{
if(rebuf[10]==0xaa)
{
LCD_write_shu(1,0,rebuf[1]) //ID1
LCD_write_shu(2,0,rebuf[2]) //ID2
LCD_write_shu(3,0,rebuf[3]) //ID3
LCD_write_shu(0,2,rebuf[4]) //tem1
LCD_write_shu(1,2,rebuf[5]) //tem2
LCD_write_shu(2,2,10) //.
LCD_write_shu(3,2,rebuf[6]) //tem3
LCD_write_shu(4,2,12) //℃
LCD_write_hanzi(0,4,0) //光
LCD_write_shu(2,4,11) //:
LCD_write_hanzi(3,4,(rebuf[8]+1)) //
if((rebuf[4]>=(tembuf[0]/10))&&(rebuf[5]>=(tembuf[0]%10)))
f_alarm = 1
else
f_alarm = 0
if((rebuf[4]<=(tembuf[1]/10))&&(rebuf[5]<=(tembuf[1]%10)))
f_alarm = 1
else
f_alarm = 0
}
if(rebuf[10]==0xbb)
{
LCD_write_shu(6,0,rebuf[1]) //ID1
LCD_write_shu(7,0,rebuf[2]) //ID2
LCD_write_shu(8,0,rebuf[3]) //ID3
LCD_write_shu(5,2,rebuf[4]) //tem1
LCD_write_shu(6,2,rebuf[5]) //tem2
LCD_write_shu(7,2,10) //.
LCD_write_shu(8,2,rebuf[6]) //tem3
LCD_write_shu(9,2,12) //℃
LCD_write_hanzi(5,4,0) //光
LCD_write_shu(7,4,11) //:
LCD_write_hanzi(8,4,(rebuf[8]+1)) //
if((rebuf[4]>=(tembuf[0]/10))&&(rebuf[5]>=(tembuf[0]%10)))
m_alarm = 1
else
m_alarm = 0
if((rebuf[4]<=(tembuf[1]/10))&&(rebuf[5]<=(tembuf[1]%10)))
m_alarm = 1
else
m_alarm = 0
}
}
配套 2.4寸LCD屏 ST7789驱动器芯片(24P 320X240)ST7789驱动器芯片2.4寸LCD屏(24P 320X240)
主要参数
1. 模块名称:液晶显示模块
2. 型号:KD024C-4
3. 同类型型号:
4. 兼容型号:
5. 显茄伏搏示模式:TFT
6. 显示色彩:65/262K
7. 分辨率: 240*320
8. 点距:0.153 (H) x 0.153 (V)
9. 视角:12:00
10. 控制IC:ST7789V
11. 显示类型:全透型,常白
12. 外形尺寸:42.72*60.26*2.6mm
13. 可视面积:38.32*50.56 mm
14. 点阵区面积:36.72*48.96mm
15. 亮度:300cd/m2
16. 对比度:500
17. 接口类型: 8/9/16/18位8080并口
16/18位RGB接口
3/4线SPI接口
18. 引脚数:24
19. 引脚距离:0.5mm
20. 连接类型: FPC插接型
21. 工作电压:3.3V
22. 背光灯颜色及类型: 白色LED背光
23. 背光电路:4 LED 并联, 共阳
If=80mA, Vf =3.2V
24. 使用寿命:100000h
25. 工作温度:-20----70°C
26. 储存温度:-30----80°C
27. 质量体系认证:ISO9001:2008
28. 产品认证:RoHS
#MicroPython动手做(05)——零基础学MaixPy之LCD液晶屏
#测试程序之一:显示英文
#MicroPython动手做(05)——零基础学MaixPy之LCD液晶屏
#测试程序之一:显示英文
import lcd
lcd.init()
lcd.draw_string(100, 100, "hello MicroPython!", lcd.RED, lcd.BLACK)
lcd 屏幕显示驱动
lcd.display(image, roi=Auto)
在液晶屏上显示一张 image(GRAYSCALE或RGB565)。
roi 是一个感兴趣区域的矩形元组(x, y, w, h)。若未指定,即为图像颤祥矩形
若 roi 宽度小于lcd宽度,则用厅帆垂直的黑色边框使 roi 居于屏幕中心(即用黑色填充未占用区域)。
若 roi 宽度大于lcd宽度,则 roi 居于屏幕中心,且不匹配像素不会显示(即液晶屏以窗口形态显示 roi 的中心)。
若 roi 高度小于lcd高度,则用垂直的黑色边框使 roi 居于屏幕中心(即用黑色填充未占用区域)。
若 roi 高度大于lcd高度,则 roi 居于屏幕中心,且不匹配像素不会显示(即液晶屏以窗口形态显示 roi 的中心)。
roi 是键值参数,必须在函数调用中通过写入 roi= 来显式地调用。
#MicroPython动手做(05)——零基础学MaixPy之LCD液晶屏
#测试程序之二:LCD屏显示"hello maixpy"
import lcd, time
import image
bg = (236,36,36)
lcd.init(freq=15000000)
lcd.direction(lcd.YX_RLDU)
lcd.clear(lcd.RED)
time.sleep(1)
lcd.draw_string(120, 120, "hello maixpy", lcd.WHITE, lcd.RED)
time.sleep(2)
img = image.Image()
img.draw_string(60, 100, "hello maixpy", scale=2)
img.draw_rectangle((120,120,30,30))
lcd.display(img)
lcd 屏幕显示驱动函数
1. lcd.init(type=1, freq=15000000, color=lcd.BLACK)
初始化 LCD 屏幕显示
参数
type: LCD 的类型(保留给未来使用):
0: None
1: lcd shield(默认值)
type 是键值参数,必须在函数调用中通过写入 type= 来显式地调用
freq: LCD (实际上指 SPI 的通讯速率) 的频率
color: LCD 初始化的颜色, 可以是 16 位的 RGB565 颜色值,比如 0xFFFF; 或者 RGB888 元组, 比如 (236, 36, 36), 默认 lcd.BLACK
2. lcd.clear()
将液晶屏清空为黑色或者指定的颜色。
参数
color: LCD 初始化的颜色, 可以是 16 位的 RGB565 颜色值,比如 0xFFFF; 或者 RGB888 元组, 比如 (236, 36, 36)
3. lcd.freq(freq)
设置或者获取 LCD (SPI) 的频率
Paremeters
freq: LCD (SPI) 的频率
Return
LCD 的频率
4. lcd.direction(dir)
在 v0.3.1 之后已经被舍弃, 请使用lcd.rotation 和 lcd.invert代替, 如非必要请勿使用, 接口仍会被保留用于调试使用
设置屏幕方向, 以及是否镜像等
参数
dir: 正常情况下推荐 lcd.YX_LRUD 和 lcd.YX_RLDU, 另外还有其它值,交换 XY 或者 LR 或者 DU即可
#MicroPython动手做(05)——零基础学MaixPy之LCD液晶屏
#实验程序之三:LCD液晶显示器彩条测试
import lcd,image, time
lcd.init(type=1, freq=15000000)
# lcd.init(type=2, freq=20000000)
# lcd.init(type=1, width=320, height=240, invert=True, freq=20000000)
img = image.Image(size=(240,240))
img.draw_rectangle(0,0,30, 240, fill=True, color=(0xff, 0xff, 0xff))
img.draw_rectangle(30,0,30, 240, fill=True, color=(250, 232, 25))
img.draw_rectangle(60,0,30, 240, fill=True, color=(106, 198, 218))
img.draw_rectangle(90,0,30, 240, fill=True, color=(98, 177, 31))
img.draw_rectangle(120,0,30, 240, fill=True, color=(180, 82, 155))
img.draw_rectangle(150,0,30, 240, fill=True, color=(231, 47, 29))
img.draw_rectangle(180,0,30, 240, fill=True, color=(32, 77, 158))
img.draw_rectangle(210,0,30, 240, fill=True, color=(27, 28, 32))
lcd.display(img)
count = 500
while count >0:
t = time.ticks_ms()
lcd.display(img)
print(time.ticks_ms() - t)
count -= 1
#MicroPython动手做(05)——零基础学MaixPy之LCD液晶屏
#实验程序之四:测试Microphone阵列算法
fromMaiximportMIC_ARRAYasmic
importlcd
lcd.init()
mic.init()
whileTrue:
imga = mic.get_map()
b = mic.get_dir(imga)
a = mic.set_led(b,(0,0,255))
imgb = imga.resize(160,160)
imgc = imgb.to_rainbow(1)
a = lcd.display(imgc)
mic.deinit()
#MicroPython动手做(05)——零基础学MaixPy之LCD液晶屏
#实验程序之五:图形与hello maixpy
import lcd, time
import image
bg = (236,36,36)
lcd.init(freq=15000000)
lcd.direction(lcd.YX_RLDU)
img = image.Image()
img.draw_string(60, 100, "hello maixpy", scale=2)
img.draw_rectangle((120,120,30,30))
img.draw_circle((150,140, 80))
img.draw_cross((250,40))
img.draw_arrow((250,200,20,200), color=(236,36,36))
lcd.display(img)
#MicroPython动手做(05)——零基础学MaixPy之LCD液晶屏
#实验程序之六:碰碰球演示
import image, lcd
lcd.init(freq=20000000)
i = 0
dir = 1
while(True):
img = image.Image(copy_to_fb=1)
img.clear()
img.draw_rectangle(i,50,50,50)
lcd.display(img)
if dir:
i += 5
if i==270:
dir = 0
else:
i -= 5
if i==0:
dir = 1
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)