📄 lcd16.c
字号:
#include"pic.h"
#include"i2c.c"
__CONFIG(HS&WDTDIS&PWRTDIS&BORDIS);
#define rs RA3 //液晶引脚定义
#define rw RA2 //同上
#define lcden RA1//同上
#define uchar unsigned char
unsigned char table[]="0123456789"; //液晶列表
unsigned char table1[]="the temperature"; //同上
bank1 unsigned char table2[]="start work time"; //同上
bank1 unsigned char table3[]=" wait to work "; //同上
bank1 unsigned char table4[]=" on work "; //同上
bank2 unsigned char table5[]=" last set "; //同上
void init(void)//io口初始化
{
TRISD=0;
TRISB=0XF9;
CMCON=0X07;
ADCON1=0X07;
TRISA=0;
rw=0;
}
void delay() //液晶延时
{
unsigned int a,b;
for(a=10;a>0;a--)
for(b=10;b>0;b--);
}
void delay1(int x) //液晶延时
{
unsigned int a1,b1;
for(a1=x;a1>0;a1--)
for(b1=10;b1>0;b1--);
}
/////////////液晶/////////////
void write_com(char com) //液晶写指令(串行)
{
char port;
port=com;
port=port&0xf0;
port>>=4;
// PORTD=com|0x0f;
PORTD&=0Xf0;
PORTD=port|PORTD;
rs=0;
lcden=0;
delay();
lcden=1;
delay();
lcden=0;
com<<=4;
// PORTD=com|0x0f;
port=com;
port=port&0xf0;
port>>=4;
// PORTD=com|0x0f;
PORTD&=0Xf0;
PORTD=port|PORTD;
lcden=0;
delay();
lcden=1;
delay();
lcden=0;
}
void write_date(char date) //液晶写数据(串行)
{
char port;
// PORTD=date|0x0f;
port=date;
port=port&0xf0;
port>>=4;
// PORTD=com|0x0f;
PORTD&=0Xf0;
PORTD=port|PORTD;
rs=1;
lcden=0;
delay1(10);
lcden=1;
delay1(10);
lcden=0;
date<<=4;
// PORTD=date|0x0f;
port=date;
port=port&0xf0;
port>>=4;
// PORTD=com|0x0f;
PORTD&=0Xf0;
PORTD=port|PORTD;
lcden=0;
delay1(10);
lcden=1;
delay1(10);
lcden=0;
}
void initsreen() //液晶初始化
{
write_com(0x28);
delay1(10);
write_com(0x0c);
delay1(10);
write_com(0x06);
delay1(10);
write_com(0x01);
delay1(10);
}
void display_char(uchar n1) //display hour(n=0) and minute(n=3)
{
uchar i=0;
write_com(0x80);
for(i=0;i<15;i++)
{
if(n1==1)
write_date(table1[i]);
else if(n1==2)
write_date(table2[i]);
else if(n1==3)
write_date(table3[i]);
else if(n1==4)
write_date(table4[i]);
else
write_date(table5[i]); ;
}
}
void display_time(unsigned int y1,uchar n) //display hour(n=0) and minute(n=3)
{
unsigned int temp,temp1;
temp=y1;
temp1=(temp/10)%10;
write_com(0xC5+n);
write_date(table[temp1]);
temp1=temp%10;
write_date(table[temp1]);
}
void main(void)
{
unsigned int m;
init();
i2cint();
initsreen();
display_char(1);
while(1){
code=0x01;//figure word
tem_read();
while(jdate&0x40==0)//whether ready for reading
{
code=0x01;
tem_read();
}
code=0x00;//temperature word
tem_read();
display_time(jdate,1);//temperature display
delay();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -