⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wdcgq+lcd.c

📁 传感器+128*64LCD,用C语言编写,呵呵,自己写的,水平可能不是太高,但能正确使用,用KEIL C验证通过,供入门者参考,
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <reg52.h>
#include <intrins.h>
sbit 	lcd_e = P2^0;
sbit 	lcd_cs1 = P2^5;
sbit 	lcd_cs2 = P2^4;
sbit 	lcd_di = P2^2;
sbit	lcd_rw = P2^1;
sbit 	lcd_reset = P2^3;
sbit 	lcd_led=P2^6;
sbit 	DQ = P1^1;
sbit 	fan = P3^4;
sbit	key_set= P1^2;
sbit	key_up=  P1^4;
sbit	key_down = P1^3;
sbit 	relay = P3^5;
#define lcd_off_dir 0x3e
#define lcd_on_dir 0x3f 
#define uint unsigned int
#define uchar unsigned char
#define x_1 0xb8
#define x_2 0xb8+2
#define x_3 0xb8+4
#define x_4 0xb8+6
#define y_1 0x40
#define y_2 0x40+8
#define y_3 0x40+16
#define y_4 0x40+24
#define y_5 0x40+32
#define y_6 0x40+40
#define y_7 0x40+48
#define y_8 0x40+56
#define lra_l 1
#define lra_r 2
#define lra_a 3
#define EN    8
#define CH   16

uchar *word_number;
int fact_temprature;
int	set_temprature;
uint up_time,keep_time;
uchar key_select = 0;
uchar comm_out[3]={'4','5','\n'};

void delayms(uint ms) ;
void delay(void);
void delay_18b20(uint s);
uchar rest_18b20(void);
char read_18b20(void);
void write_18b20(char i);
int read_temprature(void);//读传感器温度()
void  lcd_lra(int x);
void decode_word1(int word1);
send_i(uint s);//向LCD发送命令(命令)
send_d(uint s);//向LCD发送数据(数据)
lcd_disp_pic( uchar *pic,int lr);//显示半图(图片名,左右)
lcd_disp_maxpic(uchar *pic);//显示最大图片(图片名)
lcd_disp_word(int n,uchar *word,int x,int y,int lr);//显示文字(中/英,字名,行,列,左右)
lcd_disp_number(int word1,int x,int y,int lr);//显示数字被(数字,行,列,左右)
clrscr(int lr);//清屏(左右全)
void dir_temprature(int word1,uchar x,uchar y,uchar lr);//显示温度(来自传感器或来自设置,选择来自传感器或来自设置,行,列,左右)
void string_DQ05ZKZZ();	//电气05自考制作字符
void string_SJWD(uchar x,lr);//实际温度字符
void string_YSWD(uchar x,lr);//预设温度字符
void string_YSSJ(uchar x,lr);//预设时间字符
void string_SJSJ(uchar x,lr);//实际时间字符
void lcd_inti(void);//初始化
void dir_time(uint word1,uchar x,uchar y,uchar lr);/////显示时间(显示的数,行,列,左右)
unsigned char code	MH[]=
{
/*--  宽度x高度=8x16  --*/////////////////////////////////////////////////冒号
0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x00
};
unsigned char code XSD[]=///////////////////////////////////////////小数点
{
/*--  宽度x高度=8x16  --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x0F,0x0F,0x06,0x00,0x00
};
unsigned char code noop[]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
unsigned char code _0[]=
{
0xC0,0xE0,0x30,0x10,0x30,0xE0,0xC0,0x00,0x07,0x0F,0x18,0x10,0x18,0x0F,0x07,0x00,
};
unsigned char code _1[]=
{
0x00,0x00,0x40,0x60,0xF0,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,
};
unsigned char code _2[]=
{
0x00,0x60,0x70,0x10,0x10,0xF0,0xE0,0x00,0x00,0x18,0x1C,0x16,0x13,0x11,0x10,0x00,
};
unsigned char code _3[]=
{
0x60,0x70,0x10,0x10,0x10,0xF0,0xE0,0x00,0x0C,0x1C,0x10,0x11,0x11,0x1F,0x0E,0x00,
};
unsigned char code _4[]=
{
0x00,0x00,0xC0,0xF0,0xF0,0xF0,0x00,0x00,0x06,0x07,0x05,0x04,0x1F,0x1F,0x04,0x00,
};
unsigned char code _5[]=
{
0xF0,0xF0,0x90,0x90,0x90,0x90,0x10,0x00,0x0D,0x1D,0x10,0x10,0x10,0x1F,0x0F,0x00,
};
unsigned char code _6[]=
{
0xC0,0x60,0xB0,0x90,0x90,0xB0,0x20,0x00,0x07,0x0F,0x19,0x10,0x10,0x1F,0x0F,0x00,
};
unsigned char code _7[]=
{
0x00,0x10,0x10,0x10,0x90,0xF0,0x70,0x00,0x00,0x00,0x00,0x18,0x1F,0x07,0x00,0x00,
};
unsigned char code _8[]=
{
0xE0,0xF0,0x10,0x10,0x10,0xF0,0xE0,0x00,0x0E,0x1F,0x11,0x11,0x11,0x1F,0x0E,0x00,
};
unsigned char code _9[]=
{
0xE0,0xF0,0x10,0x10,0x30,0xE0,0xC0,0x00,0x09,0x1B,0x12,0x12,0x1B,0x0F,0x07,0x00,
};
unsigned char code inv[]=//////////////////////////////////////////////////////////////////////负号
{
/*--  宽度x高度=8x16  --*/
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00
};
unsigned char code ico_shou[]=
{
0xC0,0xE0,0xE0,0x20,0x20,0x10,0x10,0x08,0x28,0x24,0xB4,0xAC,0xA0,0xA0,0xA0,0x40,
0x03,0x07,0x07,0x04,0x04,0x08,0x08,0x10,0x10,0x28,0x2A,0x12,0x0C,0x03,0x00,0x00,
};

