lcd.c

来自「RT12864M汉字图形点阵液晶显示模块」· C语言 代码 · 共 108 行

C
108
字号
#include "reg52.h"
#include "intrins.h"
#include "ds18b20.h"

void write_op(unsigned char instruction);
void write_dat(unsigned char indata);
void check_busy();
void lcd_ini();


sbit RS=P2^0;
sbit RW=P2^1;
sbit E=P2^2;
sbit PSB=P2^3;
sbit RST=P2^5;

unsigned char  dis_char[]={ "当前室温是  度"};

unsigned char code line[]={0x80,0x90,0x88,0x98};

void delayms(unsigned char n)
{
 while(n--);
}


void write_op(unsigned char instruction)
{
check_busy();
RS=0;
RW=0;
P0=instruction;
E=1;
_nop_();
E=0;
}

void write_dat(unsigned char indata)
{
check_busy();
RS=1;
RW=0;
P0=indata;
E=1;
_nop_();
E=0;
}

void check_busy()
{
RS=0;
RW=1;
E=1;
_nop_();
while((bit)P0 & 0x80);
E=0;
}

void lcd_ini()
{
RST=0;
    delayms(60);
    RST=1;
    _nop_();
    PSB=1;
    
    write_op(0x30);
    write_op(0x01);
    write_op(0x06);
    write_op(0x0c);
}

 void main()
{
unsigned char j;
unsigned char temp;
unsigned char  tab[10]={'0','1','2','3','4','5','6','7','8','9'};
unsigned char  tab1[10]={0,1,2,3,4,5,6,7,8,9};
lcd_ini();

while(1)
{
temp=ReadTemperature();

write_op(line[0]);
for(j=0;j<10;j++) 
write_dat(dis_char[j]);

for(j=0;j<10;j++)
if(temp/10==tab1[j])
  {
   write_dat(tab[j]);
 }

for(j=0;j<10;j++)
if(temp%10==tab1[j])
  {
   write_dat(tab[j]);
 }

for(j=12;j<14;j++) 
write_dat(dis_char[j]);

}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?