16 characters in the digital tube
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
Delay function (declare it before using it)
void delay(uint);
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
Light up the first diode
#include //Light up the first LED sbit D1=P1^0;//P1 is the P1 port, P1^0 represents D1, and D1 is a variable named by itself main() { D1=0;//Convert high frequency to low frequency } Light up multiple diodes #include void main() { P1=0XAA; //The eight bits of the P1 port are operated together, the high and low levels are assigned to 10101010, and the diode corresponding to the bit of 0 is lit. while(1); } #include sbit led1=P1^0; //The first LED is connected to the P1^0 port. sbit led3=P1^2; sbit led5=P1^4; sbit led7=P1^6; void main() { led1=0; //Refer to the circuit diagram, P1^0 is low level, which can make led1 light up. led3=0; led5=0; led7=0; while(1);//Set an infinite loop here to let the program stay here to prevent it from running away. } Running water lamp fool-like lighting #include #define uint unsigned int sbit p0=P1^0; sbit p1=P1^1; sbit p2=P1^2; sbit p3=P1^3; sbit p4=P1^4; sbit p5=P1^5; sbit p6=P1^6; sbit p7=P1^7; #define uchar unsigned char void delayms(uint); void main() { while(1) { //0xaa is 1, 3, 5, 7, 0x55 2, 4, 6, 8 p0=1; p1=0; p2=1; p3=0; p4=1; p5=0; p6=1; p7=0; delayms(500); p0=0; p1=1; p2=0; p3=1; p4=0; p5=1; p6=0; p7=1; delayms(500); } } void delayms(uint xms) { uint x,y; for(x=xms;x>0;x--) for(y=110;y>0;y--); } P1^(0~7) The position of the light-emitting diode on stc Timer function definition void init()//Initialization function { TMOD=0x01;//Set timer 0 to working mode 1 (0000 0001) TH0=(65536-45872)/256//install the initial value and interrupt once every 50ms TL0=(65536-45872)%256; EA=1;//Enable total interrupt ET0=01; //Enable timer 0 interrupt } interrupt service routine Interrupt routine void function name() interrupt interrupt number using working group { Interrupt service routine content } e.g.: void T1_time() interrupt 3 { TH1=(65536-10000)/256; TL1=(65536-10000)%256; }
Previous article:51 microcontroller learning - lighting up the first light-emitting diode
Next article:51 microcontroller implements thermometer
- 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
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- Motor Science Series丨Understanding Motor Control Algorithms
- A beginner was trapped by the garbage code of the development board for a whole night
- SinlinxA33 development board Linux platform bus device driver
- Broadband Matching Network_Huang Xiangfu《Scanned Version》
- MSP430 MCU application of timer, PWM, comparator
- Do I need to draw the display screen myself when drawing the AD10 schematic?
- 【AT-START-F403A Review】+A/D Waveform Drawing
- GD32L233C-START evaluation 0.96 OLED display (I2C bus) display code transplantation
- The truth is simple. Why is the invariance of the speed of light so obscure and difficult to understand? Which master can explain the mystery?
- [TI recommended course] #Innovation of general-purpose op amp and comparator chips#