1. The difference between a marquee and a running water lamp
Many people cannot tell the difference between a running light and a running light, and think they are the same. Although the difficulty level is the same, the way the light turns on and off is different. Please see the picture below.
2. Common circuit connection methods for single chip microcomputer to control LED lights
After figuring out the display status of the marquee, you can start designing. In the daily marquee design circuit, LED lights are generally connected in two forms, common power supply or common ground, which is usually called current sinking and current sourcing.
3. Circuit Analysis and Programming
You can choose one of the connection methods according to your actual circuit needs. Since the IO port of the AT89S52 microcontroller is at a high level when not in operation, I choose the common power supply connection below.
Circuit analysis: When the circuit outputs a high level [port is 1], the LED light is off; when the circuit outputs a low level [port is 0], the LED light is on
You can program according to your own ideas. There is no unique method. Here I will introduce 3 methods.
Method 1: Do not use algorithms, directly use IO control [It can be said to be the stupidest method, but it can achieve the same effect and is easy to understand]
#include
//LED output port bit definition
sbit led0=P0^0;
sbit led1=P0^1;
sbit led2=P0^2;
sbit led3=P0^3;
sbit led4=P0^4;
sbit led5=P0^5;
sbit led6=P0^6;
sbit led7=P0^7;
//delay function
void delay(void)
{
unsigned char a,b;
for(a=0;a<200;a++)
for(b=0;b<200;b++);
}
void main()
{
led0=1; //port initialization
led1=1;
led2=1;
led3=1;
led4=1;
led5=1;
led6=1;
led7=1;
while(1)
{
led0=0; //Turn on LED0
delay(); //Delay
led0=1; //Turn off LED0
delay(); //Delay, prepare for the next light
led1=0;
delay();
led1=1;
delay();
led2=0;
delay();
led2=1;
delay();
led3=0;
delay();
led3=1;
delay();
led4= 0;
delay();
led4=1;
delay();
led5=0;
delay();
led5=1;
delay();
led6=0;
delay();
led6=1;
delay();
led7=0;
delay();
led7=1;
delay();
}
}
Method 2: Improve the above program with the help of arrays to define the port at one time
#include
#define uchar unsigned char
#define uint unsigned int
//Define a one-dimensional array
unsigned char table[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
//Delay function
void delay(void)
{
uchar a,b;
for(a=0;a<200;a++)
for(b=0;b<200;b++);
}
void main()
{
uchar i;
while(1)
{
for(i=0;i<8;i++)
{
P0=table[i];//11111110
delay();
}
}
}
Method 3: Using function encapsulation library
#include
#include
#define uchar unsigned char
#define uint unsigned int
//Delay function
void delay(void)
{
uchar a,b;
for(a=0;a<200;a++)
for(b=0;b<200;b++);
}
void main()
{
uchar k;
k=0xfe; //define initial value
while(1)
{
P0=k;
delay();
k=_crol_(k,1); //Call header file to encapsulate library function
}
}
There are other methods such as shift operations, which are not listed here one by one.
Previous article:Single chip microcomputer control independent key reading
Next article:51 MCU timestamp related functions
- 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
- 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
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- dsp6657 serial port learning
- Try the data visualization tool of visionseed in Ubuntu
- Help with AD9 package design
- 1. Unboxing and Review
- Brief analysis of the functional block diagram of the MSP430 series microcontroller
- Use of Linux semaphores - code testing
- Free evaluation | Ateli AT-START-F403A helps you explore and discover ARM Cortex-M4F with FPU core
- How to configure the input and output of a GPIO in the TMS320C6000 series DSP?
- Working conditions and working characteristics of switching power supply
- Let’s discuss some common misunderstandings about GaN.