[PIC®/AVR®/dsPIC®产品] PIC18F46K80板子驱动TN9

[复制链接]
1043|0
 楼主| 比神乐 发表于 2024-5-7 12:59 | 显示全部楼层 |阅读模式
代码:
  1. /******************************************************************************

  2. * 程序功能: 4脚I2C接口OLED演示例程
  3. * CPU型号 : PIC18F46K80
  4. * 系统时钟: 外部8M晶振经4xPLL倍频到32M
  5. * 开发环境: MPLAB X IDE V5.20
  6. * 编译软件: XC8 V1.41
  7. * 烧写工具: PICKIT3/KIT3.5   ICD3等        
  8. * 实验说明: 由于OLED不止一家生产的,每家生产的参数可能有所不同无法确保所有厂家的OLED都适用.
  9. *           如使用的是其他厂家的OLED无法显示时需要客户自行查找原因。
  10. *           我们也有OLED显示屏出售,直接适用于开发板并通过验证的,欢迎选购。
  11. * 作    者:博科电子
  12. * 更新日期:2021年12月5

  13. *****************************************************************************/

  14. #include <xc.h>
  15. #include "bmp.h"
  16. #include "oledfont.h"           

  17. //CONFIG1L
  18. #pragma config RETEN = OFF           // VREG Sleep Enable bit (Ultra low-power regulator is Disabled (Controlled by REGSLP bit)),禁止超低功耗稳压器
  19. #pragma config INTOSCSEL = HIGH      // LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power mode during Sleep),休眠期间 LF-INTOSC 处于高功耗模式
  20. #pragma config SOSCSEL = DIG         // SOSC Power Selection and mode Configuration bits (Digital (SCLKI) mode),SOSC 功耗选择和模式配置位,数字 ( SCLKI)模式;使能 RC0 和 RC1 的 I/O 端口功能
  21. #pragma config XINST = OFF           // Extended Instruction Set (Disabled),扩展指令集使能位,禁止指令集扩展和变址寻址模式 (传统模式)

  22. // CONFIG1H
  23. #pragma config FOSC = HS1            // Oscillator (HS oscillator (Medium power, 4 MHz - 16 MHz)),HS振荡器,中等功耗
  24. #pragma config PLLCFG = ON           // PLL x4 Enable bit (Enabled),打开PLL功能,系统时钟4倍频,变为32MHz
  25. #pragma config FCMEN = OFF           // Fail-Safe Clock Monitor (Disabled),禁止故障保护时钟监视器
  26. #pragma config IESO = OFF            // Internal External Oscillator Switch Over Mode (Disabled),禁止双速启动

  27. // CONFIG2L
  28. #pragma config PWRTEN = OFF         // Power Up Timer (Disabled),禁止上电延时定时器
  29. #pragma config BOREN = SBORDIS      // Brown Out Detect (Enabled in hardware, SBOREN disabled),只能由硬件使能欠压复位
  30. #pragma config BORV = 3             // Brown-out Reset Voltage bits (1.8V),欠压复位电压选择为1.8v
  31. #pragma config BORPWR = ZPBORMV     // BORMV Power level (ZPBORMV instead of BORMV is selected),选择ZPBORMV而不是BORMV

  32. // CONFIG2H
  33. #pragma config WDTEN = OFF          // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled),关闭看门狗功能
  34. //#pragma config WDTEN = SWDTDIS    // Watchdog Timer (WDT enabled in hardware; SWDTEN bit disabled),由硬件使能WDT,禁止SWDTEN位
  35. #pragma config WDTPS = 256          // Watchdog Postscaler (1:256),看门狗后分频1:256,溢出时间1.024s

  36. // CONFIG3H
  37. #pragma config CANMX = PORTB    // ECAN Mux bit (ECAN TX and RX pins are located on RB2 and RB3, respectively),1 = CANTX 和 CANRX 引脚分别位于 RB2 和 RB3 上
  38. #pragma config MSSPMSK = MSK7   // MSSP address masking (7 Bit address masking mode),1 = 使能 7 位地址掩码模式
  39. #pragma config MCLRE = ON       // Master Clear Enable (MCLR Enabled, RE3 Disabled),使能MCLR复位功能

  40. // CONFIG4L
  41. #pragma config STVREN = ON      // Stack Overflow Reset (Enabled),堆栈满/下溢导致复位
  42. #pragma config BBSIZ = BB2K     // Boot Block Size (2K word Boot Block size),引导区大小选择2K

  43. // CONFIG5L
  44. #pragma config CP0 = OFF        // Code Protect 00800-01FFF (Disabled),代码保护位
  45. #pragma config CP1 = OFF        // Code Protect 02000-03FFF (Disabled),代码保护位
  46. #pragma config CP2 = OFF        // Code Protect 04000-05FFF (Disabled),代码保护位
  47. #pragma config CP3 = OFF        // Code Protect 06000-07FFF (Disabled),代码保护位

  48. // CONFIG5H
  49. #pragma config CPB = OFF        // Code Protect Boot (Disabled),引导区不受代码保护
  50. #pragma config CPD = OFF        // Data EE Read Protect (Disabled),数据EEPROM不受代码保护

  51. // CONFIG6L
  52. #pragma config WRT0 = OFF       // Table Write Protect 00800-01FFF (Disabled),写保护位
  53. #pragma config WRT1 = OFF       // Table Write Protect 02000-03FFF (Disabled),写保护位
  54. #pragma config WRT2 = OFF       // Table Write Protect 04000-05FFF (Disabled),写保护位
  55. #pragma config WRT3 = OFF       // Table Write Protect 06000-07FFF (Disabled),写保护位

  56. // CONFIG6H
  57. #pragma config WRTC = OFF       // Config. Write Protect (Disabled),配置寄存器不受写保护
  58. #pragma config WRTB = OFF       // Table Write Protect Boot (Disabled),引导区不受写保护
  59. #pragma config WRTD = OFF       // Data EE Write Protect (Disabled),数据EEPROM不受写保护

  60. // CONFIG7L
  61. #pragma config EBTR0 = OFF      // Table Read Protect 00800-01FFF (Disabled),表读保护位
  62. #pragma config EBTR1 = OFF      // Table Read Protect 02000-03FFF (Disabled),表读保护位
  63. #pragma config EBTR2 = OFF      // Table Read Protect 04000-05FFF (Disabled),表读保护位
  64. #pragma config EBTR3 = OFF      // Table Read Protect 06000-07FFF (Disabled),表读保护位

  65. // CONFIG7H
  66. #pragma config EBTRB = OFF      // Table Read Protect Boot (Disabled),引导区不受写保护


  67. #define  u8 unsigned char
  68. #define  u16 unsigned int
  69. #define  u32 unsigned int
  70. #define uchar unsigned char

  71. //-----------------OLED定义----------------
  72. #define OLED_CMD  0        //写命令
  73. #define OLED_DATA 1        //写数据

  74. #define OLED_SCL     LATCbits.LATC3      //SCL接RC3
  75. #define OLED_SDA     LATCbits.LATC4      //SDA接RC4

  76. #define OLED_SCL_DIR_OUT  TRISC3=0;      //scl引脚配置为输出
  77. #define OLED_SDA_DIR_OUT  TRISC4=0;             //sda引脚配置为输出
  78.        
  79. #define OLED_SCL_Clr() OLED_SCL=0
  80. #define OLED_SCL_Set() OLED_SCL=1

  81. #define OLED_SDA_Clr() OLED_SDA=0
  82. #define OLED_SDA_Set() OLED_SDA=1

  83. //OLED控制用函数
  84. void delay_ms(unsigned int ms);
  85. void OLED_ColorTurn(u8 i);
  86. void OLED_DisplayTurn(u8 i);
  87. void OLED_WR_Byte(u8 dat,u8 cmd);
  88. void OLED_Set_Pos(u8 x, u8 y);
  89. //void OLED_Display_On(void);
  90. //void OLED_Display_Off(void);
  91. void OLED_Clear(void);
  92. void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 sizey);
  93. u32 oled_pow(u8 m,u8 n);
  94. void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 sizey);
  95. void OLED_ShowString(u8 x,u8 y,u8 *chr,u8 sizey);
  96. void OLED_ShowChinese(u8 x,u8 y,u8 no,u8 sizey);
  97. void OLED_DrawBMP(u8 x,u8 y,u8 sizex, u8 sizey,u8 BMP[]);
  98. void OLED_Init(void);

  99. void ACK_0() { RC0=0;}

  100. void ACK_1() { RC0=1;}







  101. #define DATA RC2



  102. #define CLOCK RC5







  103. float Temp;

  104. float Temp1,Temp2;

  105. unsigned char ReadData[5];

  106. //float  a,b;



  107. //-----------------------------------------------------------------------------------------

  108. //????:Delay()

  109. //?    ?:?????

  110. //-----------------------------------------------------------------------------------------

  111. void Delay(unsigned char us)

  112. {

  113.     uchar i;

  114.     while(--us)

  115.     {

  116.         for(i=0;i<50;i++);

  117.     }

  118. }



  119. //-----------------------------------------------------------------------------------------

  120. //????:Delayms()

  121. //-----------------------------------------------------------------------------------------

  122. void Delayms(unsigned int ims)

  123. {

  124.     unsigned int i,j;

  125.     for(i=0;i<ims;i++)

  126.          for(j=0;j<65;j++)

  127.          {

  128.             Delay(1);

  129.      }

  130. }

  131. void TN_IRACK_EN(void)

  132. {

  133.     ACK_0();

  134.     Delay(1);

  135. }





  136. void TN_IRACK_UN(void)

  137. {

  138.     ACK_1();

  139.     Delay(1);

  140. }





  141. void TN_ReadData(unsigned char Flag)

  142. {

  143.     unsigned char i,j,k,BitState=0;

  144.     for(k=0;k<7;k++)

  145.     {

  146.         for(j=0;j<5;j++)

  147.          {

  148.             for(i=0;i<8;i++)

  149.             {

  150.                 while(1)

  151.                 {

  152.                      if(CLOCK==0)

  153.                         break;

  154.                     Delay(1);

  155.                 }

  156.                 Delay(1);

  157.                 if(DATA==1)

  158.                      BitState=1;

  159.                 else

  160.                     BitState=0;

  161.                 ReadData[j]= ReadData[j]<<1;

  162.                 ReadData[j]= ReadData[j]|BitState;

  163.                 Delay(1);

  164.                 while(1)

  165.                 {

  166.                     if(CLOCK==1)

  167.                         break;

  168.                     Delay(1);

  169.                 }

  170.             }

  171.          }

  172.          if(ReadData[0]==Flag)

  173.             k=8;

  174.     }

  175.     TN_IRACK_UN();

  176. }

  177. float TN_GetData(unsigned char X)

  178. {



  179.     TN_ReadData(X);

  180.     Temp=(ReadData[1]<<8)|ReadData[2];

  181.     Temp=(float)Temp/16.00-273.15;

  182.     return Temp;

  183. }

  184. float TN_GetTemp(unsigned char mode)

  185. {



  186.     float T;



  187.     {

  188.          TN_IRACK_UN();

  189.             TN_IRACK_EN();

  190.          if(mode==0)

  191.          {

  192.             T=TN_GetData(0x4c);



  193.          }

  194.          else

  195.         {

  196.             T=TN_GetData(0x66);



  197.         }

  198.     }



  199.     return T;

  200. }

  201. void main(void)
  202. {       
  203.     uchar a,b,c,d;
  204.     u16 i,j;
  205.    
  206.     ANCON1=0x00;            //PORTB带模拟输入功能的引脚全部配置为数字IO
  207.     TRISC0=0;
  208.     TRISC2=1;
  209.     TRISC5=1;
  210.    
  211.         OLED_Init();//初始化OLED
  212.         OLED_ColorTurn(0);//0正常显示,1 反色显示
  213.     OLED_DisplayTurn(0);//0正常显示 1 屏幕翻转显示
  214.    
  215.     OLED_ShowChinese(0,0,7,16);//中
  216.     OLED_ShowChinese(18,0,8,16);//中
  217.     OLED_ShowChinese(36,0,11,16);//中
  218.     OLED_ShowChinese(54,0,12,16);//中
  219.    
  220.     OLED_ShowChinese(0,4,9,16);//中
  221.     OLED_ShowChinese(18,4,10,16);//中
  222.     OLED_ShowChinese(36,4,11,16);//中
  223.     OLED_ShowChinese(54,4,12,16);//中
  224.    
  225.         while(1)
  226.         {               
  227.                
  228.                 //OLED_Clear();
  229.                 Temp1=TN_GetTemp(0);
  230.         i=(u16)(Temp1*100);
  231.         a=(uchar)(i/1000);
  232.         b=(uchar)(i%1000/100);
  233.         c=(uchar)(i%100/10);
  234.         d=(uchar)(i%10);
  235.         OLED_ShowChar(76,0,a+48,16);
  236.         OLED_ShowChar(84,0,b+48,16);
  237.         OLED_ShowChar(92,0,'.',16);
  238.         OLED_ShowChar(100,0,c+48,16);
  239.         OLED_ShowChar(108,0,d+48,16);
  240.         Temp2=TN_GetTemp(1);  
  241.         j=(u16)(Temp2*100);
  242.         a=(uchar)(j/1000);
  243.         b=(uchar)(j%1000/100);
  244.         c=(uchar)(j%100/10);
  245.         d=(uchar)(j%10);
  246.         OLED_ShowChar(76,4,a+48,16);
  247.         OLED_ShowChar(84,4,b+48,16);
  248.         OLED_ShowChar(92,4,'.',16);
  249.         OLED_ShowChar(100,4,c+48,16);
  250.         OLED_ShowChar(108,4,d+48,16);
  251.                 delay_ms(2000);      
  252.                
  253.         }                 
  254. }


  255. void delay_ms(unsigned int ms)
  256. {                        
  257.         unsigned int a;
  258.         while(ms)
  259.         {
  260.                 a=1800;
  261.                 while(a--);
  262.                 ms--;
  263.         }
  264.         return;
  265. }


  266. //反显函数
  267. void OLED_ColorTurn(u8 i)
  268. {
  269.         if(i==0)
  270.                 {
  271.                         OLED_WR_Byte(0xA6,OLED_CMD);//正常显示
  272.                 }
  273.         if(i==1)
  274.                 {
  275.                         OLED_WR_Byte(0xA7,OLED_CMD);//反色显示
  276.                 }
  277. }


  278. //屏幕旋转180度
  279. void OLED_DisplayTurn(u8 i)
  280. {
  281.         if(i==0)
  282.                 {
  283.                         OLED_WR_Byte(0xC8,OLED_CMD);//正常显示
  284.                         OLED_WR_Byte(0xA1,OLED_CMD);
  285.                 }
  286.         if(i==1)
  287.                 {
  288.                         OLED_WR_Byte(0xC0,OLED_CMD);//反转显示
  289.                         OLED_WR_Byte(0xA0,OLED_CMD);
  290.                 }
  291. }



  292. //延时
  293. void IIC_delay(void)
  294. {
  295.         u8 t=1;
  296.         while(t--);
  297. }


  298. //起始信号
  299. void I2C_Start(void)
  300. {
  301.         OLED_SDA_Set();
  302.         OLED_SCL_Set();
  303.         IIC_delay();
  304.         OLED_SDA_Clr();
  305.         IIC_delay();
  306.         OLED_SCL_Clr();
  307.          
  308. }


  309. //结束信号
  310. void I2C_Stop(void)
  311. {
  312.         OLED_SDA_Clr();
  313.         OLED_SCL_Set();
  314.         IIC_delay();
  315.         OLED_SDA_Set();
  316. }


  317. //等待信号响应
  318. void I2C_WaitAck(void) //测数据信号的电平
  319. {
  320.         OLED_SDA_Set();
  321.         IIC_delay();
  322.         OLED_SCL_Set();
  323.         IIC_delay();
  324.         OLED_SCL_Clr();
  325.         IIC_delay();
  326. }


  327. //写入一个字节
  328. void Send_Byte(u8 dat)
  329. {
  330.         u8 i;
  331.         for(i=0;i<8;i++)
  332.         {
  333.                 OLED_SCL_Clr();//将时钟信号设置为低电平
  334.                 if(dat&0x80)//将dat的8位从最高位依次写入
  335.                 {
  336.                         OLED_SDA_Set();
  337.     }
  338.                 else
  339.                 {
  340.                         OLED_SDA_Clr();
  341.     }
  342.                 IIC_delay();
  343.                 OLED_SCL_Set();
  344.                 IIC_delay();
  345.                 OLED_SCL_Clr();
  346.                 dat<<=1;
  347.   }
  348. }


  349. //发送一个字节
  350. //向SSD1306写入一个字节。
  351. //mode:数据/命令标志 0,表示命令;1,表示数据;
  352. void OLED_WR_Byte(u8 dat,u8 mode)
  353. {
  354.         I2C_Start();
  355.         Send_Byte(0x78);
  356.         I2C_WaitAck();
  357.         if(mode){Send_Byte(0x40);}
  358.   else{Send_Byte(0x00);}
  359.         I2C_WaitAck();
  360.         Send_Byte(dat);
  361.         I2C_WaitAck();
  362.         I2C_Stop();
  363. }


  364. //坐标设置

  365. void OLED_Set_Pos(u8 x, u8 y)
  366. {
  367.         OLED_WR_Byte(0xb0+y,OLED_CMD);
  368.         OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);
  369.         OLED_WR_Byte((x&0x0f),OLED_CMD);
  370. }             

  371. /*
  372. //开启OLED显示   
  373. void OLED_Display_On(void)
  374. {
  375.         OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
  376.         OLED_WR_Byte(0X14,OLED_CMD);  //DCDC ON
  377.         OLED_WR_Byte(0XAF,OLED_CMD);  //DISPLAY ON
  378. }


  379. //关闭OLED显示     
  380. void OLED_Display_Off(void)
  381. {
  382.         OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
  383.         OLED_WR_Byte(0X10,OLED_CMD);  //DCDC OFF
  384.         OLED_WR_Byte(0XAE,OLED_CMD);  //DISPLAY OFF
  385. }                                            
  386. */

  387. //清屏函数,清完屏,整个屏幕是黑色的!和没点亮一样!!!          
  388. void OLED_Clear(void)  
  389. {  
  390.         u8 i,n;                    
  391.         for(i=0;i<8;i++)  
  392.         {  
  393.                 OLED_WR_Byte (0xb0+i,OLED_CMD);    //设置页地址(0~7)
  394.                 OLED_WR_Byte (0x00,OLED_CMD);      //设置显示位置?列低地址
  395.                 OLED_WR_Byte (0x10,OLED_CMD);      //设置显示位置?列高地址   
  396.                 for(n=0;n<128;n++)OLED_WR_Byte(0,OLED_DATA);
  397.         } //更新显示
  398. }


  399. //在指定位置显示一个字符,包括部分字符
  400. //x:0~127
  401. //y:0~63                                 
  402. //sizey:选择字体 6x8  8x16
  403. void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 sizey)
  404. {             
  405.         u8 c=0,sizex=sizey/2;
  406.         u16 i=0,size1;
  407.         if(sizey==8)size1=6;
  408.         else size1=(sizey/8+((sizey%8)?1:0))*(sizey/2);
  409.         c=chr-' ';//得到偏移后的值
  410.         OLED_Set_Pos(x,y);
  411.         for(i=0;i<size1;i++)
  412.         {
  413.                 if(i%sizex==0&&sizey!=8) OLED_Set_Pos(x,y++);
  414.                 if(sizey==8) OLED_WR_Byte(asc2_0806[c][i],OLED_DATA);//6X8字号
  415.                 else if(sizey==16) OLED_WR_Byte(asc2_1608[c][i],OLED_DATA);//8x16字号
  416. //                else if(sizey==xx) OLED_WR_Byte(asc2_xxxx[c][i],OLED_DATA);//用户添加字号
  417.                 else return;
  418.         }
  419. }


  420. //m^n函数
  421. u32 oled_pow(u8 m,u8 n)
  422. {
  423.         u32 result=1;         
  424.         while(n--)result*=m;   
  425.         return result;
  426. }                                  


  427. //显示数字
  428. //x,y :起点坐标
  429. //num:要显示的数字
  430. //len :数字的位数
  431. //sizey:字体大小                  
  432. void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 sizey)
  433. {                
  434.         u8 t,temp,m=0;
  435.         u8 enshow=0;
  436.         if(sizey==8)m=2;
  437.         for(t=0;t<len;t++)
  438.         {
  439.                 temp=(num/oled_pow(10,len-t-1))%10;
  440.                 if(enshow==0&&t<(len-1))
  441.                 {
  442.                         if(temp==0)
  443.                         {
  444.                                 OLED_ShowChar(x+(sizey/2+m)*t,y,' ',sizey);
  445.                                 continue;
  446.                         }else enshow=1;
  447.                 }
  448.                  OLED_ShowChar(x+(sizey/2+m)*t,y,temp+'0',sizey);
  449.         }
  450. }


  451. //显示一个字符号串
  452. void OLED_ShowString(u8 x,u8 y,u8 *chr,u8 sizey)
  453. {
  454.         u8 j=0;
  455.         while (chr[j]!='\0')
  456.         {               
  457.                 OLED_ShowChar(x,y,chr[j++],sizey);
  458.                 if(sizey==8)x+=6;
  459.                 else x+=sizey/2;
  460.         }
  461. }


  462. //显示汉字
  463. void OLED_ShowChinese(u8 x,u8 y,u8 no,u8 sizey)
  464. {
  465.         u16 i,size1=(sizey/8+((sizey%8)?1:0))*sizey;
  466.         for(i=0;i<size1;i++)
  467.         {
  468.                 if(i%sizey==0) OLED_Set_Pos(x,y++);
  469.                 if(sizey==16) OLED_WR_Byte(Hzk[no][i],OLED_DATA);//16x16字号
  470. //                else if(sizey==xx) OLED_WR_Byte(xxx[c][i],OLED_DATA);//用户添加字号
  471.                 else return;
  472.         }                               
  473. }


  474. //显示图片
  475. //x,y显示坐标
  476. //sizex,sizey,图片长宽
  477. //BMP:要显示的图片
  478. void OLED_DrawBMP(u8 x,u8 y,u8 sizex, u8 sizey,u8 BMP[])
  479. {        
  480.   u16 j=0;
  481.         u8 i,m;
  482.         sizey=sizey/8+((sizey%8)?1:0);
  483.         for(i=0;i<sizey;i++)
  484.         {
  485.                 OLED_Set_Pos(x,i+y);
  486.     for(m=0;m<sizex;m++)
  487.                 {      
  488.                         OLED_WR_Byte(BMP[j++],OLED_DATA);                   
  489.                 }
  490.         }
  491. }



  492. //初始化                                    
  493. void OLED_Init(void)
  494. {
  495.     OLED_SCL_DIR_OUT;
  496.     OLED_SDA_DIR_OUT;
  497.     delay_ms(200);
  498.         OLED_WR_Byte(0xAE,OLED_CMD);//--turn off oled panel
  499.         OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
  500.         OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
  501.         OLED_WR_Byte(0x40,OLED_CMD);//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
  502.         OLED_WR_Byte(0x81,OLED_CMD);//--set contrast control register
  503.         OLED_WR_Byte(0xCF,OLED_CMD); // Set SEG Output Current Brightness
  504.         OLED_WR_Byte(0xA1,OLED_CMD);//--Set SEG/Column Mapping     0xa0左右反置 0xa1正常
  505.         OLED_WR_Byte(0xC8,OLED_CMD);//Set COM/Row Scan Direction   0xc0上下反置 0xc8正常
  506.         OLED_WR_Byte(0xA6,OLED_CMD);//--set normal display
  507.         OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
  508.         OLED_WR_Byte(0x3f,OLED_CMD);//--1/64 duty
  509.         OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset        Shift Mapping RAM Counter (0x00~0x3F)
  510.         OLED_WR_Byte(0x00,OLED_CMD);//-not offset
  511.         OLED_WR_Byte(0xd5,OLED_CMD);//--set display clock divide ratio/oscillator frequency
  512.         OLED_WR_Byte(0x80,OLED_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec
  513.         OLED_WR_Byte(0xD9,OLED_CMD);//--set pre-charge period
  514.         OLED_WR_Byte(0xF1,OLED_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
  515.         OLED_WR_Byte(0xDA,OLED_CMD);//--set com pins hardware configuration
  516.         OLED_WR_Byte(0x12,OLED_CMD);
  517.         OLED_WR_Byte(0xDB,OLED_CMD);//--set vcomh
  518.         OLED_WR_Byte(0x40,OLED_CMD);//Set VCOM Deselect Level
  519.         OLED_WR_Byte(0x20,OLED_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02)
  520.         OLED_WR_Byte(0x02,OLED_CMD);//
  521.         OLED_WR_Byte(0x8D,OLED_CMD);//--set Charge Pump enable/disable
  522.         OLED_WR_Byte(0x14,OLED_CMD);//--set(0x10) disable
  523.         OLED_WR_Byte(0xA4,OLED_CMD);// Disable Entire Display On (0xa4/0xa5)
  524.         OLED_WR_Byte(0xA6,OLED_CMD);// Disable Inverse Display On (0xa6/a7)
  525.         OLED_Clear();
  526.         OLED_WR_Byte(0xAF,OLED_CMD); /*display ON*/
  527. }

  528.        
效果图



温度值显示有些模糊。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

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

本版积分规则

470

主题

3537

帖子

7

粉丝
快速回复 在线客服 返回列表 返回顶部