unsigned char code GTH[]=	////////////////////////////////////////////////////////////////////  感叹号
{
0x00,0x00,0xFC,0xFC,0xFC,0x00,0x00,0x00,0x00,0x00,0x73,0x73,0x73,0x00,0x00,0x00
};

unsigned char code SSD[]=	////////////////////////////////////////////////////////////////////  摄氏度
{
/*--  宽度x高度=16x16  --*/
0x00,0x0C,0x12,0x12,0x0C,0xC0,0xE0,0x10,0x18,0x18,0x18,0x18,0x18,0x10,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x1F,0x3F,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x40,0x00,0x00
};

unsigned char code dian4[]=
{
/*--  文字:  电  --*/
/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=17x16   --*/
0x00,0x00,0xF0,0xF0,0x90,0x90,0xFF,0xFF,0x48,0x08,0xF8,0xF8,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x03,0x03,0x02,0x1F,0x3F,0x21,0x21,0x21,0x20,0x20,0x3C,0x1C,
0x00,0x00
};

unsigned char code qi4[]=
{
/*--  文字:  气  --*/
/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=17x16   --*/
0x00,0x20,0xB0,0x98,0xAC,0xA6,0xF6,0x54,0x56,0xD2,0xC2,0x02,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x1F,0x30,0x20,0x20,0x3C,
0x3C,0x00
};

unsigned char code zi4[]=
{
/*--  文字:  自  --*/
/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=17x16   --*/
0x00,0x00,0x00,0x00,0xE0,0xF0,0x9C,0x9F,0x93,0x10,0xF0,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x3F,0x3F,0x34,0x14,0x14,0x30,0x7F,0x7F,0x00,0x00,0x00,
0x00,0x00
};

unsigned char code kao3[]=
{
/*--  文字:  考  --*/
/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=17x16   --*/
0x00,0x40,0x40,0x40,0x48,0x48,0xFF,0xFF,0x64,0xB4,0xB8,0xAE,0xA6,0x20,0x20,0x00,
0x00,0x08,0x08,0x0C,0x06,0x02,0x0F,0x0F,0x27,0x65,0x7D,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00
};
unsigned char code zhi4[]=
{
/*--  文字:  制  --*/
/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=17x16   --*/
0x00,0x80,0xA0,0xB8,0x98,0xFE,0xFE,0x48,0x48,0x40,0xF0,0xF0,0xFE,0xFE,0x00,0x00,
0x00,0x00,0x00,0x0E,0x0E,0x02,0x3F,0x3F,0x0F,0x0F,0x00,0x03,0x13,0x3F,0x3F,0x00,
0x00,0x00
};
unsigned char code zuo4[]=
{
/*--  文字:  作  --*/
/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=17x16   --*/
0x80,0xC0,0x60,0xF0,0xFE,0x8E,0xC0,0x70,0x3C,0xFF,0xF3,0x98,0x88,0x88,0x08,0x00,
0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00,0x7F,0x7F,0x04,0x04,0x04,0x00,
0x00,0x00
};

