|
制作出來的1.44寸彩屏顯示實(shí)物圖如下:
20181114_181357.jpg (308.68 KB, 下載次數(shù): 58)
下載附件
2018-11-14 18:27 上傳
20181114_181258.jpg (312.5 KB, 下載次數(shù): 70)
下載附件
2018-11-14 18:27 上傳
單片機(jī)源程序如下:
- ////////////////////////////////////////////////////////////////////////////////// //本程序只供學(xué)習(xí)使用,未經(jīng)作者許可,不得用于其它任何用途
- //測(cè)試硬件:STC12LE5A60S2
- //1.5寸TFT_ST7735液晶驅(qū)動(dòng)
- //版本:V1.0
- //版權(quán)所有,盜版必究。
- //Copyright(C) 深圳市全動(dòng)電子技術(shù)有限公司 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
- //測(cè)試硬件平臺(tái):STC12C5A60S2/STC12LE5A60S2
- //主頻:12MHZ
- //單片機(jī)IO推挽輸出設(shè)置定義
- //#define USE_LANDSCAPE//測(cè)試程序橫豎屏切換,橫屏請(qǐng)開啟此宏,豎屏請(qǐng)屏蔽
- #define MCU_STC12//如果您使用的單片機(jī)不是STC12系列(如STC89C52)請(qǐng)屏蔽此宏定義
- #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內(nèi)容******************************************/
- /******************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快的倍數(shù)(只有1-2倍可用)
- /***************************18B20溫度返回*******wd******************/
- uchar temperature[2];//定義一個(gè)整合數(shù)據(jù)
- long wd()
- {
- unsigned char temp_data;
- long wd=0;//溫度值清0
- temp_data = temperature[1];
- temp_data &= 0xf0; //取高4位
- if (temp_data==0xf0) //判斷是正溫度還是負(fù)溫度讀數(shù)
- {
- //負(fù)溫度讀數(shù)求補(bǔ),取反加1,判斷低8位是否有進(jìn)位
- if (temperature[0]==0)
- { //有進(jìn)位,高8位取反加1
- temperature[0]=~temperature[0]+1;
- temperature[1]=~temperature[1]+1;
- }
- else
- { //沒進(jìn)位,高8位不加1
- temperature[0]=~temperature[0]+1;
- temperature[1]=~temperature[1];
- }
- }
- wd=(temperature[1]*256+temperature[0])*(0.0625*10000);
- //wd=12345;
- return wd;//返回一個(gè)數(shù)據(jù)(溫度)用于顯示
- }
- /**********************讀溫度數(shù)據(jù)函數(shù)***********************************/
- void Read_Temp()
- {
- unsigned char i;
- DS18B20_Reset(); //復(fù)位
- DS18B20_WriteData(0xcc); //跳過ROM命令
- DS18B20_WriteData(0x44); //溫度轉(zhuǎn)換命令
- DS18B20_Reset(); //復(fù)位
- DS18B20_WriteData(0xcc); //跳過ROM命令
- DS18B20_WriteData(0xbe); //讀DS18B20溫度暫存器命令
- for (i=0;i<2;i++)
- {
- temperature[i]=DS18B20_ReadData();
- }
- DS18B20_Reset(); //復(fù)位,結(jié)束讀數(shù)據(jù)
- }
- /****************************DS18B20復(fù)位及存在檢測(cè)******************************/
- uchar DS18B20_Reset()
- {
- unsigned char i;
- uchar flag; //DS18B20存在標(biāo)志位
- DS18B20_L; //拉低總線
- for (i=(240*g);i>0;i--);//延時(shí)480微秒,產(chǎn)生復(fù)位脈沖
- DS18B20_H; //釋放總線
- for (i=(40*g);i>0;i--); //延時(shí)80微秒對(duì)總線采樣
- flag = DS18B20_V();
- for (i=(200*g);i>0;i--); //延時(shí)400微秒等待總線恢復(fù)
- return (flag); //根據(jù)flag的值可以知道DS18B20是否存在或損壞
- } //可以加聲音告警提示DS18B20故障
- /***********************寫數(shù)據(jù)到DS18B20 ***********************************/
- void DS18B20_WriteData(unsigned char wData)
- {
- unsigned char i,j;
- for (i=8;i>0;i--)
- {
- DS18B20_L; //拉低總線,產(chǎn)生寫信號(hào)
- for (j=(7*g);j>0;j--); //延時(shí)14us
- if((bit)(wData&0x01)==1)//發(fā)送1位
- {
- DS18B20_H;
- }
- else
- {
- DS18B20_L;
- }
- for (j=(30*g);j>0;j--); //延時(shí)60us,寫時(shí)序至少要60us
- DS18B20_H; //釋放總線,等待總線恢復(fù)
- wData>>=1; //準(zhǔn)備下一位數(shù)據(jù)的傳送
- }
- }
- /************************DS18B20中讀出數(shù)據(jù)**********************************/
- unsigned char DS18B20_ReadData()
- {
- unsigned char i,j,TmepData;
- for (i=8;i>0;i--)
- {
- TmepData>>=1;
- DS18B20_L; //拉低總線,產(chǎn)生讀信號(hào)
- for (j=(2*g);j>0;j--); //延時(shí)4us
- DS18B20_H; //釋放總線,準(zhǔn)備讀數(shù)據(jù)
- for (j=(4*g);j>0;j--); //延時(shí)8微秒讀數(shù)據(jù)
- if (DS18B20_V()) TmepData |= 0x80;
- for (j=(15*g);j>0;j--); //延時(shí)30us
- DS18B20_H; //拉高總線,準(zhǔn)備下一位數(shù)據(jù)的讀取.
- }
- return (TmepData);//返回讀到的數(shù)據(jù)
- }
- //向SPI總線傳輸一個(gè)8位數(shù)據(jù)
- void SPI_WriteData(uchar Data)
- {
- unsigned char i=0;
- for(i=8;i>0;i--)
- {
- if(Data&0x80)
- sda=1; //輸出數(shù)據(jù)
- else sda=0;
- scl=0;
- scl=1;
- Data<<=1;
- }
- }
- //向液晶屏寫一個(gè)8位指令
- void Lcd_WriteIndex(uchar Data)
- {
-
- cs=0;
- rs=0;
- SPI_WriteData(Data);
- cs=1;
- }
- //向液晶屏寫一個(gè)8位數(shù)據(jù)
- void Lcd_WriteData(uchar Data)
- {
- unsigned char i=0;
- cs=0;
- rs=1;
- SPI_WriteData(Data);
- cs=1;
- }
- //向液晶屏寫一個(gè)16位數(shù)據(jù)
- void LCD_WriteData_16Bit(unsigned int Data)
- {
- unsigned char i=0;
- cs=0;
- rs=1;
- SPI_WriteData(Data>>8); //寫入高8位數(shù)據(jù)
- SPI_WriteData(Data); //寫入低8位數(shù)據(jù)
- 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
- }
- /*************************************************
- 函數(shù)名:LCD_Set_Region
- 功能:設(shè)置lcd顯示區(qū)域,在此區(qū)域?qū)扅c(diǎn)數(shù)據(jù)自動(dòng)換行
- 入口參數(shù):xy起點(diǎn)和終點(diǎn)
- 返回值:無
- *************************************************/
- 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);
- }
- /************************數(shù)據(jù)處理顯示2************************************/
- void dsplay(long temp) //uint uchar 位數(shù)不足 long長(zhǎng)數(shù)據(jù)
- { 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);//數(shù)據(jù)刷新頻率
- Lcd_SetRegion(x+9,y,x+68,y+14); //(X1,Y1,X2,Y2)X1行開始、 X2行結(jié)束 、Y1列開始、 Y2列結(jié)束
- for (i=0;i<28;i++) //數(shù)據(jù)刷新頻率
- for (j=0;j<35;j++) //數(shù)據(jù)刷新頻率
- LCD_WriteData_16Bit(RED);// 字體區(qū)清除后色
- /*
- //定義常用顏色
- #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
- */
- }
- /************************數(shù)據(jù)處理顯示2************************************/
- void dsplay1(long temp) //uint uchar 位數(shù)不足 long長(zhǎng)數(shù)據(jù)
- { 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);//數(shù)據(jù)刷新頻率
- Lcd_SetRegion(x,y,x+78,y+14); //(X1,Y1,X2,Y2)X1行開始、 X2行結(jié)束 、Y1列開始、 Y2列結(jié)束
- for (i=0;i<35;i++) //數(shù)據(jù)刷新頻率
- for (j=0;j<40;j++) //數(shù)據(jù)刷新頻率
- LCD_WriteData_16Bit(RED);// 字體區(qū)清除后色
- /*
- //定義常用顏色
- #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;//定時(shí)器1 TMOD=0X11;方式1.
- TH1=(65536-50000)/256;//裝初值
- TL1=(65536-50000)%256;//裝初值
- EA=1;
- ET1=1;
- TR1=1;//定時(shí)器先關(guān)。等開關(guān)鍵啟動(dòng)
- #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,
-
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
STC12顯1.44顯溫度ok3.zip
(89.88 KB, 下載次數(shù): 60)
2018-11-14 18:27 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|