#include
int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
void delay()
void stop()
delay();
void ADC_PCF8591_wt_(uchar date)
float a; int j;
a=i;
a=a*500/256;
j=a;
uint temp;
while(1)
{
temp=ADC_PCF8591_rd_(0x00);
display(temp);
}
Reference address:#Microcontroller# Using pcf8591 to read the voltage value of the potentiometer
sbit sda=P2^0;
sbit scl=P2^1;
#define uint unsigned int
#define uchar unsigned char
uchar code table[] ={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0x40};
//Display codes of 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, b, C, d, E, F
//--Define the read and write address of PCF8591--//
#define WRITEADDR 0x90 //write address
#define READADDR 0x91 //read address
void delayms(uint z)
{
}
{ ;; }
void start()
{
sda=1;
delay();
scl=1;
delay();
sda=0;
delay();
}
{
sda=0;
delay();
scl=1;
delay();
sda=1;
delay();
}
void respons() //response
{
flying i;
scl=1;
delay();
while((sda==1)&&(i<250))i ;
scl=0;
delay();
}
void write_byte(uchar date)
{
flying i,temp;
temp=date;
for(i=0;i<8;i )
{
temp=temp<<1;
scl=0;
sda=CY;
delay();
scl=1;
delay();
}
scl=0;
delay();
sda=1;
delay();
}
fly read_byte()
{
flying i,k;
scl=0;
delay();
sda=1;
delay();
for(i=0;i<8;i )
{
scl=1;
delay();
k=(k<<1)|sda;
scl=0;
delay();
}
return k;
}
flying ADC_PCF8591_rd_(flying channel)
{
flying date;
start();
write_byte(0x90);
response();
write_byte(channal);
response();
start();
write_byte(0x91);
response();
date=read_byte();
stop();
return date;
}
{
start();
write_byte(0x90);
response();
write_byte(0x40);
response();
write_byte(date);
response();
stop();
}
//Note: Select AD or DA in the main function and process it
void display(uchar i)
{
P2=0xfd;
P0=0xff;
P0=~table[j/100]&0x7f;
delayms(5);
P2=0xfb;
P0=0xff;
P0=~table[j0/10];
delayms(5);
P2=0xf7;
P0=0xff;
P0=~table[j];
delayms(5);
}
void main()
{
sda=1;
delay();
scl=1;
delay();
}
Previous article:#Single-chipcomputer#Matrix keyboard-electronic piano
Next article:#Single-chipcomputer# Song——There is only mother in the world
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- Teach you to learn 51 single chip microcomputer-C language version (Second Edition) (Song Xuefeng)
- 51 Single Chip Microcomputer Basic Experiment and Comprehensive Practice (Edited by Li Zuojin, Nie Ling, and Zhai Yuan)
- AUTOSAR MCAL Principles and Practice
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
MoreDaily News
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
Guess you like
- FP8102 1A single-cell lithium-ion linear charging IC
- Design of Passive Acoustic Target Detection Platform Based on Single Chip Microcomputer and DSP
- Design of low power portable electrocardiograph based on MSP430
- EEWORLD University Hall----Live Replay: Application of TI mmWave Radar Sensors in Smart Home and Smart Security
- I would like to ask the teachers: Class D amplifier problem
- India's richest man announced the successful development of domestic 5G, which may be deployed in 2021
- Smartphone module performance test
- Discussion on the Causes of Breakpoint Phenomenon of Shaded Pole Motor
- What is the difference between different chip suffixes?
- A survey on TikTok to see how much our engineering community plays it