屏幕和编码器OK

This commit is contained in:
2025-03-23 20:45:23 +08:00
parent 9d910c6770
commit 3f4efa0554
88 changed files with 4812 additions and 13918 deletions
+316
View File
@@ -0,0 +1,316 @@
//***************************************************************************
//连线表: CPU=89C52 *
//RS=P3.0 RW=P3.1 E=P3.2 *
//FOSC=12MHz D0-D7=P1.0-P1.7 *
//***************************************************************************
#include "drv_st7920.h"
enum {
LCD_CMD = 0x00,
LCD_DAT = 0x01
};
#define LCD_CLEAR 0x01
#define LCD_HOME 0x02
#define LCD_CLR 0x01
#define LCD_CLR 0x01
#define LCD_CLR 0x01
#define LCD_CLR 0x01
#define LCD_CLR 0x01
#define LCD_CLR 0x01
/***************************************************************************************
* 2020.11.20
* LED12864模块
* 管脚号 管脚名称 LEVER 管脚功能描述
* 1 VSS 0 电源地
* 2 VDD +5.0V 电源电压
* 3 V0 - 液晶显示器驱动电压
* 4 D/I(RS) H/L D/I=“H” 表示DB7∽DB0为显示数据
* D/I=“L” 表示DB7∽DB0为显示指令数据
* 5 R/W(SID) H/L R/W=“H”,E=“H”数据被读到DB7∽DB0
* R/W=“L”,E=“H→L”数据被写到IR或DR
* 6 E(CLK) H/L R/W=“L”,E信号下降沿锁存DB7∽DB0
* R/W=“H”,E=“H”DDRAM数据读到DB7∽DB0
* 7 DB0 H/L 数据线
* 8 DB1 H/L 数据线
* 9 DB2 H/L 数据线
* 10 DB3 H/L 数据线
* 11 DB4 H/L 数据线
* 12 DB5 H/L 数据线
* 13 DB6 H/L 数据线
* 14 DB7 H/L 数据线
* 15 PSB(CS1) H/L 并/串行接口选择:H-并行 L-串行
* 16 NC(CS2) 空脚
* 17 RST H/L 复位信号,低电平复位
* 18 VOUT -10V LCD驱动负电压
* 19 LED+ + LED背光板电源
* 20 LED- - LED背光板电源
*********************************************************************************************/
/*****************************
屏幕与DDRAM地址的对应关系
第一字 第二字 ......... 第七字 第八字
第一行 80H 81H ......... 82H 87H
第二行 90H 91H ......... 92H 97H
第三行 88H 89H ......... 8EH 8FH
第四行 98H 99H ......... 9EH 9FH
第n行
*******************************/
unsigned char GDRAM[] = { //横向取模,无字节倒序 16 * 64
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,
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,
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,
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,
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,
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,0x80,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,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,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,0xC0,0x30,0x10,0x18,0x08,0x08,0x08,0x08,
0x18,0x10,0x30,0x60,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x01,0x00,0x00,0x80,0x80,
0x40,0x20,0x00,0x20,0x10,0x10,0x10,0x10,0x08,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,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x01,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x02,0x01,0x00,0x00,0x00,
0x80,0x80,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,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0E,0x70,0xC0,0x80,0x80,0x80,0x80,0xC0,
0x40,0x40,0x20,0x20,0x10,0x0C,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x07,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0x06,0x08,0x10,0x20,0x40,0x80,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,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,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,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,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,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,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,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,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,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,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,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,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,0x00,0x00,0x00,0x00,
};
void init_lcd (void);
void cn_disp(unsigned char *cn);
void txt_disp(unsigned char *cn,unsigned char adr);
void gra_disp(unsigned char *img);
void lat_disp(unsigned char data1,unsigned char data2);
void con_disp(unsigned char data1,unsigned char x0,unsigned char y0,unsigned char xl,unsigned char yl);
void lcd_txt_clr(void);
void lcd_gra_clr(void);
void LCD_CheckBusy(void)
{
//可能是模块有问题,这个函数没办法检测繁忙
GPIO_InitTypeDef GPIO_InitStruct = {0};
//修改为输入
GPIO_InitStruct.Pin = LCD_DB0_Pin|LCD_DB1_Pin|LCD_DB2_Pin|LCD_DB3_Pin
|LCD_DB4_Pin|LCD_DB5_Pin|LCD_DB6_Pin|LCD_DB7_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_PinState status;
RS(0);
RW(1); //读出数据,RW=1
HAL_Delay(1);
GPIOA->BSRR = 0x00ff;
GPIOA->BRR = 0x0000;
EN(0);
EN(1);
do
{
status = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_7);//接收BF位,判断是否忙
}while(status);
EN(0);
//修改为输出
GPIO_InitStruct.Pin = LCD_DB0_Pin|LCD_DB1_Pin|LCD_DB2_Pin|LCD_DB3_Pin
|LCD_DB4_Pin|LCD_DB5_Pin|LCD_DB6_Pin|LCD_DB7_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
void LCD_Write(unsigned char type,unsigned char data)
{
LCD_CheckBusy();
RS(type);
RW(0); //write
EN(1);
//HAL_Delay(1);//延迟是必须的
//整个端口赋值
GPIOA->BSRR = data & 0x00ff;
GPIOA->BRR = ~data & 0x00ff;
EN(0);
}
void LCD_Read(unsigned char type,unsigned char data)
{
}
void LCD_init (void)
{
PS(0x01);//选择并口模式
LCD_Write(LCD_CMD,0x30); /*30---功能设定,8-bit模式*/
LCD_Write(LCD_CMD,0x30); /*30---功能设定,基本指令*/
LCD_Write(LCD_CMD,0x08); /*设置显示、光标、闪烁全关*/
LCD_Write(LCD_CMD,0x01); /*清屏,地址指针指向00H*/
LCD_Write(LCD_CMD,0x06); /*光标的移动方向*/
LCD_Write(LCD_CMD,0x0c); /*开显示,关游标*/
}
void LCD_flush(void)
{
//LCD全局刷新,每秒刷新20次。
static int count = 0;
count ++;
if(count % 50)
{
}
}
void LCD_Clear(void)
{
LCD_Write(LCD_CMD,0x01); //写清屏指令0x01
}
void LCD_DDRAM(unsigned char x,unsigned char y,unsigned char *s)
{
switch(y)
{
case 0:
LCD_Write(LCD_CMD,0x80+x); //第一行
break;
case 1:
LCD_Write(LCD_CMD,0x90+x); //第二行
break;
case 2:
LCD_Write(LCD_CMD,0x88+x); //第三行
break;
case 3:
LCD_Write(LCD_CMD,0x98+x); //第四行
break;
}
while(*s>0)
{
LCD_Write(LCD_DAT,*s++);
}
}
/*************** 绘制的API *******************/
void LCD_DrawText(unsigned char *str,unsigned char adr)
{
unsigned char i,j;
LCD_Write(LCD_CMD,0x30);
LCD_Write(LCD_CMD,adr); //第一到四行地址分别是0x80,0x90,0x88,0x98
j=0;
for(i=0;i<16;i++)
LCD_Write(LCD_DAT,str[j*16+i]);
}
void LCD_DrawPix(unsigned char *str,unsigned char adr)
{
}
void LCD_DEMO(void)
{
unsigned char str[50];
LCD_init();
while(1)
{
HAL_Delay(50);
LCD_Clear();
sprintf(str, "编码器数值: %d ", ec11_count);
LCD_DrawText(str,0x80);
}
}