void leddisplay(); // digital tube display
void delayms(unsigned int k); // delay n ms
void USART_SEND(unsigned char dat); // serial port sending subroutine
unsigned char data ledxs[8]={16,16,16,16,16,0,0,18}; // digital tube display buffer
unsigned char code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0,0xff,0x76};
// common cathode code 0-F, all off, all on, H
void main()
{
unsigned char dat=0,i;
delayms(200);
TMOD=0x20; // Timer 1 mode 2, 8-bit auto-reload
TL1=0xe6;
TH1=0xe6; // Baud rate 1200
TR1=1;
SCON=0x50; // Serial port mode 1, receive enabled, 8-bit data, no parity, 1 start bit, 1 end bit
EA=1; // Enable serial port interrupt
ES=1; // Enable total interrupt
while(1)
{
for(i=0;i<60;i++)
leddisplay(); // Loop display 60 times, delay 480ms
USART_SEND(dat); // Serial port sends data (0-255)
dat++;
if(dat==256) dat=0;
}
}
void USART_SEND(unsigned char dat) // Serial port sending subroutine
{
SBUF=dat; // Send data
while(TI==0); // Wait for sending to complete
TI=0;
}
void USART_RCV_INT(void) interrupt 4 using 1 // Serial port receive interrupt service routine
{
unsigned char dat;
if(RI==1) // Determine whether it is a receive interrupt
{
RI=0;
dat=SBUF; // Receive data
ledxs[5]=dat/16;
ledxs[6]=dat%16; // Convert received data to hexadecimal display
ledxs[7]=18;
}
}
void leddisplay() // LED display subroutine
{
P2=0xdf;
P0=tab[ledxs[0]];
delayms(1);
P0=0x00;
P2=0x5f;
P0=tab[ledxs[1]];
delayms(1);
P0=0x00;
P2=0x9f;
P0=tab[ledxs[2]];
delayms(1);
P0=0x00;
P2=0x1f;
P0=tab[ledxs[3]];
delayms(1);
P0=0x00;
P2=0xff;
P0=tab[ledxs[4]];
delayms(1);
P0=0x00;
P2=0x7f;
P0=tab[ledxs[5]];
delayms(1);
P0=0x00;
P2=0xbf;
P0=tab[ledxs[6]];
delayms(1);
P0=0x00;
P2=0x3f;
P0=tab[ledxs[7]];
delayms(1);
P0=0x00;
}
void delayms(unsigned int k) //Delay n ms
{
while(k)
{
int i;
i=110;
while(i--);
k=k-1;
}
}
Previous article:PS2 keyboard 51 test program 1
Next article:51 programs for matrix keyboard
- Popular Resources
- Popular amplifiers
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
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Four-axis source code
- [Help] Hardware IIC slave problem of stm8s103f3p6
- Is it necessary to add a π-type filter circuit for serial communication? If the board is small and the space is limited, this must be considered.
- The conducted spurious signals of the RF with shielding cover are 5-6dB worse than those without shielding cover.
- What should we pay attention to when launching new products? In particular, is there any good advice on how to prevent plagiarism?
- Design of Chinese Human-Machine Interface Based on MSP430 Microcontroller with Low Power Consumption
- Goodbye 2019, hello 2020. Some of the goals set in 2019 have not been achieved. It’s a pity. Let’s continue to work hard in 2020.
- EEWORLD University Hall----Shijian KOL: Who protects the source of life--ADuCM355 one test five!
- How to configure EPI mode on TI microcontroller?
- The reverse connection protection circuit will also be turned on. Please help me see