/***************************************************** 函数功能:显示没有检测到DS18B20 ***************************************************/ void DS18B20_display_error(void) { unsigned char i; Lcd_WriteCom(0x01); //清屏 Lcd_delay(5); Lcd_WriteAddress(0x00); //写显示地址,将在第1行第1列开始显示 i = 0; //从第一个字符开始显示 while(Error[i] != '\0') //只要没有写到结束标志,就继续写 { Lcd_WriteData(Error[i]); //将字符常量写入LCD i++; //指向下一个字符 Lcd_delay(10); //延时100ms较长时间,以看清关于显示的说明 } Lcd_WriteAddress(0x40); //写显示地址,将在第1行第1列开始显示 i = 0; //从第一个字符开始显示 while(Error1[i] != '\0') //只要没有写到结束标志,就继续写 { Lcd_WriteData(Error1[i]); //将字符常量写入LCD i++; //指向下一个字符 Lcd_delay(10); //延时100ms较长时间,以看清关于显示的说明 } Ds18B20_beep(); //蜂鸣器响一声函数 // while(1) //进入死循环,等待查明原因 如果多个应用的话会使别的程序没办法运行,一般不加 ; }
/*****画点函数*****/ void Lcd_DrawPoint(u8 X,u8 Y,u8 Color ) //0000 1111 0000 0000 { u8 Row , Lie , Lie_bit ; u8 ReadOldH, ReadOldL ; Lcd_WriteCmd(0x34); Lcd_WriteCmd(0x36); Lie=X>> 4 ; //0000 0000 右移4等同于除以16,得到大地址 Lie_bit=X&0x0f ; //0000 1111 15 得到小地址 if(Y<32) { Row=Y; //0000 0000 0 } else { Row=Y-32; Lie+=8; } Lcd_WriteCmd(Row+0x80); //0 Lcd_WriteCmd(Lie+0x80); //0 Lcd_ReadData(); //虚读一次 ReadOldH =Lcd_ReadData(); ReadOldL =Lcd_ReadData(); Lcd_WriteCmd(Row+0x80); Lcd_WriteCmd(Lie+0x80); if(Lie_bit<8) { switch( Color) { case 0 : ReadOldH&=(~(0x01<<(7-Lie_bit))) ; break; //将该点变为0 case 1 : ReadOldH|=(0x01<<(7-Lie_bit)); break; //将该点变为1 case 2 : ReadOldH^=(0x01<<(7-Lie_bit )); break; //将该点翻转 default : break ; } Lcd_WriteData(ReadOldH) ; Lcd_WriteData(ReadOldL) ; } else { switch(Color) { case 0 : ReadOldL&=(~(0x01<<(15-Lie_bit)));break ; //将该点变为0 case 1 : ReadOldL|=(0x01<<(15-Lie_bit));break ; //将该点变为1 case 2 : ReadOldL^=(0x01<<(15-Lie_bit));break ; //将该点翻转 default : break ; } Lcd_WriteData(ReadOldH); Lcd_WriteData(ReadOldL); } Lcd_WriteCmd(0x30); }
/***************************************************** 函数功能:显示温度的小数数部分 入口参数:x ***************************************************/ void DS18B20_display_temp2(unsigned char x) { Lcd_WriteAddress(0x4a); //写显示地址,将在第2行第11列开始显示 Lcd_delay(1); //延时10ms给硬件一点反应时间 Lcd_WriteData(digit[x]); //将小数部分的第一位数字字符常量写入LCD Lcd_delay(1); //延时1ms给硬件一点反应时间 }
/************************************************* LCD_DrawPoint *************************************************/ void Gui_DrawPoint(u16 x,u16 y,u16 Data) { Lcd_SetRegion(x,y,x+1,y+1); Lcd_WriteData(Data>>8); Lcd_WriteData(Data); }
/************************************************* 函数名:LCD_DrawPoint 功能:画一个点 入口参数:无 返回值:无 *************************************************/ void Gui_DrawPoint(u16 x,u16 y,u16 Data) { Lcd_SetXY(x,y); Lcd_WriteData(Data>>8); Lcd_WriteData(Data); }
//当i=0时显示上面128×32,当i=8时显示下面128×32 //当i=0时显示上面128×32,当i=8时显示下面128×32 void Lcd_Fill(u8 test) { u8 x,y,i; for(i=0;i<9;i=i+8) for(y=0;y<0x20;y++) { for(x=0;x<8;x++) { Lcd_WriteCmd(0x36); //扩充指令 绘图显示 Lcd_WriteCmd(y+0x80); //行地址 Lcd_WriteCmd(x+0x80+i); //列地址 Lcd_WriteData(test); //写数据 D15-D8 Lcd_WriteData(test); //写数据 D7-D0 Lcd_WriteCmd(0x30); } } }
//图片取模方式:横向取模,字节正序 void pic_Disp(u8 *pic) //显示Gdram内容(显示图片) { u8 x,y; //for(i=0;i<9;i=i+8) for(y=0;y<16;y++) { for(x=0;x<1;x++) { Lcd_WriteCmd(0x36); //扩充指令,开绘图显示 Lcd_WriteCmd(0x80+y); //行地址 Lcd_WriteCmd(0x80+x); //列地址 Lcd_WriteData(*pic++); //写数据 D15-D8 Lcd_WriteData(*pic++); //写数据 D7-D0 Lcd_WriteCmd(0x30); } } }
//********************************************************************** // 清除液晶GDRAM中的数据 //********************************************************************** void Lcd_Clear(void) { unsigned char i,j,k; Lcd_WriteCmd(0x34); //打开扩展指令集 i = 0x80; for(j = 0;j < 32;j++) { Lcd_WriteCmd(i); Lcd_WriteCmd(0x80); for(k = 0;k < 16;k++) Lcd_WriteData(0x00); Lcd_WriteCmd(i++); Lcd_WriteCmd(0x88); for(k = 0;k < 16;k++) Lcd_WriteData(0x00); } }
void Table_Disp(u8 x,u8 y,u8 *s)//x:0~3 y: { Lcd_WriteCmd(addr_tab[8*x+y]); //写地址 while(*s) { Lcd_WriteData(*s); //写数据 s++; } }
void hanzi_Disp(Uint16 x,Uint16 y,char *s) { Lcd_WriteCmd(addr_tab[8*x+y]); //写地址 while(*s>0) { Lcd_WriteData(*s); //写数据 DelayUS2(1); s++; } }
/***************************************** TFT ******************************************/ unsigned int Lcd_ReadPoint(u16 x,u16 y) { unsigned int Data; Lcd_SetXY(x,y); //Lcd_ReadData();// //Data=Lcd_ReadData(); Lcd_WriteData(Data); return Data; }
/*****整屏显示横条*****/ void LcdFill_Level(void) { u8 x,y,i; u8 k; for(i=0;i<9;i+=8) for(y=0;y<0x20;y++) { if((y%2)==1) k=0xff; else k=0; for(x=0;x<8;x++) { Lcd_WriteCmd(0x36); //扩充指令 绘图显示 Lcd_WriteCmd(y+0x80); //行地址 Lcd_WriteCmd(x+0x80+i); //列地址 Lcd_WriteData(k); Lcd_WriteData(k); Lcd_WriteCmd(0x30); } } }
/************************************************* Lcd_Clear *************************************************/ void Lcd_Clear(u16 Color) { unsigned int i,m; Lcd_SetRegion(0,0,X_MAX_PIXEL-1,Y_MAX_PIXEL-1); Lcd_WriteIndex(0x2C); for(i=0;i<128;i++) for(m=0;m<160;m++) { Lcd_WriteData(Color>>8); Lcd_WriteData(Color); } }
/************************************************* Lcd_Clear *************************************************/ void Lcd_Clear(u16 Color) { unsigned int i,m; // Lcd_SetRegion(0,0,X_MAX_PIXEL-1,Y_MAX_PIXEL-1);// Kullan1lmayacak. Text le gozukmuyor Lcd_WriteIndex(0x2C); for(i=0;i<X_MAX_PIXEL;i++)// orjinali 128 for(m=0;m<Y_MAX_PIXEL;m++)//orjinali 160 { Lcd_WriteData(Color>>8); Lcd_WriteData(Color); } }
/***************************************************** 函数功能:显示温度的整数部分 入口参数:x ***************************************************/ void DS18B20_display_temp1(unsigned char x) { unsigned char j,k,l; //j,k,l分别储存温度的百位、十位和个位 j=x/100; //取百位 k=(x%100)/10; //取十位 l=x%10; //取个位 Lcd_WriteAddress(0x46); //写显示地址,将在第2行第7列开始显示 if(flag==1) //负温度时 显示“—” { Lcd_WriteData(digit[10]); //将百位数字的字符常量写入LCD Lcd_delay(1); //延时5ms给硬件一点反应时间 } else{ Lcd_WriteData(digit[j]); //将百位数字的字符常量写入LCD Lcd_delay(1); //延时5ms给硬件一点反应时间 } Lcd_WriteData(digit[k]); //将十位数字的字符常量写入LCD Lcd_delay(1); //延时5ms给硬件一点反应时间 Lcd_WriteData(digit[l]); //将个位数字的字符常量写入LCD Lcd_delay(1); //延时5ms给硬件一点反应时间 }
/***************************************************** 函数功能:显示说明信息 ***************************************************/ void DS18B20_display_explain(void) { unsigned char i; Lcd_WriteAddress(0x00); //写显示地址,将在第1行第1列开始显示 i = 0; //从第一个字符开始显示 while(Str[i] != '\0') //只要没有写到结束标志,就继续写 { Lcd_WriteData(Str[i]); //将字符常量写入LCD i++; //指向下一个字符 Lcd_delay(1); //延时100ms较长时间,以看清关于显示的说明 } }
/***************************************************** 函数功能:显示温度的单位(Cent) ***************************************************/ void DS18B20_display_cent(void) { unsigned char i; Lcd_WriteAddress(0x4c); //写显示地址,将在第2行第13列开始显示 i = 0; //从第一个字符开始显示 while(Cent[i] != '\0') //只要没有写到结束标志,就继续写 { Lcd_WriteData(Cent[i]); //将字符常量写入LCD i++; //指向下一个字符 Lcd_delay(1); //延时1ms给硬件一点反应时间 } }
void Lcd_Clear(uint16_t Color) { unsigned int i,m; Lcd_SetRegion(0, 0, X_MAX_PIXEL-1, Y_MAX_PIXEL-1); Lcd_WriteIndex(0x2C); for(i = 0; i < X_MAX_PIXEL; i++){ for(m = 0; m < Y_MAX_PIXEL; m++){ Lcd_WriteData(Color>>8); Lcd_WriteData(Color); } } LCD_CS_SET; }
void Lcd_SetRegion(uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end) { Lcd_WriteIndex(0x2a); Lcd_WriteData(0x00); Lcd_WriteData(x_start); Lcd_WriteData(0x00); Lcd_WriteData(x_end); Lcd_WriteIndex(0x2b); Lcd_WriteData(0x00); Lcd_WriteData(y_start); Lcd_WriteData(0x00); Lcd_WriteData(y_end); Lcd_WriteIndex(0x2c); }
/**************************************************************************** Function: Name Description:在LCD写入一个字符 Input: Output: Notes: *****************************************************************************/ void Lcd_StrDisp(u8 x,u8 y,const u8 *s) { const u8 addr_tab[]= { 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, 0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, 0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, }; Lcd_WriteCmd(addr_tab[8*x+y]); while(*s>0) { Lcd_WriteData(*s); s++; } }
//********************************************************************** // 向 LCD 指定起始位置写入一个字符串 //********************************************************************** void Lcd_WriteStr(unsigned char x,unsigned char y,unsigned char *Str) { Lcd_WriteCmd(0x30); switch(y) { case 0: Lcd_WriteCmd(0x80+x); break; case 1: Lcd_WriteCmd(0x90+x); break; case 2: Lcd_WriteCmd(0x88+x); break; case 3: Lcd_WriteCmd(0x98+x); break; } while(*Str>0) { Lcd_WriteData(*Str); Str++; } }
/******************************************************** 名称:GUI_Point(打点) 说明:X:横坐标(代表列的位置,0~127) Y:纵坐标(代表行的位置,0~63) 根据Datesheet需先把数据写到GDRAM,读取当前位置的数据,经过或和移位后再把数据重新写入 GDRAM每行有16个位元,共64行,每个位元有两个8位(高低8位) 计算出在那个位元,在该位元的哪一位 易出现的问题:1、打点位置的定位 2、读取当前显示的数据 3、或和移位,即重新写人的新数据 ********************************************************/ void GUI_Point(u8 x,u8 y,u8 flag) { u8 x_Dyte,x_byte; //定义列地址的字节位,及在字节中的哪1位 u8 y_Dyte,y_byte; //定义为上下两个屏(取值为0,1),行地址(取值为0~31) u8 GDRAM_hbit,GDRAM_lbit; Lcd_WriteCmd(0x36); //绘图模式命令 /***X,Y坐标互换,即普通的X,Y坐标***/ x_Dyte=x/16; //计算在16个字节中的哪一个 x_byte=x&0x0f; //计算在该字节中的哪一位 y_Dyte=y/32; //0为上半屏,1为下半屏 y_byte=y&0x1f; //计算在0~31当中的哪一行 Lcd_WriteCmd(0x80+y_byte); //设定行地址(y坐标) Lcd_WriteCmd(0x80+x_Dyte+8*y_Dyte); //设定列地址(x坐标),并通过8*y_Dyte选定上下屏 Lcd_ReadData(); GDRAM_hbit=Lcd_ReadData(); //读取当前显示高8位数据 GDRAM_lbit=Lcd_ReadData(); //读取当前显示低8位数据 delay_us(5); if(flag==1) { Lcd_WriteCmd(0x80+y_byte); //设定行地址(y坐标) Lcd_WriteCmd(0x80+x_Dyte+8*y_Dyte); //设定列地址(x坐标),并通过8*y_Dyte选定上下屏 delay_us(5); if(x_byte<8) //判断其在高8位,还是在低8位 { Lcd_WriteData(GDRAM_hbit|(0X01<<(7-x_byte))); //显示GDRAM区高8位数据 Lcd_WriteData(GDRAM_lbit); //显示GDRAM区低8位数据 } else { Lcd_WriteData(GDRAM_hbit); Lcd_WriteData(GDRAM_lbit|(0x01<<(15-x_byte))); } } else { Lcd_WriteData(0x00); //清除GDRAM区高8位数据 Lcd_WriteData(0x00); //清除GDRAM区低8位数据 } }
//********************************************************************** // 有反白显示功能的打点函数:(X-水平位址,Y-竖直位址) //********************************************************************** void GUI_Point(unsigned char x,unsigned char y,unsigned char color) { unsigned char x_Dyte,x_byte; //定义列地址的字节位,及在字节中的哪1位 unsigned char y_Dyte,y_byte; //定义为上下两个屏(取值为0,1),行地址(取值为0~31) unsigned char GDRAM_hbit,GDRAM_lbit; Lcd_WriteCmd(0x36); //扩展指令命令 x_Dyte=x/16; //计算在16个字节中的哪一个 x_byte=x&0x0f; //计算在该字节中的哪一位 y_Dyte=y/32; //0为上半屏,1为下半屏 y_byte=y&0x1f; //计算在0~31当中的哪一行 Lcd_WriteCmd(0x80+y_byte); //设定行地址(y坐标) Lcd_WriteCmd(0x80+x_Dyte+8*y_Dyte); //设定列地址(x坐标) Lcd_ReadData(); //预读取数据 GDRAM_hbit=Lcd_ReadData(); //读取当前显示高8位数据 GDRAM_lbit=Lcd_ReadData(); //读取当前显示低8位数据 Lcd_WriteCmd(0x80+y_byte); //设定行地址(y坐标) Lcd_WriteCmd(0x80+x_Dyte+8*y_Dyte); //设定列地址(x坐标) if(x_byte<8) //判断其在高8位,还是在低8位 { if(color==1) { Lcd_WriteData(GDRAM_hbit|(0x01<<(7-x_byte)));//置位GDRAM区高8位数据中相应的点 } else Lcd_WriteData(GDRAM_hbit&(~(0x01<<(7-x_byte))));//清除GDRAM区高8位数据中相应的点 Lcd_WriteData(GDRAM_lbit); //显示GDRAM区低8位数据 } else { Lcd_WriteData(GDRAM_hbit); if(color==1) Lcd_WriteData(GDRAM_lbit|(0x01<<(15-x_byte)));//置位GDRAM区高8位数据中相应的点 else Lcd_WriteData(GDRAM_lbit&(~(0x01<<(15-x_byte))));//清除GDRAM区高8位数据中相应的点 } Lcd_WriteCmd(0x30); //恢复到基本指令集 }
void Lcd_Init(void) { LCD_GPIO_Init(); Lcd_Reset(); Lcd_WriteIndex(0x11);//Sleep exit xSysCtlDelay(xSysCtlClockGet()/10); //ST7735R Frame Rate Lcd_WriteIndex(0xB1); Lcd_WriteData(0x01); Lcd_WriteData(0x2C); Lcd_WriteData(0x2D); Lcd_WriteIndex(0xB2); Lcd_WriteData(0x01); Lcd_WriteData(0x2C); Lcd_WriteData(0x2D); Lcd_WriteIndex(0xB3); Lcd_WriteData(0x01); Lcd_WriteData(0x2C); Lcd_WriteData(0x2D); Lcd_WriteData(0x01); Lcd_WriteData(0x2C); Lcd_WriteData(0x2D); Lcd_WriteIndex(0xB4); //Column inversion Lcd_WriteData(0x07); //ST7735R Power Sequence Lcd_WriteIndex(0xC0); Lcd_WriteData(0xA2); Lcd_WriteData(0x02); Lcd_WriteData(0x84); Lcd_WriteIndex(0xC1); Lcd_WriteData(0xC5); Lcd_WriteIndex(0xC2); Lcd_WriteData(0x0A); Lcd_WriteData(0x00); Lcd_WriteIndex(0xC3); Lcd_WriteData(0x8A); Lcd_WriteData(0x2A); Lcd_WriteIndex(0xC4); Lcd_WriteData(0x8A); Lcd_WriteData(0xEE); Lcd_WriteIndex(0xC5); //VCOM Lcd_WriteData(0x0E); Lcd_WriteIndex(0x36); //MX, MY, RGB mode Lcd_WriteData(0xC8); //ST7735R Gamma Sequence Lcd_WriteIndex(0xe0); Lcd_WriteData(0x0f); Lcd_WriteData(0x1a); Lcd_WriteData(0x0f); Lcd_WriteData(0x18); Lcd_WriteData(0x2f); Lcd_WriteData(0x28); Lcd_WriteData(0x20); Lcd_WriteData(0x22); Lcd_WriteData(0x1f); Lcd_WriteData(0x1b); Lcd_WriteData(0x23); Lcd_WriteData(0x37); Lcd_WriteData(0x00); Lcd_WriteData(0x07); Lcd_WriteData(0x02); Lcd_WriteData(0x10); Lcd_WriteIndex(0xe1); Lcd_WriteData(0x0f); Lcd_WriteData(0x1b); Lcd_WriteData(0x0f); Lcd_WriteData(0x17); Lcd_WriteData(0x33); Lcd_WriteData(0x2c); Lcd_WriteData(0x29); Lcd_WriteData(0x2e); Lcd_WriteData(0x30); Lcd_WriteData(0x30); Lcd_WriteData(0x39); Lcd_WriteData(0x3f); Lcd_WriteData(0x00); Lcd_WriteData(0x07); Lcd_WriteData(0x03); Lcd_WriteData(0x10); Lcd_WriteIndex(0x2a); Lcd_WriteData(0x00);Lcd_WriteData(0x00); Lcd_WriteData(0x00);Lcd_WriteData(0x7f); Lcd_WriteIndex(0x2b); Lcd_WriteData(0x00);Lcd_WriteData(0x00); Lcd_WriteData(0x00);Lcd_WriteData(0x9f); Lcd_WriteIndex(0xF0); //Enable test command Lcd_WriteData(0x01); Lcd_WriteIndex(0xF6); //Disable ram power save mode Lcd_WriteData(0x00); Lcd_WriteIndex(0x3A); //65k mode Lcd_WriteData(0x05); Lcd_WriteIndex(0x29);//Display on }
void Lcd_WriteReg(uint8_t Index, uint8_t Data) { Lcd_WriteIndex(Index); Lcd_WriteData(Data); }
void Gui_DrawPoint(uint16_t x,uint16_t y, uint16_t Data) { Lcd_SetRegion(x,y,x+1,y+1); Lcd_WriteData(Data>>8); Lcd_WriteData(Data); }
void Lcd_WriteReg(u8 Index,u8 Data) { Lcd_WriteIndex(Index); Lcd_WriteData(Data); }
/***************************************************** 函数功能:显示温度的小数点 ***************************************************/ void DS18B20_display_dot(void) { Lcd_WriteAddress(0x49); //写显示地址,将在第2行第10列开始显示 Lcd_WriteData('.'); //将小数点的字符常量写入LCD Lcd_delay(1); //延时1ms给硬件一点反应时间 }
void Lcd_WriteReg(u8 Index, u16 Data) { Lcd_WriteIndex(Index); Lcd_WriteData( Data>>8 ); Lcd_WriteData(Data); }
/*****显示一个字节*****/ void Disp_achar(u8 x,u8 y,u8 achar)//x:0~3 y: { Lcd_WriteCmd(addr_tab[8*x+y]); //写地址 Lcd_WriteData(achar); //写数据 }