1643 views|2 replies

249

Posts

5

Resources
The OP
 

【N32L43x Review】OLED Displays Temperature and Humidity Data [Copy link]

 

Last time we tested the sht20 temperature and humidity sensor, we always used the debugging method, which made it difficult to see clearly. It is best to use a display screen to display it. Today we will use the software method to test our OLED display screen to display our temperature and humidity data.

First, we initialize our IO ports. Since we are still using analog IIC, we just randomly select two ports. Here I choose PA2 and PA3. The actual configuration is simple and can communicate. Here we configure it to output mode because we don't read data.

/**********************************************

//IIC Start

**********************************************/

void IIC_START()

{

 OLED_SDIN_Set();

 delay_us(10);

 OLED_SCLK_Set();

 delay_us(10);

 OLED_SDIN_Clr();

 delay_us(10);

 OLED_SCLK_Clr();

 delay_us(10);

}



/**********************************************

//IIC Stop

**********************************************/

void IIC_STOP()

{

 OLED_SDIN_Clr();

 delay_us(10);

 OLED_SCLK_Set();

 delay_us(10);

// OLED_SCLK_Clr();



 OLED_SDIN_Set();

 delay_us(10);



}



void IIC_Wait_Ack()

{

 OLED_SDIN_Clr();

 delay_us(5);

 OLED_SCLK_Set();

 delay_us(5);

 OLED_SCLK_Clr();

}



/**********************************************

// IIC Write byte

**********************************************/

void Write_IIC_Byte(unsigned char IIC_Byte)

{

 unsigned char i;

 unsigned char m,da;

 da=IIC_Byte;

 OLED_SCLK_Clr();

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

 {

 m=da;

 m=m&0x80;

 if(m==0x80)

 {

 OLED_SDIN_Set();

 }

 else

 {

 OLED_SDIN_Clr();

 }

 da=da<<1;

 delay_us(5);

 OLED_SCLK_Set();

 delay_us(5);

 OLED_SCLK_Clr();

 delay_us(5);

 }

}



/**********************************************

// IIC Write Command

**********************************************/

void Write_IIC_Command(unsigned char IIC_Command)

{

 IIC_START();

 Write_IIC_Byte(0x78); //Slave address,SA0=0

 IIC_Wait_Ack();

 Write_IIC_Byte(0x00); //write command

 IIC_Wait_Ack();

 Write_IIC_Byte(IIC_Command);

 IIC_Wait_Ack();

 IIC_STOP();

}



/**********************************************

// IIC Write Data

**********************************************/

void Write_IIC_Data(unsigned char IIC_Data)

{

 IIC_START();

 Write_IIC_Byte(0x78); //D/C#=0; R/W#=0

 IIC_Wait_Ack();

 Write_IIC_Byte(0x40); //write data

 IIC_Wait_Ack();

 Write_IIC_Byte(IIC_Data);

 IIC_Wait_Ack();

 IIC_STOP();

}

在我们的IIC中我们还是需要配置下延时的,实测速度比较快,没有延时OLED要么显示不对,要么就是直接不亮了。

 OLED_ShowString(byte(3)+4,line1," Nation",8);

 OLED_ShowString(byte(0),line4,"Temp:",8);

 OLED_ShowString(byte(0),line6,"Humi:",8);



 OLED_ShowString(byte(10),line4,"C",8);

 OLED_ShowString(byte(10),line6,"%",8);

After that, we will establish several fixed display positions in main, which will serve as prompts.

Then comes the dynamic display part. Our data is of float type. Our OLED displays either characters or numbers. To get floating-point data, we need to convert the floating-point data into characters.

Then here is another function that can be used. As follows:

 SHT20_GetValue();

 sprintf(temp,"%.2f",sht20Info.tempreture);

 sprintf(humi,"%.2f",sht20Info.humidity);

 OLED_ShowString(byte(5),line4,temp,8);

 OLED_ShowString(byte(5),line6,humi,8);

This is our sprintf function, which can convert floating point to char. And you can choose to keep the decimal places. Very convenient. In this way, we have completed the transplantation. Watch our video. The last attachment is at the end.

演示视频

demo.zip (8.97 MB, downloads: 5)

This post is from Domestic Chip Exchange

Latest reply

Support the boss!!!! I took the source code! ! Just put it on my homework   Details Published on 2022-7-26 10:14
 
 

16

Posts

0

Resources
2
 

Support the boss!!!!

I took the source code! ! Just put it on my homework

This post is from Domestic Chip Exchange

Comments

No problem Search Copy  Details Published on 2022-7-26 10:49
 
 
 

249

Posts

5

Resources
3
 
Pythonista posted on 2022-7-26 10:14 Support the big guy! ! ! ! I took the source code! ! I will post it directly on my homework

no problem

This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list