unsigned char 	code yu4[]=
{
/*--  文字:  预  --*/
/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=17x16   --*/
0x40,0x44,0x44,0x54,0xFE,0xEE,0x66,0x64,0xE4,0xF4,0xDC,0xDE,0x12,0xF2,0xF2,0x00,
0x00,0x00,0x00,0x08,0x18,0x1F,0x0F,0x20,0x20,0x37,0x1F,0x0F,0x0F,0x18,0x33,0x33,
0x00,0x00
};

unsigned char 	code she4[]=
{
/*--  文字:  设  --*/
/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=17x16   --*/
0x40,0x60,0xE2,0xE6,0x04,0x40,0x60,0xBC,0x9E,0x82,0xBE,0xBE,0x20,0x20,0x00,0x00,
0x00,0x00,0x00,0x1F,0x1F,0x2C,0x24,0x31,0x1B,0x0E,0x0E,0x1B,0x31,0x30,0x20,0x20,
0x20,0x00
};
unsigned char 	code wen1[]=
{
/*--  文字:  温  --*/
/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=17x16   --*/
0x20,0x60,0x44,0x0C,0x08,0x0C,0x3C,0x74,0x5E,0x6A,0xBA,0xBE,0x8E,0x00,0x00,0x00,
0x00,0x00,0x18,0x1E,0x17,0x11,0x1F,0x1F,0x1F,0x1F,0x0F,0x0F,0x0F,0x0F,0x08,0x08,
0x00,0x00
};
unsigned char 	code du4[]=
{
/*--  文字:  度  --*/
/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=17x16   --*/
0x00,0x00,0x00,0xF8,0xF8,0x28,0xF8,0xF9,0xAF,0xFE,0x7C,0x14,0x14,0x00,0x00,0x00,
0x00,0x20,0x38,0x1E,0x27,0x21,0x22,0x36,0x1E,0x0B,0x1F,0x37,0x30,0x20,0x20,0x20,
0x20,0x00
};
unsigned char 	code shi2[]=
{
/*--  文字:  实  --*/
/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=17x16   --*/
0x00,0x00,0x30,0x38,0x88,0xA8,0x6D,0x47,0xF6,0xF4,0x04,0x0C,0x0C,0x00,0x00,0x00,
0x00,0x00,0x00,0x44,0x44,0x64,0x35,0x1F,0x0E,0x07,0x0B,0x19,0x31,0x31,0x01,0x00,
0x00,0x00

};
unsigned char 	code ji4[]=
{
/*--  文字:  际  --*/
/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=17x16   --*/
0x00,0xFC,0xFC,0x96,0xFA,0xEE,0x46,0x48,0x48,0xEC,0xE4,0x24,0x24,0x20,0x20,0x00,
0x00,0x00,0x1F,0x1F,0x00,0x00,0x04,0x07,0x03,0x10,0x3F,0x3F,0x01,0x03,0x06,0x06,
0x00,0x00

};
unsigned char 	code shii2[]=
{
/*--  文字:  时  --*/
/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=17x16   --*/
0x00,0xF8,0xF8,0x4C,0xFC,0xFC,0xA0,0xA0,0x20,0x20,0xFE,0xFE,0x10,0x10,0x10,0x00,
0x00,0x00,0x0F,0x0F,0x04,0x0F,0x0F,0x00,0x01,0x11,0x30,0x3F,0x3F,0x00,0x00,0x00,
0x00,0x00
};
unsigned char 	code jian1[]=
{
/*--  文字:  间  --*/
/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=17x16   --*/
0x00,0x00,0xF8,0xFA,0x06,0xE4,0xE4,0xB4,0xF4,0xF6,0x02,0x02,0xFE,0xFE,0x00,0x00,
0x00,0x00,0x00,0x1F,0x1F,0x00,0x07,0x07,0x02,0x07,0x07,0x10,0x30,0x3F,0x1F,0x00,
0x00,0x00
};
unsigned char 	code miao3[]=
{
/*--  文字:  秒  --*/
/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=17x16   --*/
0x00,0x20,0x24,0xA4,0xFC,0xFE,0x92,0x52,0x70,0x30,0xFF,0xFF,0xC8,0xC8,0x18,0x10,
0x00,0x04,0x06,0x03,0x01,0x1F,0x1F,0x21,0x21,0x30,0x18,0x0C,0x06,0x03,0x01,0x00,
0x00,0x00
};
unsigned char 	code sheng1[]=
{
/*--  文字:  升  --*/
/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=17x16   --*/
0x80,0x80,0x80,0x90,0x90,0xF8,0xFC,0x44,0x40,0xFF,0xFF,0x40,0x40,0x40,0x40,0x00,
0x00,0x00,0x00,0x20,0x30,0x18,0x0F,0x07,0x00,0x00,0x7F,0x7F,0x00,0x00,0x00,0x00,
0x00,0x00
};
unsigned char 	code wei2[]=
{
/*--  文字:  维  --*/
/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=17x16   --*/
0x00,0x20,0xB0,0xF8,0x6E,0xB6,0xB0,0xF0,0xFC,0xAE,0xE6,0xFC,0x58,0x50,0x00,0x00,
0x00,0x00,0x08,0x09,0x0D,0x05,0x07,0x02,0x7F,0x7F,0x12,0x1F,0x0F,0x09,0x09,0x08,
0x00,0x00
};
unsigned char 	code chi2[]=
{
/*--  文字:  持  --*/
/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=17x16   --*/
0x00,0x20,0x20,0xFF,0xFF,0x90,0x50,0x50,0x50,0x7F,0xFF,0xA8,0x28,0x28,0x20,0x20,
0x00,0x02,0x02,0x13,0x3F,0x3F,0x00,0x02,0x06,0x0E,0x2B,0x7F,0x7F,0x01,0x01,0x01,
0x00,0x00
};
unsigned char code bmp_1[]=
{
/*--  宽度x高度=64x64  --*/
0x00,0x00,0x00,0x00,0x00,0xC0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,
0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,
0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,
0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x01,0x01,0x01,0x01,0x01,0xC1,0x41,
0x41,0xC1,0x01,0xC1,0x41,0x41,0x41,0x41,0x01,0x01,0x01,0x81,0x81,0x81,0xE1,0x81,
0x81,0x81,0x01,0x01,0x01,0x81,0x61,0x41,0x41,0x41,0x41,0x41,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x1F,0x10,
0x10,0x1F,0x00,0x13,0x92,0x92,0x92,0x9E,0x80,0x00,0x00,0x0F,0x0A,0x0A,0x3F,0x2A,
0x2A,0x2F,0x20,0xB0,0x81,0x04,0x05,0x05,0x05,0x35,0xBD,0xA4,0x20,0x20,0x38,0x30,
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x09,0x9B,
0x9B,0x00,0x00,0xE0,0x2F,0xEA,0x2A,0xEA,0x2F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x82,0x42,0x22,0xFF,0x12,0x02,0x00,0x4E,0x22,0x52,0x42,0xC2,0x42,0x52,0x22,
0x4E,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xE0,0xE0,0xE0,0xE0,0xE0,0xE1,0xE1,
0xE1,0xE0,0xE2,0xE3,0xE2,0xE3,0xE2,0xE3,0xE2,0xE3,0xE2,0xE0,0xE0,0xE0,0xE0,0xE0,
0xE0,0xE0,0xE0,0xE1,0xE3,0xE0,0xE0,0xE0,0xE0,0xE2,0xE2,0xE2,0xE3,0xE2,0xE2,0xE2,
0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xF0,0xF8,0xF9,0xF9,0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,
0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,
0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,0x79,
0x79,0x79,0x79,0x79,0x79,0x79,0x79,0xF9,0xF9,0xF8,0xF0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,
0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x0B,0x0B,0x09,0x0F,
0x00,0x00,0x0E,0x0A,0x0A,0x0E,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x1F,0x3F,0x3F,0x3F,0x3F,0x3E,0x3E,0x3C,0x3C,0x3C,0x3C,0x3C,
0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,
0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,
0x3C,0x3C,0x3C,0x3C,0x3E,0x3E,0x3F,0x3F,0x3F,0x3F,0x1F,0x00,0x00,0x00,0x00,0x00
};
void delay(void)
{ uint i,j;
	for(i=1;i<=100;i++)
		for(j=1;j<=1000;j++);
 
}

void delayms(uint ms) 
// 延时子程序
{
 uchar i;
 while(ms--)
 {
  for(i = 0; i < 120; i++);
 }
}

void delay_18b20(uint s)
{
	for(;s>0;s--);
}

uchar rest_18b20(void)
{
 uchar i;
 DQ=0;
 delay_18b20(29);
 DQ=1;
 delay_18b20(3);
 i=DQ;
  delay_18b20(25);
  return i;
}

char read_18b20(void)
{
uchar i,j=0;
for(i=8;i>0;i--)
   {
   		j>>=1;
		DQ=0;
		DQ=1;
		delay_18b20(1);
		if(DQ)j|=0x80;
		delay_18b20(6);
   }
 return j;
}

void write_18b20(char i)
{
	uchar j;

⌨️ 快捷键说明

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