找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4967|回复: 7
收起左侧

STC12单片机驱动1.44寸彩屏显温度源程序(刷新太慢但能用)

[复制链接]
ID:358930 发表于 2018-11-14 18:29 | 显示全部楼层 |阅读模式
制作出来的1.44寸彩屏显示实物图如下:
20181114_181357.jpg 20181114_181258.jpg

单片机源程序如下:
  1. //////////////////////////////////////////////////////////////////////////////////         //本程序只供学习使用,未经作者许可,不得用于其它任何用途
  2. //测试硬件:STC12LE5A60S2
  3. //1.5寸TFT_ST7735液晶驱动
  4. //版本:V1.0
  5. //版权所有,盗版必究。
  6. //Copyright(C) 深圳市全动电子技术有限公司 2009-2019
  7. //All rights reserved
  8. //********************************************************************************
  9. //V1.1修改说明
  10. //加入横屏显示代码,直接在初始化中切换横竖屏模式
  11. //////////////////////////////////////////////////////////////////////////////////
  12. #include<reg51.h>
  13. #include<absacc.h>
  14. #include<intrins.h>
  15. #include<string.h>
  16. #define uchar unsigned char
  17. #define uint unsigned int


  18. //测试硬件平台:STC12C5A60S2/STC12LE5A60S2
  19. //主频:12MHZ
  20. //单片机IO推挽输出设置定义
  21. //#define USE_LANDSCAPE//测试程序横竖屏切换,横屏请开启此宏,竖屏请屏蔽
  22. #define MCU_STC12//如果您使用的单片机不是STC12系列(如STC89C52)请屏蔽此宏定义
  23. #ifdef MCU_STC12
  24. sfr P3M1  = 0xB1;        //P3M1.n,P3M0.n         =00--->Standard,        01--->push-pull
  25. sfr P3M0  = 0xB2;        //                                        =10--->pure input,        11--->open drain
  26. #endif


  27. //---------------------------液晶屏接线说明-------------------------------------//
  28. /*
  29. sbit bl        =P3^2;//接模块BL引脚,背光可以采用IO控制或者PWM控制,也可以直接接到高电平常亮
  30. sbit scl       =P1^7;//接模块CLK引脚,接裸屏Pin9_SCL
  31. sbit sda       =P1^5;//接模块DIN/MOSI引脚,接裸屏Pin8_SDA
  32. sbit rs        =P1^2;//接模块D/C引脚,接裸屏Pin7_A0
  33. sbit cs        =P1^3;//接模块CE引脚,接裸屏Pin12_CS
  34. sbit reset     =P3^3;//接模块RST引脚,接裸屏Pin6_RES
  35. */
  36. sbit sda       =P1^0;//接模块DI
  37. sbit scl       =P1^1;//接模块SC
  38. sbit cs        =P1^2;//接模块CS
  39. sbit reset     =P1^3;//接模块RST
  40. sbit rs        =P1^4;//接模块rs
  41. sbit bl        =P1^5;//接模块BLk
  42. //---------------------------End of液晶屏接线---------------------------------//

  43. //定义常用颜色
  44. #define RED                  0xf800
  45. #define GREEN                0x07e0
  46. #define BLUE                 0x001f
  47. #define WHITE                0xffff
  48. #define BLACK                0x0000
  49. #define YELLOW  0xFFE0
  50. #define GRAY0   0xEF7D   
  51. #define GRAY1   0x8410             
  52. #define GRAY2   0x4208   
  53. void  Contrast_Adjust();
  54. uchar code Zk_ASCII8X16[];
  55. uint sec,s;
  56. void Display_Desc();
  57. void Output_Pixel(uint x,uint y);
  58. void Display_ASCII8X16(uint x0,uint y0,uchar *s);

  59. void delay_ms(uint time)
  60. {
  61. uint i,j;
  62.   for(i=0;i<time;i++)
  63.    for(j=0;j<250;j++);
  64. }

  65. /************************************以上为DS18B20内容******************************************/
  66. /******************DS18B20温度***********************/
  67. sbit    DS18B20=P1^6;
  68. #define DS18B20_H {DS18B20=1;}
  69. #define DS18B20_L {DS18B20=0;}
  70. uchar DS18B20_V() {return DS18B20;}
  71. void  Read_Temp();
  72. uchar DS18B20_Reset();
  73. void  DS18B20_WriteData(unsigned char wData);
  74. uchar DS18B20_ReadData();
  75. uchar g=2;//STC12比STC8951快的倍数(只有1-2倍可用)
  76. /***************************18B20温度返回*******wd******************/
  77. uchar temperature[2];//定义一个整合数据
  78. long wd()
  79. {
  80.         unsigned char temp_data;
  81.         long wd=0;//温度值清0

  82.         temp_data = temperature[1];
  83.         temp_data &= 0xf0; //取高4位
  84.         if (temp_data==0xf0) //判断是正温度还是负温度读数
  85.         {
  86.                 //负温度读数求补,取反加1,判断低8位是否有进位
  87.                 if (temperature[0]==0)
  88.                 { //有进位,高8位取反加1
  89.                         temperature[0]=~temperature[0]+1;
  90.                         temperature[1]=~temperature[1]+1;
  91.                 }
  92.                 else
  93.                 { //没进位,高8位不加1
  94.                         temperature[0]=~temperature[0]+1;
  95.                         temperature[1]=~temperature[1];
  96.                 }
  97.         }
  98.         wd=(temperature[1]*256+temperature[0])*(0.0625*10000);
  99.         //wd=12345;
  100.         return wd;//返回一个数据(温度)用于显示       
  101. }
  102. /**********************读温度数据函数***********************************/
  103. void Read_Temp()
  104. {
  105.         unsigned char i;
  106.         DS18B20_Reset(); //复位
  107.         DS18B20_WriteData(0xcc); //跳过ROM命令
  108.         DS18B20_WriteData(0x44); //温度转换命令
  109.         DS18B20_Reset(); //复位
  110.         DS18B20_WriteData(0xcc); //跳过ROM命令
  111.         DS18B20_WriteData(0xbe); //读DS18B20温度暂存器命令
  112.         for (i=0;i<2;i++)
  113.         {
  114.                 temperature[i]=DS18B20_ReadData();
  115.         }
  116.         DS18B20_Reset(); //复位,结束读数据
  117. }
  118. /****************************DS18B20复位及存在检测******************************/
  119. uchar DS18B20_Reset()
  120. {
  121.         unsigned char i;
  122.         uchar flag; //DS18B20存在标志位
  123.         DS18B20_L; //拉低总线
  124.         for (i=(240*g);i>0;i--);//延时480微秒,产生复位脉冲
  125.         DS18B20_H; //释放总线
  126.         for (i=(40*g);i>0;i--); //延时80微秒对总线采样
  127.         flag = DS18B20_V();
  128.         for (i=(200*g);i>0;i--); //延时400微秒等待总线恢复
  129.         return (flag); //根据flag的值可以知道DS18B20是否存在或损坏
  130. } //可以加声音告警提示DS18B20故障
  131. /***********************写数据到DS18B20 ***********************************/
  132. void DS18B20_WriteData(unsigned char wData)
  133. {
  134.         unsigned char i,j;
  135.         for (i=8;i>0;i--)
  136.         {
  137.                 DS18B20_L; //拉低总线,产生写信号
  138.                 for (j=(7*g);j>0;j--); //延时14us
  139.                 if((bit)(wData&0x01)==1)//发送1位
  140.                 {
  141.                         DS18B20_H;
  142.                 }
  143.                 else
  144.                 {
  145.                         DS18B20_L;
  146.                 }

  147.                 for (j=(30*g);j>0;j--); //延时60us,写时序至少要60us
  148.                 DS18B20_H; //释放总线,等待总线恢复
  149.                 wData>>=1; //准备下一位数据的传送
  150.         }
  151. }
  152. /************************DS18B20中读出数据**********************************/
  153. unsigned char DS18B20_ReadData()
  154. {
  155.         unsigned char i,j,TmepData;
  156.         for (i=8;i>0;i--)
  157.         {
  158.                 TmepData>>=1;
  159.                 DS18B20_L; //拉低总线,产生读信号
  160.                 for (j=(2*g);j>0;j--); //延时4us
  161.                 DS18B20_H; //释放总线,准备读数据
  162.                 for (j=(4*g);j>0;j--); //延时8微秒读数据
  163.                 if (DS18B20_V()) TmepData |= 0x80;
  164.                 for (j=(15*g);j>0;j--); //延时30us
  165.                 DS18B20_H; //拉高总线,准备下一位数据的读取.
  166.         }
  167.         return (TmepData);//返回读到的数据
  168. }
  169. //向SPI总线传输一个8位数据
  170. void  SPI_WriteData(uchar Data)
  171. {
  172.         unsigned char i=0;
  173.         for(i=8;i>0;i--)
  174.         {
  175.                 if(Data&0x80)       
  176.                 sda=1; //输出数据
  177.                 else sda=0;
  178.                 scl=0;
  179.                 scl=1;
  180.                 Data<<=1;
  181.         }
  182. }
  183. //向液晶屏写一个8位指令
  184. void  Lcd_WriteIndex(uchar Data)
  185. {
  186.                
  187.                 cs=0;
  188.                 rs=0;
  189.                 SPI_WriteData(Data);                
  190.                 cs=1;
  191. }
  192. //向液晶屏写一个8位数据
  193. void  Lcd_WriteData(uchar Data)
  194. {       
  195.                 unsigned char i=0;
  196.                 cs=0;
  197.                 rs=1;
  198.                 SPI_WriteData(Data);        
  199.                 cs=1;
  200. }
  201. //向液晶屏写一个16位数据
  202. void  LCD_WriteData_16Bit(unsigned int Data)
  203. {
  204.         unsigned char i=0;
  205.         cs=0;
  206.         rs=1;
  207.         SPI_WriteData(Data>>8);         //写入高8位数据
  208.         SPI_WriteData(Data);                         //写入低8位数据
  209.         cs=1;

  210. }

  211. void Reset()
  212. {
  213.     reset=0;
  214.     delay_ms(100);
  215.     reset=1;
  216.     delay_ms(100);
  217. }
  218. //////////////////////////////////////////////////////////////////////////////////////////////
  219. //液晶屏初始化 for S6D02A1
  220. void lcd_initial()
  221. {        Reset();//Reset before LCD Init.
  222.                
  223.         //LCD Init For 1.44Inch LCD Panel with ST7735R.
  224.         Lcd_WriteIndex(0x11);//Sleep exit
  225.         delay_ms (120);
  226.                
  227.         //ST7735R Frame Rate
  228.         Lcd_WriteIndex(0xB1);
  229.         Lcd_WriteData(0x01);
  230.         Lcd_WriteData(0x2C);
  231.         Lcd_WriteData(0x2D);

  232.         Lcd_WriteIndex(0xB2);
  233.         Lcd_WriteData(0x01);
  234.         Lcd_WriteData(0x2C);
  235.         Lcd_WriteData(0x2D);

  236.         Lcd_WriteIndex(0xB3);
  237.         Lcd_WriteData(0x01);
  238.         Lcd_WriteData(0x2C);
  239.         Lcd_WriteData(0x2D);
  240.         Lcd_WriteData(0x01);
  241.         Lcd_WriteData(0x2C);
  242.         Lcd_WriteData(0x2D);
  243.        
  244.         Lcd_WriteIndex(0xB4); //Column inversion
  245.         Lcd_WriteData(0x07);
  246.        
  247.         //ST7735R Power Sequence
  248.         Lcd_WriteIndex(0xC0);
  249.         Lcd_WriteData(0xA2);
  250.         Lcd_WriteData(0x02);
  251.         Lcd_WriteData(0x84);
  252.         Lcd_WriteIndex(0xC1);
  253.         Lcd_WriteData(0xC5);

  254.         Lcd_WriteIndex(0xC2);
  255.         Lcd_WriteData(0x0A);
  256.         Lcd_WriteData(0x00);

  257.         Lcd_WriteIndex(0xC3);
  258.         Lcd_WriteData(0x8A);
  259.         Lcd_WriteData(0x2A);
  260.         Lcd_WriteIndex(0xC4);
  261.         Lcd_WriteData(0x8A);
  262.         Lcd_WriteData(0xEE);
  263.        
  264.         Lcd_WriteIndex(0xC5); //VCOM
  265.         Lcd_WriteData(0x0E);
  266.        
  267.         Lcd_WriteIndex(0x36); //MX, MY, RGB mode
  268. #ifdef USE_LANDSCAPE
  269.         Lcd_WriteData(0xA8); //竖屏C8 横屏08 A8
  270. #else
  271.         Lcd_WriteData(0xC8); //竖屏C8 横屏08 A8
  272. #endif               
  273.         //ST7735R Gamma Sequence
  274.         Lcd_WriteIndex(0xe0);
  275.         Lcd_WriteData(0x0f);
  276.         Lcd_WriteData(0x1a);
  277.         Lcd_WriteData(0x0f);
  278.         Lcd_WriteData(0x18);
  279.         Lcd_WriteData(0x2f);
  280.         Lcd_WriteData(0x28);
  281.         Lcd_WriteData(0x20);
  282.         Lcd_WriteData(0x22);
  283.         Lcd_WriteData(0x1f);
  284.         Lcd_WriteData(0x1b);
  285.         Lcd_WriteData(0x23);
  286.         Lcd_WriteData(0x37);
  287.         Lcd_WriteData(0x00);        
  288.         Lcd_WriteData(0x07);
  289.         Lcd_WriteData(0x02);
  290.         Lcd_WriteData(0x10);

  291.         Lcd_WriteIndex(0xe1);
  292.         Lcd_WriteData(0x0f);
  293.         Lcd_WriteData(0x1b);
  294.         Lcd_WriteData(0x0f);
  295.         Lcd_WriteData(0x17);
  296.         Lcd_WriteData(0x33);
  297.         Lcd_WriteData(0x2c);
  298.         Lcd_WriteData(0x29);
  299.         Lcd_WriteData(0x2e);
  300.         Lcd_WriteData(0x30);
  301.         Lcd_WriteData(0x30);
  302.         Lcd_WriteData(0x39);
  303.         Lcd_WriteData(0x3f);
  304.         Lcd_WriteData(0x00);
  305.         Lcd_WriteData(0x07);
  306.         Lcd_WriteData(0x03);
  307.         Lcd_WriteData(0x10);  
  308.        
  309.         Lcd_WriteIndex(0x2a);
  310.         Lcd_WriteData(0x00);
  311.         Lcd_WriteData(0x00+2);
  312.         Lcd_WriteData(0x00);
  313.         Lcd_WriteData(0x80+2);

  314.         Lcd_WriteIndex(0x2b);
  315.         Lcd_WriteData(0x00);
  316.         Lcd_WriteData(0x00+3);
  317.         Lcd_WriteData(0x00);
  318.         Lcd_WriteData(0x80+3);
  319.        
  320.         Lcd_WriteIndex(0xF0); //Enable test command  
  321.         Lcd_WriteData(0x01);
  322.         Lcd_WriteIndex(0xF6); //Disable ram power save mode
  323.         Lcd_WriteData(0x00);
  324.        
  325.         Lcd_WriteIndex(0x3A); //65k mode
  326.         Lcd_WriteData(0x05);
  327.        
  328.        
  329.         Lcd_WriteIndex(0x29);//Display on

  330. }



  331. /*************************************************
  332. 函数名:LCD_Set_Region
  333. 功能:设置lcd显示区域,在此区域写点数据自动换行
  334. 入口参数:xy起点和终点
  335. 返回值:无
  336. *************************************************/
  337. void Lcd_SetRegion(unsigned int x_start,unsigned int y_start,unsigned int x_end,unsigned int y_end)
  338. {       
  339. #ifdef USE_LANDSCAPE//使用横屏模式
  340.         Lcd_WriteIndex(0x2a);
  341.         Lcd_WriteData(0x00);
  342.         Lcd_WriteData(x_start+3);
  343.         Lcd_WriteData(0x00);
  344.         Lcd_WriteData(x_end+3);

  345.         Lcd_WriteIndex(0x2b);
  346.         Lcd_WriteData(0x00);
  347.         Lcd_WriteData(y_start+2);
  348.         Lcd_WriteData(0x00);
  349.         Lcd_WriteData(y_end+2);

  350. #else//竖屏模式       
  351.         Lcd_WriteIndex(0x2a);
  352.         Lcd_WriteData(0x00);
  353.         Lcd_WriteData(x_start+2);
  354.         Lcd_WriteData(0x00);
  355.         Lcd_WriteData(x_end+2);

  356.         Lcd_WriteIndex(0x2b);
  357.         Lcd_WriteData(0x00);
  358.         Lcd_WriteData(y_start+3);
  359.         Lcd_WriteData(0x00);
  360.         Lcd_WriteData(y_end+3);       
  361. #endif
  362.         Lcd_WriteIndex(0x2c);
  363. }


  364. void PutPixel(uint x_start,uint y_start,uint color)
  365. {
  366.         Lcd_SetRegion(x_start,y_start,x_start+1,y_start+1);
  367.         LCD_WriteData_16Bit(color);
  368.        
  369. }



  370. void dsp_single_colour(int color) //清屏写入颜色
  371. {
  372.         uchar i,j;
  373.         Lcd_SetRegion(0,0,128-1,128-1);
  374.         for (i=0;i<128;i++)
  375.             for (j=0;j<128;j++)
  376.                 LCD_WriteData_16Bit(color);
  377. }
  378. /************************数据处理显示2************************************/
  379. void dsplay(long temp)         //uint uchar 位数不足 long长数据
  380. {         uchar i,j;
  381.          uchar x=20,y=60;
  382.     uchar dt1,dt2,dt3,dt4,dt5,dt6,dt7,dt8;
  383.         dt1 = temp%10;//1位
  384.         dt2 = temp%100/10;//2位
  385.         dt3 = temp%1000/100;//3位
  386.         dt4 = temp%10000/1000;//4位

  387.         dt5 = temp%100000/10000;//5位
  388.         dt6 = temp%1000000/100000;//6位
  389.         dt7 = temp%10000000/1000000;//7位
  390.         dt8 = temp/10000000;//8位             最高位  
  391.      
  392.         Display_ASCII8X16(2,y,"WD: ");
  393.          
  394.    /*
  395.          if(dt8==1)Display_ASCII8X16(x,y,"1");
  396.      if(dt8==2)Display_ASCII8X16(x,y,"2");
  397.          if(dt8==3)Display_ASCII8X16(x,y,"3");
  398.      if(dt8==4)Display_ASCII8X16(x,y,"4");
  399.          if(dt8==5)Display_ASCII8X16(x,y,"5");
  400.      if(dt8==6)Display_ASCII8X16(x,y,"6");
  401.          if(dt8==7)Display_ASCII8X16(x,y,"7");
  402.      if(dt8==8)Display_ASCII8X16(x,y,"8");
  403.          if(dt8==9)Display_ASCII8X16(x,y,"9");
  404.      if(dt8==0)Display_ASCII8X16(x,y,"0");
  405.    */
  406.          if(dt7==1)Display_ASCII8X16(x+10,y,"1");
  407.      if(dt7==2)Display_ASCII8X16(x+10,y,"2");
  408.          if(dt7==3)Display_ASCII8X16(x+10,y,"3");
  409.      if(dt7==4)Display_ASCII8X16(x+10,y,"4");
  410.          if(dt7==5)Display_ASCII8X16(x+10,y,"5");
  411.      if(dt7==6)Display_ASCII8X16(x+10,y,"6");
  412.          if(dt7==7)Display_ASCII8X16(x+10,y,"7");
  413.      if(dt7==8)Display_ASCII8X16(x+10,y,"8");
  414.          if(dt7==9)Display_ASCII8X16(x+10,y,"9");
  415.      if(dt7==0)Display_ASCII8X16(x+10,y,"0");

  416.      if(dt6==1)Display_ASCII8X16(x+20,y,"1");
  417.      if(dt6==2)Display_ASCII8X16(x+20,y,"2");
  418.          if(dt6==3)Display_ASCII8X16(x+20,y,"3");
  419.      if(dt6==4)Display_ASCII8X16(x+20,y,"4");
  420.          if(dt6==5)Display_ASCII8X16(x+20,y,"5");
  421.      if(dt6==6)Display_ASCII8X16(x+20,y,"6");
  422.          if(dt6==7)Display_ASCII8X16(x+20,y,"7");
  423.      if(dt6==8)Display_ASCII8X16(x+20,y,"8");
  424.          if(dt6==9)Display_ASCII8X16(x+20,y,"9");
  425.      if(dt6==0)Display_ASCII8X16(x+20,y,"0");

  426.          if(dt5==1)Display_ASCII8X16(x+30,y,"1");
  427.      if(dt5==2)Display_ASCII8X16(x+30,y,"2");
  428.          if(dt5==3)Display_ASCII8X16(x+30,y,"3");
  429.      if(dt5==4)Display_ASCII8X16(x+30,y,"4");
  430.          if(dt5==5)Display_ASCII8X16(x+30,y,"5");
  431.      if(dt5==6)Display_ASCII8X16(x+30,y,"6");
  432.          if(dt5==7)Display_ASCII8X16(x+30,y,"7");
  433.      if(dt5==8)Display_ASCII8X16(x+30,y,"8");
  434.          if(dt5==9)Display_ASCII8X16(x+30,y,"9");
  435.      if(dt5==0)Display_ASCII8X16(x+30,y,"0");


  436.          Display_ASCII8X16(x+40,y,".");

  437.          if(dt4==1)Display_ASCII8X16(x+50,y,"1");
  438.      if(dt4==2)Display_ASCII8X16(x+50,y,"2");
  439.          if(dt4==3)Display_ASCII8X16(x+50,y,"3");
  440.      if(dt4==4)Display_ASCII8X16(x+50,y,"4");
  441.          if(dt4==5)Display_ASCII8X16(x+50,y,"5");
  442.      if(dt4==6)Display_ASCII8X16(x+50,y,"6");
  443.          if(dt4==7)Display_ASCII8X16(x+50,y,"7");
  444.      if(dt4==8)Display_ASCII8X16(x+50,y,"8");
  445.          if(dt4==9)Display_ASCII8X16(x+50,y,"9");
  446.      if(dt4==0)Display_ASCII8X16(x+50,y,"0");

  447.          if(dt3==1)Display_ASCII8X16(x+60,y,"1");
  448.      if(dt3==2)Display_ASCII8X16(x+60,y,"2");
  449.          if(dt3==3)Display_ASCII8X16(x+60,y,"3");
  450.      if(dt3==4)Display_ASCII8X16(x+60,y,"4");
  451.          if(dt3==5)Display_ASCII8X16(x+60,y,"5");
  452.      if(dt3==6)Display_ASCII8X16(x+60,y,"6");
  453.          if(dt3==7)Display_ASCII8X16(x+60,y,"7");
  454.      if(dt3==8)Display_ASCII8X16(x+60,y,"8");
  455.          if(dt3==9)Display_ASCII8X16(x+60,y,"9");
  456.      if(dt3==0)Display_ASCII8X16(x+60,y,"0");
  457.         /*
  458.      if(dt2==1)Display_ASCII8X16(x+60,y,"1");
  459.      if(dt2==2)Display_ASCII8X16(x+60,y,"2");
  460.          if(dt2==3)Display_ASCII8X16(x+60,y,"3");
  461.      if(dt2==4)Display_ASCII8X16(x+60,y,"4");
  462.          if(dt2==5)Display_ASCII8X16(x+60,y,"5");
  463.      if(dt2==6)Display_ASCII8X16(x+60,y,"6");
  464.          if(dt2==7)Display_ASCII8X16(x+60,y,"7");
  465.      if(dt2==8)Display_ASCII8X16(x+60,y,"8");
  466.          if(dt2==9)Display_ASCII8X16(x+60,y,"9");
  467.      if(dt2==0)Display_ASCII8X16(x+60,y,"0");

  468.          if(dt1==1)Display_ASCII8X16(x+70,y,"1");
  469.      if(dt1==2)Display_ASCII8X16(x+70,y,"2");
  470.          if(dt1==3)Display_ASCII8X16(x+70,y,"3");
  471.      if(dt1==4)Display_ASCII8X16(x+70,y,"4");
  472.          if(dt1==5)Display_ASCII8X16(x+70,y,"5");
  473.      if(dt1==6)Display_ASCII8X16(x+70,y,"6");
  474.          if(dt1==7)Display_ASCII8X16(x+70,y,"7");
  475.      if(dt1==8)Display_ASCII8X16(x+70,y,"8");
  476.          if(dt1==9)Display_ASCII8X16(x+70,y,"9");
  477.      if(dt1==0)Display_ASCII8X16(x+70,y,"0");
  478.    */
  479.         Display_ASCII8X16(x+70,y,"C");
  480.        
  481.         delay_ms(3000);//数据刷新频率
  482.         Lcd_SetRegion(x+9,y,x+68,y+14);         //(X1,Y1,X2,Y2)X1行开始、 X2行结束        、Y1列开始、 Y2列结束
  483.         for (i=0;i<28;i++) //数据刷新频率
  484.       for (j=0;j<35;j++) //数据刷新频率
  485.                 LCD_WriteData_16Bit(RED);//  字体区清除后色

  486. /*
  487.          //定义常用颜色
  488. #define RED                  0xf800
  489. #define GREEN                0x07e0
  490. #define BLUE                 0x001f
  491. #define WHITE                0xffff
  492. #define BLACK                0x0000
  493. #define YELLOW  0xFFE0
  494. #define GRAY0   0xEF7D   
  495. #define GRAY1   0x8410             
  496. #define GRAY2   0x4208
  497. */

  498.         }
  499. /************************数据处理显示2************************************/
  500. void dsplay1(long temp)         //uint uchar 位数不足 long长数据
  501. {         uchar i,j;
  502.          uchar x=33,y=80;
  503.     uchar dt1,dt2,dt3,dt4,dt5,dt6,dt7,dt8;
  504.         temp=sec;
  505.         dt1 = temp%10;//1位
  506.         dt2 = temp%100/10;//2位
  507.         dt3 = temp%1000/100;//3位
  508.         dt4 = temp%10000/1000;//4位

  509.         dt5 = temp%100000/10000;//5位
  510.         dt6 = temp%1000000/100000;//6位
  511.         dt7 = temp%10000000/1000000;//7位
  512.         dt8 = temp/10000000;//8位             最高位  
  513.      
  514.         Display_ASCII8X16(2,y,"SEC: ");
  515.          
  516.    
  517.          if(dt8==1)Display_ASCII8X16(x,y,"1");
  518.      if(dt8==2)Display_ASCII8X16(x,y,"2");
  519.          if(dt8==3)Display_ASCII8X16(x,y,"3");
  520.      if(dt8==4)Display_ASCII8X16(x,y,"4");
  521.          if(dt8==5)Display_ASCII8X16(x,y,"5");
  522.      if(dt8==6)Display_ASCII8X16(x,y,"6");
  523.          if(dt8==7)Display_ASCII8X16(x,y,"7");
  524.      if(dt8==8)Display_ASCII8X16(x,y,"8");
  525.          if(dt8==9)Display_ASCII8X16(x,y,"9");
  526.      if(dt8==0)Display_ASCII8X16(x,y,"0");
  527.    
  528.          if(dt7==1)Display_ASCII8X16(x+10,y,"1");
  529.      if(dt7==2)Display_ASCII8X16(x+10,y,"2");
  530.          if(dt7==3)Display_ASCII8X16(x+10,y,"3");
  531.      if(dt7==4)Display_ASCII8X16(x+10,y,"4");
  532.          if(dt7==5)Display_ASCII8X16(x+10,y,"5");
  533.      if(dt7==6)Display_ASCII8X16(x+10,y,"6");
  534.          if(dt7==7)Display_ASCII8X16(x+10,y,"7");
  535.      if(dt7==8)Display_ASCII8X16(x+10,y,"8");
  536.          if(dt7==9)Display_ASCII8X16(x+10,y,"9");
  537.      if(dt7==0)Display_ASCII8X16(x+10,y,"0");

  538.      if(dt6==1)Display_ASCII8X16(x+20,y,"1");
  539.      if(dt6==2)Display_ASCII8X16(x+20,y,"2");
  540.          if(dt6==3)Display_ASCII8X16(x+20,y,"3");
  541.      if(dt6==4)Display_ASCII8X16(x+20,y,"4");
  542.          if(dt6==5)Display_ASCII8X16(x+20,y,"5");
  543.      if(dt6==6)Display_ASCII8X16(x+20,y,"6");
  544.          if(dt6==7)Display_ASCII8X16(x+20,y,"7");
  545.      if(dt6==8)Display_ASCII8X16(x+20,y,"8");
  546.          if(dt6==9)Display_ASCII8X16(x+20,y,"9");
  547.      if(dt6==0)Display_ASCII8X16(x+20,y,"0");

  548.          if(dt5==1)Display_ASCII8X16(x+30,y,"1");
  549.      if(dt5==2)Display_ASCII8X16(x+30,y,"2");
  550.          if(dt5==3)Display_ASCII8X16(x+30,y,"3");
  551.      if(dt5==4)Display_ASCII8X16(x+30,y,"4");
  552.          if(dt5==5)Display_ASCII8X16(x+30,y,"5");
  553.      if(dt5==6)Display_ASCII8X16(x+30,y,"6");
  554.          if(dt5==7)Display_ASCII8X16(x+30,y,"7");
  555.      if(dt5==8)Display_ASCII8X16(x+30,y,"8");
  556.          if(dt5==9)Display_ASCII8X16(x+30,y,"9");
  557.      if(dt5==0)Display_ASCII8X16(x+30,y,"0");


  558.          //Display_ASCII8X16(x+40,y,".");

  559.          if(dt4==1)Display_ASCII8X16(x+40,y,"1");
  560.      if(dt4==2)Display_ASCII8X16(x+40,y,"2");
  561.          if(dt4==3)Display_ASCII8X16(x+40,y,"3");
  562.      if(dt4==4)Display_ASCII8X16(x+40,y,"4");
  563.          if(dt4==5)Display_ASCII8X16(x+40,y,"5");
  564.      if(dt4==6)Display_ASCII8X16(x+40,y,"6");
  565.          if(dt4==7)Display_ASCII8X16(x+40,y,"7");
  566.      if(dt4==8)Display_ASCII8X16(x+40,y,"8");
  567.          if(dt4==9)Display_ASCII8X16(x+40,y,"9");
  568.      if(dt4==0)Display_ASCII8X16(x+40,y,"0");

  569.          if(dt3==1)Display_ASCII8X16(x+50,y,"1");
  570.      if(dt3==2)Display_ASCII8X16(x+50,y,"2");
  571.          if(dt3==3)Display_ASCII8X16(x+50,y,"3");
  572.      if(dt3==4)Display_ASCII8X16(x+50,y,"4");
  573.          if(dt3==5)Display_ASCII8X16(x+50,y,"5");
  574.      if(dt3==6)Display_ASCII8X16(x+50,y,"6");
  575.          if(dt3==7)Display_ASCII8X16(x+50,y,"7");
  576.      if(dt3==8)Display_ASCII8X16(x+50,y,"8");
  577.          if(dt3==9)Display_ASCII8X16(x+50,y,"9");
  578.      if(dt3==0)Display_ASCII8X16(x+50,y,"0");
  579.        
  580.      if(dt2==1)Display_ASCII8X16(x+60,y,"1");
  581.      if(dt2==2)Display_ASCII8X16(x+60,y,"2");
  582.          if(dt2==3)Display_ASCII8X16(x+60,y,"3");
  583.      if(dt2==4)Display_ASCII8X16(x+60,y,"4");
  584.          if(dt2==5)Display_ASCII8X16(x+60,y,"5");
  585.      if(dt2==6)Display_ASCII8X16(x+60,y,"6");
  586.          if(dt2==7)Display_ASCII8X16(x+60,y,"7");
  587.      if(dt2==8)Display_ASCII8X16(x+60,y,"8");
  588.          if(dt2==9)Display_ASCII8X16(x+60,y,"9");
  589.      if(dt2==0)Display_ASCII8X16(x+60,y,"0");

  590.          if(dt1==1)Display_ASCII8X16(x+70,y,"1");
  591.      if(dt1==2)Display_ASCII8X16(x+70,y,"2");
  592.          if(dt1==3)Display_ASCII8X16(x+70,y,"3");
  593.      if(dt1==4)Display_ASCII8X16(x+70,y,"4");
  594.          if(dt1==5)Display_ASCII8X16(x+70,y,"5");
  595.      if(dt1==6)Display_ASCII8X16(x+70,y,"6");
  596.          if(dt1==7)Display_ASCII8X16(x+70,y,"7");
  597.      if(dt1==8)Display_ASCII8X16(x+70,y,"8");
  598.          if(dt1==9)Display_ASCII8X16(x+70,y,"9");
  599.      if(dt1==0)Display_ASCII8X16(x+70,y,"0");
  600.    
  601.         Display_ASCII8X16(x+80,y,"S");
  602.        
  603.         delay_ms(3000);//数据刷新频率
  604.         Lcd_SetRegion(x,y,x+78,y+14);         //(X1,Y1,X2,Y2)X1行开始、 X2行结束        、Y1列开始、 Y2列结束
  605.         for (i=0;i<35;i++) //数据刷新频率
  606.       for (j=0;j<40;j++) //数据刷新频率
  607.                 LCD_WriteData_16Bit(RED);//  字体区清除后色

  608. /*
  609.          //定义常用颜色
  610. #define RED                  0xf800
  611. #define GREEN                0x07e0
  612. #define BLUE                 0x001f
  613. #define WHITE                0xffff
  614. #define BLACK                0x0000
  615. #define YELLOW  0xFFE0
  616. #define GRAY0   0xEF7D   
  617. #define GRAY1   0x8410             
  618. #define GRAY2   0x4208
  619. */

  620.         }
  621. void Display_ASCII8X16(uint x0,uint y0,uchar *s)
  622. {
  623.         int i,j,k,x,y,xx;
  624.        
  625.         unsigned char qm;
  626.        
  627.         long int ulOffset;
  628.        
  629.         char  ywbuf[32],temp[2];

  630.         for(i = 0; i<strlen((char*)s);i++)
  631.         {
  632.                 if(((unsigned char)(*(s+i))) >= 161)
  633.                 {
  634.                         temp[0] = *(s+i);
  635.                         temp[1] = '\0';
  636.                         return;
  637.                 }
  638.                
  639.                 else
  640.                 {
  641.                         qm = *(s+i);

  642.                         ulOffset = (long int)(qm) * 16;
  643.                        
  644.       for (j = 0; j < 16; j ++)
  645.       {
  646.                                 ywbuf[j]=Zk_ASCII8X16[ulOffset+j];
  647.       }
  648.             
  649.       for(y = 0;y < 16;y++)
  650.       {
  651.                 for(x=0;x<8;x++)
  652.                 {
  653.              k=x % 8;
  654.                        
  655.                                           if(ywbuf[y]&(0x80 >> k))
  656.                                            {
  657.                                                   xx=x0+x+i*8;
  658.                                             PutPixel(xx,y+y0,BLACK);//字色彩
  659.                                           }
  660.                                                        
  661.                                    }
  662.       }

  663.                 }
  664.         }            
  665. }


  666. main()
  667. {

  668.     TMOD=0X11;//定时器1   TMOD=0X11;方式1.
  669.         TH1=(65536-50000)/256;//装初值
  670.         TL1=(65536-50000)%256;//装初值
  671.         EA=1;
  672.         ET1=1;
  673.         TR1=1;//定时器先关。等开关键启动

  674. #ifdef MCU_STC12
  675.         P3M1 &= ~(1<<2),        P3M0 |=  (1<<2);        //P3.2 set as push-pull output mode
  676. #endif
  677.         lcd_initial();
  678.         bl=1;
  679.         dsp_single_colour(GREEN);//清屏色
  680.   while(1)
  681.   {
  682.         Display_ASCII8X16(30,10,"(18b20)");
  683.         Read_Temp();
  684.         //delay_ms(1000);
  685.        
  686.         sec++;
  687.         if(sec>9999){sec=0;}
  688.                 dsplay(wd());
  689.                 dsplay1();
  690.                        
  691.     }
  692. }

  693. uchar code Zk_ASCII8X16[]=
  694. {
  695.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  696.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  697.   
  698. ……………………

  699. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
STC12显1.44显温度ok3.zip (89.88 KB, 下载次数: 58)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:358930 发表于 2018-11-14 18:36 | 显示全部楼层
求一个相关参考,还是就一定要STM32才能行。
回复

使用道具 举报

ID:358930 发表于 2018-11-14 18:46 来自手机 | 显示全部楼层
冰冰洁洁 发表于 2018-11-14 18:36
求一个相关参考,还是就一定要STM32才能行。

这是自学单片机写的,从没有老师指导过,写的有点搞笑的N多if,不过这是一年前的事了,进入51黑相信一切会好起来。我几乎拆过我能拆的所有东西………求名师

评分

参与人数 1黑币 +20 收起 理由
admin + 20 回帖助人的奖励!

查看全部评分

回复

使用道具 举报

ID:85865 发表于 2018-11-15 19:40 | 显示全部楼层
谢谢分享,参考了
回复

使用道具 举报

ID:264487 发表于 2019-5-9 18:23 | 显示全部楼层
厉害,谢谢分享
回复

使用道具 举报

ID:743654 发表于 2022-1-5 17:28 | 显示全部楼层
我也有一块类似的彩屏,显示实时时钟,貌似刷新速度不够,要6秒左右才刷新一次,怎么样才能提高刷新速度呢?
回复

使用道具 举报

ID:106977 发表于 2022-1-7 15:13 | 显示全部楼层
换STC8A8K64D4,工作时钟设置为44.2368MHz,显示速度大增!
回复

使用道具 举报

ID:93626 发表于 2022-12-5 08:03 | 显示全部楼层
谢谢分享,参考了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表