逻辑图
左边三段数字是温度显示 右边两位是湿度 下面是完整的程序 (io口模拟spi发送数据写给ram)个人理解 水平有限 头文件 lcd.h
#ifndef __LCD__H__
#define __LCD__H__
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define NOP _nop_();_nop_();_nop_();_nop_();_nop_();_nop_()
sbit DATA=P1^0;
sbit W_R=P1^1;
sbit CS=P1^3;
/*************************/
uchar num_data[];
//char flag;
char cache[];
void initial();
void Write_Bits(uchar buffer,uchar i);
void tran_data(uchar *p);
void wave();
void delay(uchar);
void witre_clear();
void write_data_by_8bit(uchar num,uchar ad);
void Write_Temperature(uint t,uchar p1,uchar t46);//温度显示
void Write_Humidity(uint h ,uchar t3);//湿度显示
void Write_Mode(uchar a,uchar m);//AUTO//Manual 模式
void Write_Wifi(uchar h);//wifi显示
void Write_Water(uchar w);//缺水显示
void Write_Level(uchar s7,uchar s14,uchar s21); //风力档位
void Show_cache();//将显存写入HT1621的ram
#endif
源文件
#include
#include
#include"lcd.h"
uchar num_data[]={0xf5,0x05,0xb6,0x97,0x47,0xd3,0xf3,0x85,0xf7,0xd7};//0到9的字库
char cache[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};///显存数组
char flag=1 ;
void initial()
{
CS=0;
DATA=1; wave(); //command mode命令模式 配置HT1621
DATA=0; wave();
DATA=0; wave();
Write_Bits(0x18, 8);//RC 256K
Write_Bits(0x00, 8);
Write_Bits(0x01, 8);//turn on system oscilator
Write_Bits(0x03, 8);//turn on bias generator
Write_Bits(0x29, 8);//1/3 bias 4 commons// 1/2 bias 3 commons//0x04
// tran_inst(0xe0); //turn on lcd output
CS=1;
}
void write_data_by_8bit(uchar p,uchar ad)
{
unsigned char i,address=((ad*2)<<2);///对应ram地址 两个4位一写
CS=0;
DATA=1;wave();//数据模式
DATA=0;wave();
DATA=1;wave();
for(i=0;i<6;i++)////6位地址
{
DATA=((address&0x80)==0x80);
wave();
address<<=1;
}
Write_Bits(p,8);
//delay(4);
CS= 1;
}
void Write_Bits(uchar buffer,uchar j) //按j位写数据
{
uchar i;
for(i=0;i cache[2]=cache[2]|(1<<3);
cache[3]=cache[3]&~(1<<3);
cache[0]=cache[0]|(1<<3);
}
else
{
flag=0;
cache[2]=cache[2]&~(1<<3);
cache[3]=cache[3]&~(1<<3);
cache[0]=cache[0]&~(1<<3);
}
}
void Write_Humidity(uint h,uchar t3)//写两位湿度 T3 %
{
unsigned char a0,a1;
a1=(h/10)%10;///////
a0=h%10;////////////
if(flag)
cache[3]=num_data[a1]|(1<<3);
else
cache[3]=num_data[a1]&~(1<<3);
cache[4]=num_data[a0];
if(t3==1)
cache[4]=cache[4]|(1<<3);
else
cache[4]=cache[4]&~(1<<3);
}
void Write_Mode(uchar a,uchar m)//
if(a==1)
cache[5]=cache[5]|(1<<6);
else
cache[5]=cache[5]&~(1<<6);
if(m==1)
cache[5]=cache[5]|(1<<7);
else
cache[5]=cache[5]&~(1<<7);
}
void Write_Wifi(uchar h);//
void Write_Water(uchar w)//
{
if(w==1)
cache[7]=cache[7]|(1<<3);
else
cache[7]=cache[7]&~(1<<3);
}
void Write_Level(uchar s7,uchar s14,uchar s21)//S7/S14/S21 第几个叶子代表档位 1单叶 2双叶 0:灭 单页和双叶循环转动
{
if(s7==1){
cache[7]=cache[7]|(1<<1);
cache[7]=cache[7]|(1<<2);
cache[7]=cache[7]|(1<<4);
cache[7]=cache[7]|(1<<6);
cache[7]=cache[7]&~(1<<0);
cache[7]=cache[7]&~(1<<5);
cache[7]=cache[7]&~(1<<7);
}
else if(s7==2){
cache[7]=cache[7]|(1<<1);
cache[7]=cache[7]|(1<<0);
cache[7]=cache[7]|(1<<5);
cache[7]=cache[7]|(1<<7);
cache[7]=cache[7]&~(1<<2);
cache[7]=cache[7]&~(1<<4);
cache[7]=cache[7]&~(1<<6);
}
else{
cache[7]=cache[7]&~(1<<1);
cache[7]=cache[7]&~(1<<2);
cache[7]=cache[7]&~(1<<0);
cache[7]=cache[7]&~(1<<4);
cache[7]=cache[7]&~(1<<5);
cache[7]=cache[7]&~(1<<6);
cache[7]=cache[7]&~(1<<7);
}
//////////////////////////////
if(s14==1){
cache[6]=cache[6]|(1<<1);
cache[6]=cache[6]|(1<<2);
cache[6]=cache[6]|(1<<4);
cache[6]=cache[6]|(1<<6);
cache[6]=cache[6]&~(1<<0);
cache[6]=cache[6]&~(1<<5);
cache[6]=cache[6]&~(1<<3);
}
else if(s14==2){
cache[6]=cache[6]|(1<<1);
cache[6]=cache[6]|(1<<0);
cache[6]=cache[6]|(1<<5);
cache[6]=cache[6]|(1<<3);
cache[6]=cache[6]&~(1<<2);
cache[6]=cache[6]&~(1<<4);
cache[6]=cache[6]&~(1<<6);
}
else{
cache[6]=cache[6]&~(1<<1);
cache[6]=cache[6]&~(1<<2);
cache[6]=cache[6]&~(1<<0);
cache[6]=cache[6]&~(1<<4);
cache[6]=cache[6]&~(1<<5);
cache[6]=cache[6]&~(1<<6);
cache[6]=cache[6]&~(1<<3);
}
/////////////////////////////////////
if(s21==1){
cache[5]=cache[5]|(1<<2);
cache[5]=cache[5]|(1<<4);
cache[5]=cache[5]|(1<<1);
cache[6]=cache[6]|(1<<7);//
cache[5]=cache[5]&~(1<<0);
cache[5]=cache[5]&~(1<<5);
cache[5]=cache[5]&~(1<<3);
}
else if(s21==2){
cache[5]=cache[5]|(1<<2);
cache[5]=cache[5]&~(1<<4);
cache[5]=cache[5]&~(1<<1);
cache[6]=cache[6]&~(1<<7);//
cache[5]=cache[5]|(1<<0);
cache[5]=cache[5]|(1<<5);
cache[5]=cache[5]|(1<<3);
}
else{
cache[5]=cache[5]&~(1<<2);
cache[5]=cache[5]&~(1<<4);
cache[5]=cache[5]&~(1<<1);
cache[6]=cache[6]&~(1<<7);//
cache[5]=cache[5]&~(1<<0);
cache[5]=cache[5]&~(1<<5);
cache[5]=cache[5]&~(1<<3);
}
}
void Show_cache()
{
unsigned int j;
for(j=0;j<8;j++)
{
write_data_by_8bit(cache[j], j);
}
}
main.c#include
#include
#include"lcd.h"
void main()
{
unsigned long h=0,i=0;
CS=1;
W_R=0;
initial();//³õʼ»¯ ÉèÖÃlcd
witre_clear();
while(1)
{
i++;h++;
Write_Temperature(i,1,1);//
Write_Humidity(h,1);//***********//
Write_Mode(0,0);
Write_Water(1);
Write_Level(1,1,1);
if(i>=1000) i=0;
if(h>=100) h=0;
Show_cache();
delay(10);//500ms
Write_Temperature(i,1,2);
Write_Humidity(h,0);
Write_Mode(1,1);
Write_Water(0);
Write_Level(2,2,2);
Show_cache();
delay(10);
}
}