Xiaobai self-study c51 notes - running water lamp

Publisher:温文儒雅Latest update time:2022-04-19 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Development board schematic diagram:

insert image description here

From the schematic diagram of the development board, we know that LEDs 1 to 8 are connected to P2^0 to P2^7 respectively. When low voltage is input to P2 port, the LED lights up (VCC indicates high voltage, and P2 outputs low voltage when it is 0 and high voltage when it is 1).

It can be expressed in two ways:

1.


#include


sbit led1=P2^0; //If you want to use other LEDs, change to the corresponding


void main()

{

led1=0;

}


#include

#define led P2 //no semicolon


void main()

{

led=0x00; //0x means hexadecimal, other explanations are below

}


Note: P is capitalized.

Here is the code I wrote:


#include "reg52.h "

#include "intrins.h"

#define led P2 //#define is a macro definition

void delay(unsigned int i) //custom delay function

{

while(i--);

}

void main()

{

unsigned int i=0;       //define unsigned integer i and assign value 0

led=0xfe;               //0xfe is hexadecimal: 1111 1110; that is, only the first LED is lit

delay(20000); //Call the delay function above to achieve the purpose of delay

while(i<7) //while loop, when i does not meet the condition, {} the inner loop ends

{

led=_crol_(led,1); //Left shift function: LED is shifted left by 1 bit, that is, 1111 1101, which can light up the second LED

delay(20000);

i++; //i=i+1;

} //The above while loop can make the eight LEDs light up in sequence

while(i>2)

{

led=0x55; //0101 0101

delay(5000);

led=~led; //negate: 1010 1010

delay(5000);

i--;

}

}


Next, Xiaobai self-studies C51's mood chapter:

So damn excited, just a little bit away from ascending to heaven

Reference address:Xiaobai self-study c51 notes - running water lamp

Previous article:Xiaobai's self-study notes on C51 digital tube 1——D74HC245 and D74HC138
Next article:51 single chip multi-channel independent key switch program

Recommended posts

02.USART routines and tests
ThereisnotmuchinformationaboutL233CxProjectsunderthedevelopmentboardDemo,soUSARTisselectedfortesting. OpentheUSARTrelatedprogram,compileanddownloadit,andthenburnitintothechip BecauseIonlyhaveoneMini
unisqhzgok GD32 MCU
Is there any recommended equipment for measuring high voltage and current in automobiles?
Isthereanyrecommendedequipmentformeasuringhighvoltageandcurrentinautomobiles? Whataretherequirements?Ihavejuststartedtogetinvolvedintheautomotiveelectronicsindustryandhavenotencounteredsuchademandyet.Iamnots
是广州智维的段工呀 Automotive Electronics
Which shielding effect is better, copper foil or plain cloth?
IwanttoshieldthecircuitonaPCB.Whichoneisbetter,copperfoiltapeorplainclothtapeofthesamethickness? IhaveonlyusedcopperfoiltapeandEMCgluetoenhancetheshieldingofmetalcasings,andbothhaveacertaineffect. Cop
littleshrimp Integrated technical exchanges
Dual-band transceiver for 1.3GHz and 2.3GHz bands
Thisisalowpowerdualbandtransceiverdesignedforthe1.3GHzand2.3GHzamateurbands,operatinginbothSSBandCWmodes.Thefrequenciescoveredare1296MHzto1298MHzand2320MHzto2322MHz. Schematicdiagram
btty038 RF/Wirelessly
How to record and call script files in Allegro software?
Title:HowtorecordandcallscriptfilesinAllegrosoftware? Inthepreviousquestionandanswer,wementionedhowtousetheReplaycommandtospecifyshortcutkeys.WhenusingtheReplaycommandtospecifyshortcutkeys,youneedtorecorda
凡亿教育 PCB Design
Detailed explanation of PWM control principle and circuit application
1 PWM(PulseWidthModulation)isatechnologythatusespulsestooutputanalogsignals.Itmodulatesthewidthofaseriesofpulsestoproduceanequivalenttargetwaveform.Itiswidelyusedinmeasurement,communication,switchingpowersuppl
smls_小森 Power technology
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号