Experiment 1: Flashing an LED
//An LED flashing experiment
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
//Header file
#include
//Port setting
sbit P10=P1^0;
char code dx516[3] _at_ 0x003b;
//Main function
void main(void)
{ uint i;
P10=0;
while(1)
{
P10=~P10; //Invert
for (i=0;i<20000;i++);//Delay
}
}
Experiment 2: Marquee Experiment
//Marquee experiment
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#include
//Port settings
sbit P10=P1^0;
sbit P11=P1^1;
sbit P12=P1^2;
sbit P13=P1^3;
char code dx516[3] _at_ 0x003b;
//Main function
void main(void)
{ uint i;
while(1)
{
P13=1;P10=0; //Adjacent port inversion
for (i=0;i<40000;i++); //Delay
P10=1;P11=0;
for (i=0;i<40000;i++);
P11=1;P12=0;
for (i=0;i<40000;i++);
P12=1;P13=0;
for (i=0;i<40000;i++);
}
}
Experiment 3: One button controls the on and off of an LED
//One button controls the LED
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#include
//Port settings
sbit P10=P1^0;
sbit K1=P3^2;
sbit K2=P3^5;
char code dx516[3] _at_ 0x003b;
//Main function
void main(void)
{
while(1)
{
if (!K1) //Press once
{
P10=0; //On
}
if (!K2) //Press again
{
P10=1; //Off
}
}
}
Program with debounce:
//Debounce button control LED light experiment
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#include
//Port setting
sbit P10=P1^0; //LED light
sbit K1=P3^2; //key
char code dx516[3] _at_ 0x003b;
//main function
void main(void)
{
bit light;
uint i;
while(1)
{
if (!K1) //confirm key is pressed
{
for (i=0;i<1000;i++); //delay
light=~light; //light inversion
while(!K1); //debounce function
for (i=0;i<1000;i++);
}
P10=light;
}
}
Previous article:C51 Introduction 3, IIC Communication Experiment
Next article:Application of temperature sensor DS18820 in color measurement system
- 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
- GD32E231 DIY Competition (9)——"Home Intelligent Monitoring" Project Summary
- About G2553 with 20 pins cannot be programmed
- Method for testing FPGA logic unit based on BIST using ORCA structure
- [TI recommended course] #[High Precision Laboratory] Magnetic Sensor Technology#
- BLE CC2541 as low-power intelligent hardware
- I really don't know how to convert brd to PCB. Please help me.
- PT6312 driver Samsung segment screen hardware design driver source code
- Verilog_HDL_Implementation of Common Logic
- TI CC2530 button controls the light on and off
- Why does the STM series MCU use SMD T card instead of traditional T card?