elleny

AT89S52 solution colorful flowing water lamp

 
Overview

Topic requirements:

Use a microcontroller to make a graduation project product, and complete it independently, from designing EDA schematics to drawing PCB to PCB proofing, purchasing components, and soldering components, and use keil5 microcontroller development software for development

Implementation function:

Use a button to control, and need to develop a power-on system, with a total of 4 major functions. After the product is powered on, the LED lights on both sides will light up at the same time, and then go out. Then you need to operate the function/power-on button to perform function operations/

choose.

Functional requirements: Press and hold for 4 seconds to turn on the computer. There are 4 major functions in total. Each function is represented by LED1-LED4 respectively. The 4s button is not automatically determined by the operating system. Then each function executes the command once, and then waits for the user to reselect the function. The same if It will be automatically determined if the user does not operate for 3 seconds, and so on!

Development requirements:

It must be developed using logical statements and must be developed using C language.

Recommended function: Switch Meaning: Switch multi-branch function Usage:

#include <REG52.H> //声明包含单片机相关文件

#define u8 unsigned char//声明一个8位的宏定义

#define u16 unsigned int//声明一个16位的宏定义

sbit LED0=P1^0;/声明LED0端口

sbit LED1=P1^1;/声明KED端口

int main(void)//主函数  一个程序的开始

{

   u8 data=0;//声明一个char 类型的变量

          u16i;

     while(1)/循环 括号为1循环,假0循环

        {   

        Switch(data)

          {

                                    case 1: LED0=0;LED1=1;break;

                                    case2: LED0=1;LED1=0;break;

          } 

                          if(data==3){data=0}//Determine whether data is equal to 3, if it is equal to 3, it will immediately equal 0

                          data++;

                          for(i=0;i<5900;i++);//This method is a delay function. Disadvantages: It consumes very much microcontroller resources and is generally not recommended.

        }

}

product photo:

 

Demo video address:

Link: https://pan.baidu.com/s/1I_61yqeoSQlLQq5szW4WcA?pwd=hvue 
Extraction code: hvue 

Code and EDA schematic download address:

Link: https://pan.baidu.com/s/14bVjTVu0I1kMeTJGmWnFTg?pwd=uz5l 
Extraction code: uz5l 

Well, this project ends here. Thank you for your support!

Part of the code:

void GN_3_1(void)
{
//右边  LED10  
//左边  LED26
//上面  LED2
//下面  LED18
    LED26=LED10=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED27=LED11=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED28=LED12=0;
    delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED29=LED13=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED30=LED14=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED31=LED15=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED1=LED16=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED2=LED17=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    

    LED3=LED18=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED4=LED19=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED5=LED20=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED6=LED21=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED7=LED22=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    
    LED8=LED23=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED9=LED24=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED10=LED25=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    
    
    //2    
    LED26=LED10=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED25=LED9=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED24=LED8=0;
    delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED23=LED7=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED22=LED6=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED21=LED5=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED19=LED4=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED18=LED3=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    
    LED17=LED2=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED16=LED1=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED15=LED31=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED14=LED30=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED13=LED29=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    
    LED12=LED28=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED11=LED27=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    LED10=LED26=0;delay_ms(100);
    P0=P1=P2=P3=0XFF;
    
    //
    LED26=LED10=0;delay_ms(100);
    LED27=LED11=0;delay_ms(100);
    LED28=LED12=0;delay_ms(100);
    LED29=LED13=0;delay_ms(100);
    LED30=LED14=0;delay_ms(100);
    LED31=LED15=0;delay_ms(100);
    LED1=LED16=0;delay_ms(100);
    LED2=LED17=0;delay_ms(100);
    LED3=LED18=0;delay_ms(100);
    LED4=LED19=0;delay_ms(100);
    LED5=LED20=0;delay_ms(100);
    LED6=LED21=0;delay_ms(100);
    LED7=LED22=0;delay_ms(100);
    LED8=LED23=0;delay_ms(100);
    LED9=LED24=0;delay_ms(100);
    LED10=LED25=0;delay_ms(100);

    //
    P0=P1=P2=P3=0XFF;
    LED10=LED25=0;delay_ms(100);
    LED9=LED24=0;delay_ms(100);
    LED8=LED23=0;delay_ms(100);
    LED7=LED22=0;delay_ms(100);
    LED6=LED21=0;delay_ms(100);
    LED5=LED20=0;delay_ms(100);
    LED4=LED19=0;delay_ms(100);
    LED3=LED18=0;delay_ms(100);
    LED2=LED17=0;delay_ms(100);
    LED1=LED16=0;delay_ms(100);
    LED31=LED15=0;delay_ms(100);
    LED30=LED14=0;delay_ms(100);
    LED29=LED13=0;delay_ms(100);
    LED28=LED12=0;delay_ms(100);
    LED27=LED11=0;delay_ms(100);
    LED26=LED10=0;delay_ms(100);    
}
int main(void)
{

  bit QD=0;//功能选择变量/退出
  u16 kj=0;//记录系统开机变量 
  bit H=0;
  bit n=1;
  u16 datat=0;//自动确认变量
    qd_cx();
    while(1)
    {
        /************系统开机程序***********/
        kj=0;
        while(n){
        if(key==0){
        kj+=1;
        if(kj==60000){QD=1;n=0;QD_1();}
        }
    }//选择启动功能程序
      while(QD)
      {
          if(key==0&&H==0)
          {
              datat=0;
              delay_ms(10);
              H=1;
              unm+=1;
              if(unm==5){unm=1;}
               kz_GN();
          }if(key==1){H=0;}
         datat+=1;
      if(datat==50000&&unm==1){GN_1=1;QD=0;datat=0;}
      if(datat==50000&&unm==2){GN_2=1;QD=0;datat=0;}
      if(datat==50000&&unm==3){GN_3=1;QD=0;datat=0;}
      if(datat==50000&&unm==4){GN_4=1;QD=0;datat=0;}
  }
//功能1程序
  while(GN_1)
  {
      
      GN1_cx();
      GN_1=0;//退出程序
      QD=1;
     P0=P1=P2=P3=0XFF;
      datat=30000;
      kz_GN();

  }     
  //功能2程序
  while(GN_2)
  {
      GN_cx2_1();
      GN_cx2_2();
      GN_cx2();
      GN_2=0;//退出程序
      QD=1;
      P0=P1=P2=P3=0XFF;
      datat=30000;
      kz_GN();
  }
  while(GN_3)
  {
      
      GN_3_1();
      GN_3=0;//退出程序
      QD=1;
      P0=P1=P2=P3=0XFF;
      datat=30000;
      kz_GN();
  }
  while(GN_4)
  {
       GN1_cx();
      GN_cx2_1();
      GN_cx2_2();
      GN_cx2();
      GN_3_1();
      GN_4=0;//退出程序
      QD=1;
      P0=P1=P2=P3=0XFF;
      datat=30000;
      kz_GN();
  }
   }
    }

参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-06-20 22:57:37
  • +++++++++GPRS data serial port to Ethernet
  • A comprehensive look at the entire family of MSP430 microcontrollers
  • I2C Bus Specification
  • Intelligent Plant Growth LED Lighting Control System
  • New Android feature: Use Google search to find lost phones
  • CircuitPython upgraded to 5.2.0

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

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号