内容发布更新时间 : 2025/1/5 18:33:31星期一 下面是文章的全部内容请认真阅读。
数码管段代码: 共阳:
0xc0,0xf9,0xa4,0xb0, 0x99,0x92,0x82,0xf8, 0x80,0x90,0x88,0x83, 0xc6,0xa1,0x86,0x8e
共阴:
0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71
12864液晶:
/*------------------------------------------------ 检测忙位
------------------------------------------------*/ void Check_Busy() {
RS=0; RW=1; E=1;
DataPort=0xff;
while((DataPort&0x80)==0x80);//忙则等待 E=0; }
/*------------------------------------------------ 写命令
------------------------------------------------*/ void Write_Cmd(unsigned char Cmd) { Check_Busy(); RS=0; RW=0; E=1; DataPort=Cmd; DelayUs2x(5); E=0; DelayUs2x(5); }
/*------------------------------------------------
写数据
------------------------------------------------*/ void Write_Data(unsigned char Data) { Check_Busy(); RS=1; RW=0; E=1; DataPort=Data; DelayUs2x(5); E=0; DelayUs2x(5); }
/*------------------------------------------------ 液晶屏初始化 ------------------------------------------------*/ void Init_ST7920() {
DelayMs(40); //大于40MS的延时程序
PSB=1; //设置为8BIT并口工作模式 DelayMs(1); //延时 RES=0; //复位 DelayMs(1); //延时
RES=1; //复位置高 DelayMs(10);
Write_Cmd(0x30); //选择基本指令集 DelayUs2x(50); //延时大于100us Write_Cmd(0x30); //选择8bit数据流 DelayUs2x(20); //延时大于37us
Write_Cmd(0x0c); //开显示(无游标、不反白) DelayUs2x(50); //延时大于100us
Write_Cmd(0x01); //清除显示,并且设定地址指针为00H DelayMs(15); //延时大于10ms
Write_Cmd(0x06); //指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位,光标从右向左加1位移动
DelayUs2x(50); //延时大于100us }
/*------------------------------------------------ 用户自定义字符 ------------------------------------------------*/ void CGRAM() {
int i;
Write_Cmd(0x30);
Write_Cmd(0x40); for(i=0;i<16;i++) { Write_Data(user16x16[i*2]); Write_Data(user16x16[i*2+1]); } }
/*------------------------------------------------ 显示用户自定义字符 ------------------------------------------------*/
void DisplayCGRAM(unsigned char x,unsigned char y) {
switch(y) { case 1: Write_Cmd(0x80+x);break; case 2: Write_Cmd(0x90+x);break; case 3: Write_Cmd(0x88+x);break; case 4: Write_Cmd(0x98+x);break; default:break; }
Write_Data(00); Write_Data(00);
}
/*------------------------------------------------ 显示字符串 x:横坐标值,范围0~8 y:纵坐标值,范围1~4
------------------------------------------------*/
void LCD_PutString(unsigned char x,unsigned char y,unsigned char code *s) {
switch(y) { case 1: Write_Cmd(0x80+x);break; case 2: Write_Cmd(0x90+x);break; case 3: Write_Cmd(0x88+x);break; case 4: Write_Cmd(0x98+x);break; default:break; }
while(*s>0) {
Write_Data(*s); s++;
DelayUs2x(50);