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
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!
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.
}
}
Demo video address:
Link: https://pan.baidu.com/s/1I_61yqeoSQlLQq5szW4WcA?pwd=hvue
Extraction code: hvue
Link: https://pan.baidu.com/s/14bVjTVu0I1kMeTJGmWnFTg?pwd=uz5l
Extraction code: uz5l
Well, this project ends here. Thank you for your support!
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();
}
}
}
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet