The MCU in this article is the hardware equipment of the 11th Blue Bridge Cup MCU training .
<> Hardware foundation of Blue Bridge Cup single chip microcomputer
<>PCF8591 Circuit diagram :
PCF8591 Yes IIC Bus interface 8 position A/D and D/A converter , have 4 road A/D Conversion input ,1 road D/A Analog output , Information transmission only depends on the clock line SCL And data cable SDA Can be achieved .
<> Analog voltage input circuit diagram :
Hardware rotation Rb2 knob , The input value of analog voltage can be changed .
<> Circuit diagram of light intensity resistance voltage input :
Change of photoresist value , Affect the input value of the analog voltage channel .
<>ADC/DAC Module driven configuration
* PCF8591 use IIC Addressing method of bus interface device , The device address and pin address are as follows :
The first byte written is known 0x90;
* The control byte format is configured as follows :
therefore , The analog voltage control word is 0x43; The photoresist voltage input control word is 0x41;
<>ADC/DAC Module function code :
Due to the use of IIC Bus interface , therefore ADC/DAC The conversion function is the same as that described earlier AT24C02 Memory consistency , Just modify the corresponding device address and control word , I won't introduce more here .
<> Related code writing :
* ADC Read function u8 ADC(u8 channal) { u8 dat; IIC_Start(); IIC_SendByte(0x90);
IIC_WaitAck(); IIC_SendByte(0x40+ch); IIC_WaitAck(); IIC_Start(); IIC_SendByte(
0x91); IIC_WaitAck(); dat = IIC_RecByte(); IIC_SendAck(1); // No response IIC_Stop();
return dat; }
* DAC Output function ( Voltage output ) void DAC(u8 dat) { IIC_Start(); IIC_SendByte(0x90);
IIC_WaitAck(); IIC_SendByte(0x43); IIC_WaitAck(); IIC_SendByte(dat); IIC_WaitAck
(); IIC_Stop(); Delay5ms(); }
How to use functions , Not here , Welcome questions and consultation ~
Technology