Breathing light program using 51 single chip microcomputer

Publisher:alpha11Latest update time:2018-03-08 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

//Crystal oscillator 11.0592
//The light changes gradually from bright to dark under the control of the single-chip microcomputer, and it feels like breathing.
//This example uses a digital tube and an LED light on the 51hei-5 development board to achieve a breathing effect.
//File download: http://www.51hei.com/f/fxd.rar
#include
#define uint unsigned int
#define uchar unsigned char


    sbit D1=P0^7;

    uchar sr;
uchar jf;

    uchar code table[]={
0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,
19,20,21 ,22,23,24,25,26,27,
28,29,30,31,32,33,34,35,36,
37,38,39,40,41,42,43,44,45,
46 ,47,48,49};

    void light(uchar num);
void delay(uint z);

    void main()
{
//Set the counter
//Select counting mode 1
 TMOD = 0x11;
//Write the initial value to the counter
 TH0 = 0;
 TL0 = 0;
////////////////////
//Operate the microcontroller
//Turn on CPU interrupt
 EA = 1;
/////////////////////
//Turn on timer T0 bit interrupt
 ET0 = 1;
//Turn on counter
 TR0 = 1;
//Operate diode
P1=0;
 while(1)
 {
  if(sr<50)
  light(sr);
  else sr=0;
 }
}
//Subfunction
void light(uchar num)
{
 uchar tme;
 D1 = 0;
 tme = table[num];
 delay(tme);
 D1 = 1;
 delay(49-tme);
}
//Interrupt function
void time () interrupt 1
{
//Increment the independent variable
 if (jf<2)
  {
  jf++;
  TH0 =0;
  TL0 = 0;
  }
 
 if (jf==2)
  {
//Write initial value
  jf=0;
  
  TH0 = 254;
  TL0 = 254;
  sr++;
  } 
}
void delay(uint z)
{
 uint x,y;
 for(x=10;x>0;x--)
  for(y=z;y>0;y--);
}


Reference address:Breathing light program using 51 single chip microcomputer

Previous article:Dot matrix + music = happy birthday program based on 51 single chip microcomputer
Next article:Microcontroller self-study notes: Flowing light design program

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号