Blue Bridge Cup MCU PCF8591 Data reading is converted to humidity detection , Because there is no chip for humidity detection on the single chip microcomputer provided by Blue Bridge Cup , So when investigating, we use PCF8591 Replace the data read by the chip , There are two general investigation forms for specific data formats , One is 0-255 Integer form ; The other is 0-5 Floating point data . But in fact, it is just a data conversion .

No matter how you investigate it, it is (0-255)
And (0-5) Corresponding conversion of . Because use PCF8591 The data read out is in integer form 0-255, So you need to show 0-5 Floating point data , Necessary conversion is required .

Another is PCF8591 The address read by the chip is different , There is a little difference between the peripherals corresponding to reading . Read address 0x01 When reading the resistance value of the sliding rheostat , Read address 0x03 When reading, the resistance value of the photoresist is read , But they also have one thing in common , The resistance range of both is 0-255, The conversion formula is the same when conversion is required .
# include "reg52.h" # include "intrins.h" # include "iic.h" typedef unsigned
char u8; typedef unsigned int u16; u8 shuma[12] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92
,0x82,0xf8,0x80,0x90,0xbf,0xbf}; u8 adc_value; u8 adc_table[3]; u8 value_table[3
]; // Initialize peripheral functions void init_system() { P2 = (P2 & 0x1f) | 0x80; P0 = 0xff; P2 = (P2
& 0x1f); P2 = (P2 & 0x1f) | 0xa0; P0 = 0x00; P2 = (P2 & 0x1f); P2 = (P2 & 0x1f)
| 0xc0; P0 = 0x00; P2 = (P2 & 0x1f); } // Gating function void select(u8 local) { switch(
local) { case(4): P2 = (P2 & 0x1f) | 0x80; break; case(5): P2 = (P2 & 0x1f) |
0xa0; break; case(6): P2 = (P2 & 0x1f) | 0xc0; break; case(7): P2 = (P2 & 0x1f)
| 0xe0; break; } } void delay() { u8 t = 200; while(t--); } void display(u8
local, u8 num) { select(6); P0 = 0x80 >> (local - 1); P2 = P2 & 0x1f; select(7);
P0= num; P2 = P2 & 0x1f; // Simple delay delay(); } void close_display() { // Blanking select
(6); P0 = 0x00; P2 = P2 & 0x1f; } // Write content to address add inside void adc_write(u8 add) {
IIC_Start(); IIC_SendByte(0x90); IIC_WaitAck(); IIC_SendByte(add); IIC_WaitAck()
; IIC_Stop(); } // Read address add What's inside u8 adc_read(u8 add) { u8 temp; IIC_Start();
IIC_SendByte(0x90); IIC_WaitAck(); IIC_SendByte(add); IIC_WaitAck(); IIC_Start()
; IIC_SendByte(0x91); IIC_WaitAck(); temp = IIC_RecByte(); IIC_WaitAck();
IIC_Stop(); return temp; } // Delay two milliseconds ( Software delay ) void Delay2ms() //@11.0592MHz { u8 i,
j; _nop_(); _nop_(); i = 22; j = 128; do { while (--j); } while (--i); } void
main() { float volt; init_system(); adc_write(0x01); // Resistance value of sliding rheostat (0x03 Photosensitive rheostat )
while(1) { adc_value = adc_read(0x01); // Read the resistance value of the sliding rheostat ( By sliding RB3 To view changes ) //
The read address is 0x03 When , Read the resistance value of the photosensitive rheostat ( The change can be observed by adjusting the brightness ) adc_table[0] = adc_value % 10;
adc_table[1] = adc_value / 10 % 10; adc_table[2] = adc_value / 100; //
display(1,shuma[adc_table[0]]); // integer 0-255 Display form of //
display(2,shuma[adc_table[1]]); // display(3,shuma[adc_table[2]]); //
close_display(); volt = (adc_value / 255.0) * 5.0; value_table[2] = (u8)(volt);
// Directly take out the single digit value value_table[1] = (u8)(volt*10) % 10; // Zoom in ten times , Calculate the decimal value value_table[0
] = (u8)(volt*100) % 10; // Zoom in a hundred times , Calculate the value of the percentile // Floating point number 0-5 Display form of display(3,shuma[
value_table[2]] & 0x7f); // Each digit value processing decimal point operation display(2,shuma[value_table[1]]);
display(1,shuma[value_table[0]]); close_display(); Delay2ms(); } }

Technology