完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include #include #define uint16 unsigned short int #define uchar unsigned char #define uint unsigned int #define RS_SET IO0SET=1<<8 #define rs_clr="RS_CLR" io0clr="1<<8 #define" rw_set="RW_SET" io0set="1<<9 #define" rw_clr="RW_CLR" io0clr="1<<9 #define" en_set="EN_SET" io0set="1<<10 #define" en_clr="EN_CLR" io0clr="1<<10 #define" DataPort(Y) io0set="Y" typedef union="union" { unsigned="unsigned" int="int" i; //定义了两个共用体 float="float" f; } value; enum { TEMP,HUMI}; //void delay1(unsigned int="int" t) //{ //unsigned int="int" temp="2100; " //for(;t>0;t--) // for(;temp>0;temp--); //} void delay1(void) { int a=3000; while(a--); } void LCD_Write_Com(unsigned char com) { delay1(); RS_CLR; RW_CLR; EN_SET; DataPort(com); delay1(); EN_CLR; IO0CLR=0xff; } void LCD_Write_Data(unsigned char Data) { delay1(); RS_SET; RW_CLR; EN_SET; DataPort(Data); delay1(); EN_CLR; IO0CLR=0xff; } /* * -------------------------------------- * ;模块名称CD_init(); * ;功 能:初始化LCD1602 * ;------------------------------------- */ void LCD_Init(void) { LCD_Write_Com(0x38); /*显示模式设置*/ delay1(); LCD_Write_Com(0x38); delay1(); LCD_Write_Com(0x38); delay1(); LCD_Write_Com(0x38); LCD_Write_Com(0x08); /*显示关闭*/ LCD_Write_Com(0x01); /*显示清屏*/ LCD_Write_Com(0x06); /*显示光标移动设置*/ delay1(); LCD_Write_Com(0x0C); /*显示开及光标设置*/ } /** * -------------------------------------- * ;模块名称CD_disp_char(); * ;功 能CD1602显示一个字符函数,在某个屏幕位置上显示一个字符,X(0-15),y(1-2)。 * ;------------------------------------- */ void LCD_disp_char(uchar x, uchar y, uchar dat) { uchar address; if (y == 1) address = 0x80 + x; else address = 0xc0 + x; LCD_Write_Com(address); LCD_Write_Data(dat); } /** * -------------------------------------- * ;模块名称CD_disp_str(); * ;功 能CD1602显示字符串函数,在某个屏幕起始位置{X(0-15),y(1-2)}上显示一个字符串。 * ;------------------------------------- */ void LCD_disp_str(uchar x, uchar y, uchar * str) { uchar address; if (y == 1) address = 0x80 + x; else address = 0xc0 + x; LCD_Write_Com(address); while (* str != ' |