C51 Introduction 1, Marquee and LED Experiment

Publisher:eaff86Latest update time:2016-10-31 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The first thing I came into contact with was C51. I implemented the program I wrote before on my own experimental board. Now I have sorted it out and saved it as a souvenir!!!

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;
  }
 }

Reference address:C51 Introduction 1, Marquee and LED Experiment

Previous article:C51 Introduction 3, IIC Communication Experiment
Next article:Application of temperature sensor DS18820 in color measurement system

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号