制作出来的1.44寸彩屏显示实物图如下:
单片机源程序如下:
- ////////////////////////////////////////////////////////////////////////////////// //本程序只供学习使用,未经作者许可,不得用于其它任何用途
- //测试硬件:STC12LE5A60S2
- //1.5寸TFT_ST7735液晶驱动
- //版本:V1.0
- //版权所有,盗版必究。
- //Copyright(C) 深圳市全动电子技术有限公司 2009-2019
- //All rights reserved
- //********************************************************************************
- //V1.1修改说明
- //加入横屏显示代码,直接在初始化中切换横竖屏模式
- //////////////////////////////////////////////////////////////////////////////////
- #include<reg51.h>
- #include<absacc.h>
- #include<intrins.h>
- #include<string.h>
- #define uchar unsigned char
- #define uint unsigned int
- //测试硬件平台:STC12C5A60S2/STC12LE5A60S2
- //主频:12MHZ
- //单片机IO推挽输出设置定义
- //#define USE_LANDSCAPE//测试程序横竖屏切换,横屏请开启此宏,竖屏请屏蔽
- #define MCU_STC12//如果您使用的单片机不是STC12系列(如STC89C52)请屏蔽此宏定义
- #ifdef MCU_STC12
- sfr P3M1 = 0xB1; //P3M1.n,P3M0.n =00--->Standard, 01--->push-pull
- sfr P3M0 = 0xB2; // =10--->pure input, 11--->open drain
- #endif
- //---------------------------液晶屏接线说明-------------------------------------//
- /*
- sbit bl =P3^2;//接模块BL引脚,背光可以采用IO控制或者PWM控制,也可以直接接到高电平常亮
- sbit scl =P1^7;//接模块CLK引脚,接裸屏Pin9_SCL
- sbit sda =P1^5;//接模块DIN/MOSI引脚,接裸屏Pin8_SDA
- sbit rs =P1^2;//接模块D/C引脚,接裸屏Pin7_A0
- sbit cs =P1^3;//接模块CE引脚,接裸屏Pin12_CS
- sbit reset =P3^3;//接模块RST引脚,接裸屏Pin6_RES
- */
- sbit sda =P1^0;//接模块DI
- sbit scl =P1^1;//接模块SC
- sbit cs =P1^2;//接模块CS
- sbit reset =P1^3;//接模块RST
- sbit rs =P1^4;//接模块rs
- sbit bl =P1^5;//接模块BLk
- //---------------------------End of液晶屏接线---------------------------------//
- //定义常用颜色
- #define RED 0xf800
- #define GREEN 0x07e0
- #define BLUE 0x001f
- #define WHITE 0xffff
- #define BLACK 0x0000
- #define YELLOW 0xFFE0
- #define GRAY0 0xEF7D
- #define GRAY1 0x8410
- #define GRAY2 0x4208
- void Contrast_Adjust();
- uchar code Zk_ASCII8X16[];
- uint sec,s;
- void Display_Desc();
- void Output_Pixel(uint x,uint y);
- void Display_ASCII8X16(uint x0,uint y0,uchar *s);
- void delay_ms(uint time)
- {
- uint i,j;
- for(i=0;i<time;i++)
- for(j=0;j<250;j++);
- }
- /************************************以上为DS18B20内容******************************************/
- /******************DS18B20温度***********************/
- sbit DS18B20=P1^6;
- #define DS18B20_H {DS18B20=1;}
- #define DS18B20_L {DS18B20=0;}
- uchar DS18B20_V() {return DS18B20;}
- void Read_Temp();
- uchar DS18B20_Reset();
- void DS18B20_WriteData(unsigned char wData);
- uchar DS18B20_ReadData();
- uchar g=2;//STC12比STC8951快的倍数(只有1-2倍可用)
- /***************************18B20温度返回*******wd******************/
- uchar temperature[2];//定义一个整合数据
- long wd()
- {
- unsigned char temp_data;
- long wd=0;//温度值清0
- temp_data = temperature[1];
- temp_data &= 0xf0; //取高4位
- if (temp_data==0xf0) //判断是正温度还是负温度读数
- {
- //负温度读数求补,取反加1,判断低8位是否有进位
- if (temperature[0]==0)
- { //有进位,高8位取反加1
- temperature[0]=~temperature[0]+1;
- temperature[1]=~temperature[1]+1;
- }
- else
- { //没进位,高8位不加1
- temperature[0]=~temperature[0]+1;
- temperature[1]=~temperature[1];
- }
- }
- wd=(temperature[1]*256+temperature[0])*(0.0625*10000);
- //wd=12345;
- return wd;//返回一个数据(温度)用于显示
- }
- /**********************读温度数据函数***********************************/
- void Read_Temp()
- {
- unsigned char i;
- DS18B20_Reset(); //复位
- DS18B20_WriteData(0xcc); //跳过ROM命令
- DS18B20_WriteData(0x44); //温度转换命令
- DS18B20_Reset(); //复位
- DS18B20_WriteData(0xcc); //跳过ROM命令
- DS18B20_WriteData(0xbe); //读DS18B20温度暂存器命令
- for (i=0;i<2;i++)
- {
- temperature[i]=DS18B20_ReadData();
- }
- DS18B20_Reset(); //复位,结束读数据
- }
- /****************************DS18B20复位及存在检测******************************/
- uchar DS18B20_Reset()
- {
- unsigned char i;
- uchar flag; //DS18B20存在标志位
- DS18B20_L; //拉低总线
- for (i=(240*g);i>0;i--);//延时480微秒,产生复位脉冲
- DS18B20_H; //释放总线
- for (i=(40*g);i>0;i--); //延时80微秒对总线采样
- flag = DS18B20_V();
- for (i=(200*g);i>0;i--); //延时400微秒等待总线恢复
- return (flag); //根据flag的值可以知道DS18B20是否存在或损坏
- } //可以加声音告警提示DS18B20故障
- /***********************写数据到DS18B20 ***********************************/
- void DS18B20_WriteData(unsigned char wData)
- {
- unsigned char i,j;
- for (i=8;i>0;i--)
- {
- DS18B20_L; //拉低总线,产生写信号
- for (j=(7*g);j>0;j--); //延时14us
- if((bit)(wData&0x01)==1)//发送1位
- {
- DS18B20_H;
- }
- else
- {
- DS18B20_L;
- }
- for (j=(30*g);j>0;j--); //延时60us,写时序至少要60us
- DS18B20_H; //释放总线,等待总线恢复
- wData>>=1; //准备下一位数据的传送
- }
- }
- /************************DS18B20中读出数据**********************************/
- unsigned char DS18B20_ReadData()
- {
- unsigned char i,j,TmepData;
- for (i=8;i>0;i--)
- {
- TmepData>>=1;
- DS18B20_L; //拉低总线,产生读信号
- for (j=(2*g);j>0;j--); //延时4us
- DS18B20_H; //释放总线,准备读数据
- for (j=(4*g);j>0;j--); //延时8微秒读数据
- if (DS18B20_V()) TmepData |= 0x80;
- for (j=(15*g);j>0;j--); //延时30us
- DS18B20_H; //拉高总线,准备下一位数据的读取.
- }
- return (TmepData);//返回读到的数据
- }
- //向SPI总线传输一个8位数据
- void SPI_WriteData(uchar Data)
- {
- unsigned char i=0;
- for(i=8;i>0;i--)
- {
- if(Data&0x80)
- sda=1; //输出数据
- else sda=0;
- scl=0;
- scl=1;
- Data<<=1;
- }
- }
- //向液晶屏写一个8位指令
- void Lcd_WriteIndex(uchar Data)
- {
-
- cs=0;
- rs=0;
- SPI_WriteData(Data);
- cs=1;
- }
- //向液晶屏写一个8位数据
- void Lcd_WriteData(uchar Data)
- {
- unsigned char i=0;
- cs=0;
- rs=1;
- SPI_WriteData(Data);
- cs=1;
- }
- //向液晶屏写一个16位数据
- void LCD_WriteData_16Bit(unsigned int Data)
- {
- unsigned char i=0;
- cs=0;
- rs=1;
- SPI_WriteData(Data>>8); //写入高8位数据
- SPI_WriteData(Data); //写入低8位数据
- cs=1;
- }
- void Reset()
- {
- reset=0;
- delay_ms(100);
- reset=1;
- delay_ms(100);
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- //液晶屏初始化 for S6D02A1
- void lcd_initial()
- { Reset();//Reset before LCD Init.
-
- //LCD Init For 1.44Inch LCD Panel with ST7735R.
- Lcd_WriteIndex(0x11);//Sleep exit
- delay_ms (120);
-
- //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
- #ifdef USE_LANDSCAPE
- Lcd_WriteData(0xA8); //竖屏C8 横屏08 A8
- #else
- Lcd_WriteData(0xC8); //竖屏C8 横屏08 A8
- #endif
- //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+2);
- Lcd_WriteData(0x00);
- Lcd_WriteData(0x80+2);
- Lcd_WriteIndex(0x2b);
- Lcd_WriteData(0x00);
- Lcd_WriteData(0x00+3);
- Lcd_WriteData(0x00);
- Lcd_WriteData(0x80+3);
-
- 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
- }
- /*************************************************
- 函数名:LCD_Set_Region
- 功能:设置lcd显示区域,在此区域写点数据自动换行
- 入口参数:xy起点和终点
- 返回值:无
- *************************************************/
- void Lcd_SetRegion(unsigned int x_start,unsigned int y_start,unsigned int x_end,unsigned int y_end)
- {
- #ifdef USE_LANDSCAPE//使用横屏模式
- Lcd_WriteIndex(0x2a);
- Lcd_WriteData(0x00);
- Lcd_WriteData(x_start+3);
- Lcd_WriteData(0x00);
- Lcd_WriteData(x_end+3);
- Lcd_WriteIndex(0x2b);
- Lcd_WriteData(0x00);
- Lcd_WriteData(y_start+2);
- Lcd_WriteData(0x00);
- Lcd_WriteData(y_end+2);
- #else//竖屏模式
- Lcd_WriteIndex(0x2a);
- Lcd_WriteData(0x00);
- Lcd_WriteData(x_start+2);
- Lcd_WriteData(0x00);
- Lcd_WriteData(x_end+2);
- Lcd_WriteIndex(0x2b);
- Lcd_WriteData(0x00);
- Lcd_WriteData(y_start+3);
- Lcd_WriteData(0x00);
- Lcd_WriteData(y_end+3);
- #endif
- Lcd_WriteIndex(0x2c);
- }
- void PutPixel(uint x_start,uint y_start,uint color)
- {
- Lcd_SetRegion(x_start,y_start,x_start+1,y_start+1);
- LCD_WriteData_16Bit(color);
-
- }
- void dsp_single_colour(int color) //清屏写入颜色
- {
- uchar i,j;
- Lcd_SetRegion(0,0,128-1,128-1);
- for (i=0;i<128;i++)
- for (j=0;j<128;j++)
- LCD_WriteData_16Bit(color);
- }
- /************************数据处理显示2************************************/
- void dsplay(long temp) //uint uchar 位数不足 long长数据
- { uchar i,j;
- uchar x=20,y=60;
- uchar dt1,dt2,dt3,dt4,dt5,dt6,dt7,dt8;
- dt1 = temp%10;//1位
- dt2 = temp%100/10;//2位
- dt3 = temp%1000/100;//3位
- dt4 = temp%10000/1000;//4位
- dt5 = temp%100000/10000;//5位
- dt6 = temp%1000000/100000;//6位
- dt7 = temp%10000000/1000000;//7位
- dt8 = temp/10000000;//8位 最高位
-
- Display_ASCII8X16(2,y,"WD: ");
-
- /*
- if(dt8==1)Display_ASCII8X16(x,y,"1");
- if(dt8==2)Display_ASCII8X16(x,y,"2");
- if(dt8==3)Display_ASCII8X16(x,y,"3");
- if(dt8==4)Display_ASCII8X16(x,y,"4");
- if(dt8==5)Display_ASCII8X16(x,y,"5");
- if(dt8==6)Display_ASCII8X16(x,y,"6");
- if(dt8==7)Display_ASCII8X16(x,y,"7");
- if(dt8==8)Display_ASCII8X16(x,y,"8");
- if(dt8==9)Display_ASCII8X16(x,y,"9");
- if(dt8==0)Display_ASCII8X16(x,y,"0");
- */
- if(dt7==1)Display_ASCII8X16(x+10,y,"1");
- if(dt7==2)Display_ASCII8X16(x+10,y,"2");
- if(dt7==3)Display_ASCII8X16(x+10,y,"3");
- if(dt7==4)Display_ASCII8X16(x+10,y,"4");
- if(dt7==5)Display_ASCII8X16(x+10,y,"5");
- if(dt7==6)Display_ASCII8X16(x+10,y,"6");
- if(dt7==7)Display_ASCII8X16(x+10,y,"7");
- if(dt7==8)Display_ASCII8X16(x+10,y,"8");
- if(dt7==9)Display_ASCII8X16(x+10,y,"9");
- if(dt7==0)Display_ASCII8X16(x+10,y,"0");
- if(dt6==1)Display_ASCII8X16(x+20,y,"1");
- if(dt6==2)Display_ASCII8X16(x+20,y,"2");
- if(dt6==3)Display_ASCII8X16(x+20,y,"3");
- if(dt6==4)Display_ASCII8X16(x+20,y,"4");
- if(dt6==5)Display_ASCII8X16(x+20,y,"5");
- if(dt6==6)Display_ASCII8X16(x+20,y,"6");
- if(dt6==7)Display_ASCII8X16(x+20,y,"7");
- if(dt6==8)Display_ASCII8X16(x+20,y,"8");
- if(dt6==9)Display_ASCII8X16(x+20,y,"9");
- if(dt6==0)Display_ASCII8X16(x+20,y,"0");
- if(dt5==1)Display_ASCII8X16(x+30,y,"1");
- if(dt5==2)Display_ASCII8X16(x+30,y,"2");
- if(dt5==3)Display_ASCII8X16(x+30,y,"3");
- if(dt5==4)Display_ASCII8X16(x+30,y,"4");
- if(dt5==5)Display_ASCII8X16(x+30,y,"5");
- if(dt5==6)Display_ASCII8X16(x+30,y,"6");
- if(dt5==7)Display_ASCII8X16(x+30,y,"7");
- if(dt5==8)Display_ASCII8X16(x+30,y,"8");
- if(dt5==9)Display_ASCII8X16(x+30,y,"9");
- if(dt5==0)Display_ASCII8X16(x+30,y,"0");
- Display_ASCII8X16(x+40,y,".");
- if(dt4==1)Display_ASCII8X16(x+50,y,"1");
- if(dt4==2)Display_ASCII8X16(x+50,y,"2");
- if(dt4==3)Display_ASCII8X16(x+50,y,"3");
- if(dt4==4)Display_ASCII8X16(x+50,y,"4");
- if(dt4==5)Display_ASCII8X16(x+50,y,"5");
- if(dt4==6)Display_ASCII8X16(x+50,y,"6");
- if(dt4==7)Display_ASCII8X16(x+50,y,"7");
- if(dt4==8)Display_ASCII8X16(x+50,y,"8");
- if(dt4==9)Display_ASCII8X16(x+50,y,"9");
- if(dt4==0)Display_ASCII8X16(x+50,y,"0");
- if(dt3==1)Display_ASCII8X16(x+60,y,"1");
- if(dt3==2)Display_ASCII8X16(x+60,y,"2");
- if(dt3==3)Display_ASCII8X16(x+60,y,"3");
- if(dt3==4)Display_ASCII8X16(x+60,y,"4");
- if(dt3==5)Display_ASCII8X16(x+60,y,"5");
- if(dt3==6)Display_ASCII8X16(x+60,y,"6");
- if(dt3==7)Display_ASCII8X16(x+60,y,"7");
- if(dt3==8)Display_ASCII8X16(x+60,y,"8");
- if(dt3==9)Display_ASCII8X16(x+60,y,"9");
- if(dt3==0)Display_ASCII8X16(x+60,y,"0");
- /*
- if(dt2==1)Display_ASCII8X16(x+60,y,"1");
- if(dt2==2)Display_ASCII8X16(x+60,y,"2");
- if(dt2==3)Display_ASCII8X16(x+60,y,"3");
- if(dt2==4)Display_ASCII8X16(x+60,y,"4");
- if(dt2==5)Display_ASCII8X16(x+60,y,"5");
- if(dt2==6)Display_ASCII8X16(x+60,y,"6");
- if(dt2==7)Display_ASCII8X16(x+60,y,"7");
- if(dt2==8)Display_ASCII8X16(x+60,y,"8");
- if(dt2==9)Display_ASCII8X16(x+60,y,"9");
- if(dt2==0)Display_ASCII8X16(x+60,y,"0");
- if(dt1==1)Display_ASCII8X16(x+70,y,"1");
- if(dt1==2)Display_ASCII8X16(x+70,y,"2");
- if(dt1==3)Display_ASCII8X16(x+70,y,"3");
- if(dt1==4)Display_ASCII8X16(x+70,y,"4");
- if(dt1==5)Display_ASCII8X16(x+70,y,"5");
- if(dt1==6)Display_ASCII8X16(x+70,y,"6");
- if(dt1==7)Display_ASCII8X16(x+70,y,"7");
- if(dt1==8)Display_ASCII8X16(x+70,y,"8");
- if(dt1==9)Display_ASCII8X16(x+70,y,"9");
- if(dt1==0)Display_ASCII8X16(x+70,y,"0");
- */
- Display_ASCII8X16(x+70,y,"C");
-
- delay_ms(3000);//数据刷新频率
- Lcd_SetRegion(x+9,y,x+68,y+14); //(X1,Y1,X2,Y2)X1行开始、 X2行结束 、Y1列开始、 Y2列结束
- for (i=0;i<28;i++) //数据刷新频率
- for (j=0;j<35;j++) //数据刷新频率
- LCD_WriteData_16Bit(RED);// 字体区清除后色
- /*
- //定义常用颜色
- #define RED 0xf800
- #define GREEN 0x07e0
- #define BLUE 0x001f
- #define WHITE 0xffff
- #define BLACK 0x0000
- #define YELLOW 0xFFE0
- #define GRAY0 0xEF7D
- #define GRAY1 0x8410
- #define GRAY2 0x4208
- */
- }
- /************************数据处理显示2************************************/
- void dsplay1(long temp) //uint uchar 位数不足 long长数据
- { uchar i,j;
- uchar x=33,y=80;
- uchar dt1,dt2,dt3,dt4,dt5,dt6,dt7,dt8;
- temp=sec;
- dt1 = temp%10;//1位
- dt2 = temp%100/10;//2位
- dt3 = temp%1000/100;//3位
- dt4 = temp%10000/1000;//4位
- dt5 = temp%100000/10000;//5位
- dt6 = temp%1000000/100000;//6位
- dt7 = temp%10000000/1000000;//7位
- dt8 = temp/10000000;//8位 最高位
-
- Display_ASCII8X16(2,y,"SEC: ");
-
-
- if(dt8==1)Display_ASCII8X16(x,y,"1");
- if(dt8==2)Display_ASCII8X16(x,y,"2");
- if(dt8==3)Display_ASCII8X16(x,y,"3");
- if(dt8==4)Display_ASCII8X16(x,y,"4");
- if(dt8==5)Display_ASCII8X16(x,y,"5");
- if(dt8==6)Display_ASCII8X16(x,y,"6");
- if(dt8==7)Display_ASCII8X16(x,y,"7");
- if(dt8==8)Display_ASCII8X16(x,y,"8");
- if(dt8==9)Display_ASCII8X16(x,y,"9");
- if(dt8==0)Display_ASCII8X16(x,y,"0");
-
- if(dt7==1)Display_ASCII8X16(x+10,y,"1");
- if(dt7==2)Display_ASCII8X16(x+10,y,"2");
- if(dt7==3)Display_ASCII8X16(x+10,y,"3");
- if(dt7==4)Display_ASCII8X16(x+10,y,"4");
- if(dt7==5)Display_ASCII8X16(x+10,y,"5");
- if(dt7==6)Display_ASCII8X16(x+10,y,"6");
- if(dt7==7)Display_ASCII8X16(x+10,y,"7");
- if(dt7==8)Display_ASCII8X16(x+10,y,"8");
- if(dt7==9)Display_ASCII8X16(x+10,y,"9");
- if(dt7==0)Display_ASCII8X16(x+10,y,"0");
- if(dt6==1)Display_ASCII8X16(x+20,y,"1");
- if(dt6==2)Display_ASCII8X16(x+20,y,"2");
- if(dt6==3)Display_ASCII8X16(x+20,y,"3");
- if(dt6==4)Display_ASCII8X16(x+20,y,"4");
- if(dt6==5)Display_ASCII8X16(x+20,y,"5");
- if(dt6==6)Display_ASCII8X16(x+20,y,"6");
- if(dt6==7)Display_ASCII8X16(x+20,y,"7");
- if(dt6==8)Display_ASCII8X16(x+20,y,"8");
- if(dt6==9)Display_ASCII8X16(x+20,y,"9");
- if(dt6==0)Display_ASCII8X16(x+20,y,"0");
- if(dt5==1)Display_ASCII8X16(x+30,y,"1");
- if(dt5==2)Display_ASCII8X16(x+30,y,"2");
- if(dt5==3)Display_ASCII8X16(x+30,y,"3");
- if(dt5==4)Display_ASCII8X16(x+30,y,"4");
- if(dt5==5)Display_ASCII8X16(x+30,y,"5");
- if(dt5==6)Display_ASCII8X16(x+30,y,"6");
- if(dt5==7)Display_ASCII8X16(x+30,y,"7");
- if(dt5==8)Display_ASCII8X16(x+30,y,"8");
- if(dt5==9)Display_ASCII8X16(x+30,y,"9");
- if(dt5==0)Display_ASCII8X16(x+30,y,"0");
- //Display_ASCII8X16(x+40,y,".");
- if(dt4==1)Display_ASCII8X16(x+40,y,"1");
- if(dt4==2)Display_ASCII8X16(x+40,y,"2");
- if(dt4==3)Display_ASCII8X16(x+40,y,"3");
- if(dt4==4)Display_ASCII8X16(x+40,y,"4");
- if(dt4==5)Display_ASCII8X16(x+40,y,"5");
- if(dt4==6)Display_ASCII8X16(x+40,y,"6");
- if(dt4==7)Display_ASCII8X16(x+40,y,"7");
- if(dt4==8)Display_ASCII8X16(x+40,y,"8");
- if(dt4==9)Display_ASCII8X16(x+40,y,"9");
- if(dt4==0)Display_ASCII8X16(x+40,y,"0");
- if(dt3==1)Display_ASCII8X16(x+50,y,"1");
- if(dt3==2)Display_ASCII8X16(x+50,y,"2");
- if(dt3==3)Display_ASCII8X16(x+50,y,"3");
- if(dt3==4)Display_ASCII8X16(x+50,y,"4");
- if(dt3==5)Display_ASCII8X16(x+50,y,"5");
- if(dt3==6)Display_ASCII8X16(x+50,y,"6");
- if(dt3==7)Display_ASCII8X16(x+50,y,"7");
- if(dt3==8)Display_ASCII8X16(x+50,y,"8");
- if(dt3==9)Display_ASCII8X16(x+50,y,"9");
- if(dt3==0)Display_ASCII8X16(x+50,y,"0");
-
- if(dt2==1)Display_ASCII8X16(x+60,y,"1");
- if(dt2==2)Display_ASCII8X16(x+60,y,"2");
- if(dt2==3)Display_ASCII8X16(x+60,y,"3");
- if(dt2==4)Display_ASCII8X16(x+60,y,"4");
- if(dt2==5)Display_ASCII8X16(x+60,y,"5");
- if(dt2==6)Display_ASCII8X16(x+60,y,"6");
- if(dt2==7)Display_ASCII8X16(x+60,y,"7");
- if(dt2==8)Display_ASCII8X16(x+60,y,"8");
- if(dt2==9)Display_ASCII8X16(x+60,y,"9");
- if(dt2==0)Display_ASCII8X16(x+60,y,"0");
- if(dt1==1)Display_ASCII8X16(x+70,y,"1");
- if(dt1==2)Display_ASCII8X16(x+70,y,"2");
- if(dt1==3)Display_ASCII8X16(x+70,y,"3");
- if(dt1==4)Display_ASCII8X16(x+70,y,"4");
- if(dt1==5)Display_ASCII8X16(x+70,y,"5");
- if(dt1==6)Display_ASCII8X16(x+70,y,"6");
- if(dt1==7)Display_ASCII8X16(x+70,y,"7");
- if(dt1==8)Display_ASCII8X16(x+70,y,"8");
- if(dt1==9)Display_ASCII8X16(x+70,y,"9");
- if(dt1==0)Display_ASCII8X16(x+70,y,"0");
-
- Display_ASCII8X16(x+80,y,"S");
-
- delay_ms(3000);//数据刷新频率
- Lcd_SetRegion(x,y,x+78,y+14); //(X1,Y1,X2,Y2)X1行开始、 X2行结束 、Y1列开始、 Y2列结束
- for (i=0;i<35;i++) //数据刷新频率
- for (j=0;j<40;j++) //数据刷新频率
- LCD_WriteData_16Bit(RED);// 字体区清除后色
- /*
- //定义常用颜色
- #define RED 0xf800
- #define GREEN 0x07e0
- #define BLUE 0x001f
- #define WHITE 0xffff
- #define BLACK 0x0000
- #define YELLOW 0xFFE0
- #define GRAY0 0xEF7D
- #define GRAY1 0x8410
- #define GRAY2 0x4208
- */
- }
- void Display_ASCII8X16(uint x0,uint y0,uchar *s)
- {
- int i,j,k,x,y,xx;
-
- unsigned char qm;
-
- long int ulOffset;
-
- char ywbuf[32],temp[2];
- for(i = 0; i<strlen((char*)s);i++)
- {
- if(((unsigned char)(*(s+i))) >= 161)
- {
- temp[0] = *(s+i);
- temp[1] = '\0';
- return;
- }
-
- else
- {
- qm = *(s+i);
- ulOffset = (long int)(qm) * 16;
-
- for (j = 0; j < 16; j ++)
- {
- ywbuf[j]=Zk_ASCII8X16[ulOffset+j];
- }
-
- for(y = 0;y < 16;y++)
- {
- for(x=0;x<8;x++)
- {
- k=x % 8;
-
- if(ywbuf[y]&(0x80 >> k))
- {
- xx=x0+x+i*8;
- PutPixel(xx,y+y0,BLACK);//字色彩
- }
-
- }
- }
- }
- }
- }
- main()
- {
- TMOD=0X11;//定时器1 TMOD=0X11;方式1.
- TH1=(65536-50000)/256;//装初值
- TL1=(65536-50000)%256;//装初值
- EA=1;
- ET1=1;
- TR1=1;//定时器先关。等开关键启动
- #ifdef MCU_STC12
- P3M1 &= ~(1<<2), P3M0 |= (1<<2); //P3.2 set as push-pull output mode
- #endif
- lcd_initial();
- bl=1;
- dsp_single_colour(GREEN);//清屏色
- while(1)
- {
- Display_ASCII8X16(30,10,"(18b20)");
- Read_Temp();
- //delay_ms(1000);
-
- sec++;
- if(sec>9999){sec=0;}
- dsplay(wd());
- dsplay1();
-
- }
- }
- uchar code Zk_ASCII8X16[]=
- {
- 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,
-
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
STC12显1.44显温度ok3.zip
(89.88 KB, 下载次数: 60)
|