unsigned char code Tab[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
// Segment code table of digital tube display 0~9
unsigned char int_time; //Record interrupt times
unsigned char second; //Store seconds
/************************************************************************
Function: Fast dynamic scanning delay, delay of about 0.6 milliseconds
********************************************************************/
void delay(void)
{
unsigned char i;
for(i=0;i<200;i++)
;
}
/***************************************************************************
Function: Display seconds
Input parameter: k
Output parameter: None
************************************************************************/
void DisplaySecond(unsigned char k)
{
P2=0xbf; //P2.6 pin outputs low level, DS6 lights up
P0=Tab[k/10]; //Display tens digit
delay();
delay();
delay();
delay();
delay(); delay();
delay();
delay();
delay();
P2=0x7f; //P2.7 pin outputs low level, DS7 lights up
P0=Tab[k%10]; //Display the units digit
delay();
delay();
delay();
delay();
delay(); delay();
delay();
delay();
delay();
P2=0xff; //Turn off all digital tubes
P0=0xff; //Display units
delay();
delay();
delay();
delay(); delay ();
delay();
delay()
; delay();
delay();
}
void main(void) //Main function
{
TMOD=0x01; //Use timer T0
TH0=(65536-46083)/256; //Set the timer timing to 46083×1.085 microseconds
//=50000 microseconds=50 milliseconds
TL0=(65536-46083)%256;
EA=1; //Turn on total interrupt
ET0=1; //Timer T0 interrupt enable
TR0=1; //Start timer T0 and start running
int_time=0; //Initialize the number of interrupts
second=0; //Initialize seconds
while(1)
{
DisplaySecond(second); //Call the display subroutine of seconds
}
}
//************************************************************
// Function: interrupt service routine of timer T0
//***********************************************************
void interserve(void ) interrupt 1 using 1
{
TR0=0; //Turn off timer T0
int_time ++; //Every time an interrupt comes, the interruption count int_time is incremented by 1
if(int_time==20) //Enough interruptions, i.e. sampling the test result once every 1 second
{
int_time=0; //The interruption count is cleared to 0
second++; //Increase the second by 1
if(second==60)
second =0; //If the second is equal to 60, it returns to 0
}
TH0=(65536-46083)/256; //Re-initialize the counter T0
TL0=(65536-46083)%256;
TR0=1; //Start timer T0
}
Previous article:Digital tube scrolling display C language programming
Next article:Digital tube dynamic scanning display 12345678
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- About CRC check
- AX5201 is used as an LED driver circuit with 4.5V input and 12V output, and it is likely to be damaged.
- How to deal with impedance continuity of PCB traces?
- FPGA Design Tips
- Develop and study Hongmeng system-data collection
- Why can't CCS5.5 be installed?
- [National Technology N32G457 Review] DHT22 temperature and humidity detection
- What is the relationship between MCIMX6Y2CVM05AB and IMX6ULL?
- MSP430 FRAM Microcontrollers Enable Energy Harvesting
- Lesson 3: Exploring the Cellular Communication Module OpenCPU