*This example uses the AD0804 chip, hardware circuit: cs chip select terminal connected to P2.3, WR write data terminal write to P3.6, RD read data terminal connected to P3.7, latch terminal connected to P2.6 pin, digital tube bit select terminal connected to P3.2, P3.3, P3.4 respectively, segment select terminal connected to P1 port*/
#include
#define uint unsigned int//macro file
#define uchar unsigned char//macro file
uchar num;//variable
void delay3(uint z);//delay definition
void dissy();//delay function definition
sbit ge=P3^2;//ones digit definition
sbit shi=P3^3;//tens digit definition
sbit bai=P3^4;//hundreds digit definition
sbit ad_cs=P2^3;//chip select terminal
sbit ad_wr=P3^6;//write data terminal
sbit ad_rd=P3^7;//read data end
sbit pian=P2^6;//latch chip select
void add();//ad conversion sub-function
void delay(uint i);//delay sub-function declaration
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90,
0x88,0x83,0xc6,0xa1,0x86,
0x8e
};//array
/************Main function**********/
void main()
{
while(1)
{
add();//Call AD conversion sub-function
dissy();//Digital tube display sub-function
}
}
/************AD conversion sub-function**********/
void add()//AD conversion sub-function
{
uchar i;
ad_cs=1;//turn off the chip selectad_cs
=0;//turn on the chip selectad_wr
=1;//write the rising
edgead_wr=0;//write the falling
edgead_wr=1;//write the rising edge
P1=0xff;//Send number to P0
portad_rd=1;//Read rising
edgedelay(25);//Delay for a whilead_rd
=0;//Read falling edge
//////**************Because the AD conversion time cycle is long, my current digital tube does not use latches, and the AD conversion time is greater than the display time, so it will flicker when displayed. The solution to this problem is to call the display subroutine seven times in succession, so that the display time is consistent with the AD conversion time, and the displayed number will not flicker********************//////
for(i=0;i<7;i++) //Call 7 times, equivalent to delay(255)
void dissy();
//////**************************************//////
num=P1;//Give the number to the counter num
}
/************Display sub-function**********/
void dissy()//Display sub-function
{
P0=table[num/100];//Hundreds display data
bai=0;//Hundreds open
delay(14);//Delay for a while
bai=1;//Close hundreds
P0=table[num%100/10];//Tens display data
shi=0;//Tens open
delay(14);//Delay for a while
shi=1;//Close tens
P0=table[num%10];//Hundreds display data
ge=0;//Close tens
delay(14);//Delay for a while
ge=1;//Close tens
}
/**************Delay sub-function*************/
void delay(uint i) //delay function
{
uint j,k; //define variables
for(j=i;j>0;j--) //outer loop
for(k=30;k>0;k--); //inner loop
}
Previous article:Introduction to MB89163 MCU and its application in remote control
Next article:Introduction to programmable active filter circuit based on single chip microcomputer
Recommended ReadingLatest update time:2024-11-17 02:55
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- 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
- 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!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- 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
- Notes on lines drawn by Protel series and AD series software
- Totem pole in circuit,,,
- PA Test Solution
- Creative Modification Competition: The moderator gave me two booster boards, and I used both of them!
- How to use GPIO to control line switching
- Lots of books! Have you read any books on this Book Day? Have you bought any books?
- What does Dual Panel Flash mean in the introduction of ATSAMD51P20A?
- Capacitor three-point oscillation composed of operational amplifier
- 09 ADC acquisition and power management system (series post)
- 【Short-term weather forecast system】Scheme planning