蓝桥杯第十三届密码切换STM32正点原子例程

#include "delay.h"
#include "key.h"
#include "sys.h"
#include "lcd.h"
#include "usart.h"    
#include "usmart.h"     
#include "led.h"
#include "beep.h"

     vu8 key=0;

int t=0; int i=0;int j=0; 
int b1=0; int b2=0; int b3=0;
int Password_three[3]={1,1,1};

void sta_show()
{
  LCD_ShowString(190,340,200,80,16,"sta");    
     LCD_ShowString(150,360,200,80,16,"F:2000HZ");
    LCD_ShowString(150,380,200,80,16,"D:10%"); 
  LCD_ShowString(150,400,200,80,16,"         ");
    
}

void key0_password()
{
      b1++;
        if(b1>9) b1=0;
        LCD_ShowxNum(174,360,b1,1,16,0);
}

void key1_password()
{
      b2++;
        if(b2>9) b2=0;        
    LCD_ShowxNum(174,380,b2,1,16,0);
}

void key2_password()
{
      b3++;
        if(b3>9) b3=0;    
    LCD_ShowxNum(174,400,b3,1,16,0);
}

void keyup_password()
{
 if(Password_three[0]!=b1&&Password_three[1]!=b2&&Password_three[2]!=b3&&key==WKUP_PRES)
    {
       t++;
        LCD_ShowxNum(150,450,t,1,16,0);
        if(t>=3)
        {
            for(i=0;i<25;i++)
            {
          LED1=0;
    //        BEEP=!BEEP;    
            delay_ms(100);
            LED1=1;
      delay_ms(100);                
            }LED1=1;
        }
    }    
  else    if(Password_three[0]==b1&&Password_three[1]==b2&&Password_three[2]==b3&&key==WKUP_PRES)
    {
            for(j=0;j<25;j++)
            {    
                sta_show();
          LED0=0;
    //        BEEP=!BEEP;    
            delay_ms(100);
            LED0=1;
      delay_ms(100);                
            }LED0=1;
            

 b1=0; b2=0; b3=0;
    LCD_ShowString(190,340,200,80,16,"PSD");    
    LCD_ShowString(150,360,200,80,16,"B1:@    ");
    LCD_ShowString(150,380,200,80,16,"B2:@  ");
    LCD_ShowString(150,400,200,80,16,"B3:@");

    }
}


 int  main(void)
 {
     
    delay_init();             //延时函数初始化      
    LCD_Init();                 
  LED_Init();
    KEY_Init();
    BEEP_Init();
    POINT_COLOR=WHITE;     
     
    LCD_ShowString(190,340,200,80,16,"PSD");    
    LCD_ShowString(150,360,200,80,16,"B1:@");
    LCD_ShowString(150,380,200,80,16,"B2:@");
    LCD_ShowString(150,400,200,80,16,"B3:@");
    
//    LCD_ShowxNum(174,360,b1,1,16,0);
//    LCD_ShowxNum(174,380,b2,1,16,0);
//    LCD_ShowxNum(174,400,b3,1,16,0);

 
    while(1)
    {    
//                    BEEP=!BEEP;        

    key=KEY_Scan(0); 
    switch(key)
    {
        case KEY0_PRES: key0_password();  break;
        case KEY1_PRES: key1_password();  break;
    case KEY2_PRES: key2_password();  break;
        case WKUP_PRES: keyup_password(); break;
    }        
    
    }      
 }

 
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值