/*
Program effect: The digital tube displays one byte of data converted from AD, displayed in decimal
Adjust the corresponding potentiometer to change the displayed data accordingly
Program development: http://www.51hei.com
Principle: 0831 is a serial AD chip. Adjusting the positioner is to adjust the size of the analog voltage input to 0831, and then display it through the digital tube
Operating environment: 51hei single-chip learning board
*/
#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={0x3f,0x06,0x5b,//digital tube display value
0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
sbit scl1=P1^3; //chip communication pulse pin
sbit sda1=P1^4; //data transmission pin
sbit px1=P1^5; //Chip select pin, i.e. select ADC0831 and DS1302
sbit cs1=P1^6; //Chip select pin
uchar tmpdata[]={0,0,0};
uchar readad0831();//Define this function to read the data of ADC0831
void display(uchar *lp,uchar lc); //Display sub-function
void delay(); //Delay sub-function
void main() //Main function
{
uchar i=0,tmp;
px1=0; //Select ADC0831 chip
while(1)
{
i++;
if(i==255) //Here is a loop of 255 cycles to read 0831 once,
{ //Because the CPU runs very fast, there is no need to read it every time
tmp=readad0831(); //Read data, so that the CPU resources can be fully utilized
i=0;
tmpdata[0]=tmp/100;//Separate the hundreds digit
tmp=tmp%100;
tmpdata[1]=tmp/10; //separate the tens digit
tmpdata[2]=tmp%10; //separate the ones digit
}
display(tmpdata,3); //output display
}
}
void display(uchar *lp,uchar lc) //display subfunction
{
uchar i; //define local variable
P2=0; //Port P2 is the output port
P1=P1&0xf8; //The first three digits of port P1 are used to control which digital tube is lit.
//If it is changed to P1=0xf8, the digital tube may appear
//non-stop display, making it difficult to distinguish the displayed value
for(i=0;i
P2=table[lp[i]]; //loop display
delay(); //delay five empty instructions
if(i==7) //check whether all 8 digits have been displayed, and exit directly if completed
//Do not let port P1 add one more, otherwise it will affect port P1^4
break;
P2=0; //clear the port and prepare to display the next digit
P1++; //light up the next digital tube
}
}
void delay() //delay sub-function
{
_nop_();_nop_();_nop_();_nop_();_nop_();
}
uchar readad0831() //This function is written according to the protocol of ADC0831
{
uchar i=0,tmp=0;
sda1=1;
cs1=0;
_nop_
(
);
_nop_();
scl1=0;
_nop_();
_nop_
();
scl1=1;
_nop_
();
_nop_
(); scl1=0; _nop_();
_nop_();
scl1=1;
_nop_();
_nop_();
scl1=0;
_nop_();
_nop_();
for(i=0;i<8;i++)
{
tmp<<=1;
if(sda1)
tmp++;
scl1=1;
_nop_();
_nop_();
scl1=0;
_nop_();
_nop_();
}
cs1=1;
return tmp;
}
If the program does not compile, remove all leading spaces.
Previous article:ADC0831 voltmeter program with digital tube display
Next article:Keyboard scanning-digital tube incremental display program
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!
- 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
- X-NUCLEO-IKS01A3 sensor test based on STM32F401RE development board 3D acceleration LIS2DW12 sensor test...
- ARM Embedded Learning Resource Sharing——"ARM Embedded Architecture and Interface Technology".pdf
- I would like to ask if the 8255A chip can only select one port at a time. After defining the address for the port, such as Q8255A XBYTE...
- Power supplies with digital control
- Please advise, brothers.
- One year's work equals three years' work? TSMC engineer shows off 2.5 million yuan bonus
- Evaluation summary: Mil based on NXP's first NPU kit MYC-JX8MPQ
- How to choose a suitable water level sensor?
- Can someone help me think of a microcontroller project?
- Development of User Graphical Interface (GUI) for Digital Oscilloscope Based on DSP