Single chip microcomputer controlled marquee

Publisher:熙风细雨Latest update time:2018-08-12 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. The difference between a marquee and a running water lamp


Many people cannot tell the difference between a running light and a running light, and think they are the same. Although the difficulty level is the same, the way the light turns on and off is different. Please see the picture below.


2. Common circuit connection methods for single chip microcomputer to control LED lights

After figuring out the display status of the marquee, you can start designing. In the daily marquee design circuit, LED lights are generally connected in two forms, common power supply or common ground, which is usually called current sinking and current sourcing.

3. Circuit Analysis and Programming

You can choose one of the connection methods according to your actual circuit needs. Since the IO port of the AT89S52 microcontroller is at a high level when not in operation, I choose the common power supply connection below.


   Circuit analysis: When the circuit outputs a high level [port is 1], the LED light is off; when the circuit outputs a low level [port is 0], the LED light is on

  You can program according to your own ideas. There is no unique method. Here I will introduce 3 methods.
   
Method 1: Do not use algorithms, directly use IO control [It can be said to be the stupidest method, but it can achieve the same effect and is easy to understand]

#include

//LED output port bit definition
sbit led0=P0^0;
sbit led1=P0^1;
sbit led2=P0^2;
sbit led3=P0^3;
sbit led4=P0^4;
sbit led5=P0^5;
sbit led6=P0^6;
sbit led7=P0^7;

//delay function
void delay(void)
{
 unsigned char a,b;
  for(a=0;a<200;a++)
  for(b=0;b<200;b++);
}


void main()
{
led0=1; //port initialization
led1=1;
led2=1;
led3=1;
led4=1;
led5=1;
led6=1;
led7=1;


while(1)
 {
 led0=0; //Turn on LED0
  delay(); //Delay
  led0=1; //Turn off LED0
  delay(); //Delay, prepare for the next light

 led1=0;
 delay();
  led1=1;
  delay();
   
  led2=0;
  delay();
 led2=1;
  delay();

 led3=0;
 delay();
 led3=1;
 delay();

 led4= 0;
 delay();
 led4=1;
  delay();

 led5=0;
 delay();
 led5=1;
 delay();

 led6=0;
 delay();
 led6=1;
 delay();

 led7=0;
 delay();
 led7=1;
 delay();
 }
}


Method 2: Improve the above program with the help of arrays to define the port at one time

#include
#define uchar unsigned char       
#define uint unsigned int

//Define a one-dimensional array
unsigned char table[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};


//Delay function
void delay(void)
{
  uchar a,b;
 for(a=0;a<200;a++)
 for(b=0;b<200;b++);
}


void main()
{
  uchar i;


  while(1)
 {
  for(i=0;i<8;i++)
 {
 P0=table[i];//11111110
  delay();
  }
}
}


Method 3: Using function encapsulation library

#include
#include //This is the header file for calling functions. You must add

#define uchar unsigned char 
#define uint unsigned int

//Delay function
void delay(void)
{
  uchar a,b;
  for(a=0;a<200;a++)
  for(b=0;b<200;b++);
}

void main()
{
  uchar k;


 k=0xfe; //define initial value

  while(1)
  {
 P0=k;
  delay();
 k=_crol_(k,1); //Call header file to encapsulate library function
  }
}

There are other methods such as shift operations, which are not listed here one by one.


Reference address:Single chip microcomputer controlled marquee

Previous article:Single chip microcomputer control independent key reading
Next article:51 MCU timestamp related functions

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号