[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
本程序适用于:1:会C语言,玩过STM32,懂得STM32外部电路的并且会举一反三的同学
2:会C或者C++语言,玩过界面,只需把按键按下变成界面按钮按下,存eeprom变成读写文件即可
3:如果只会C语言,了解一下思想、
4:如果只会硬件,没问题,软件学学也没想象中的那么难
void set_password(void) { char i,j = 0; char password_buf[6] = {0};
//临时存储,为了把密码存储到eeprom int m=0; //用作密码成功判断 int k = -1;//密码,范围0~9 char store[50]
= {0}; //为了lcd显示存储的数据 _REINPUT: delay(MSec(80));
//延时函数,需自己封装,如带操作系统,根据系统性质编写,如若无系统,两个for循环也行
LCD_Show("请按键设置密码:");//LCD显示函数,需自己封装 j = 0; m = 0; while(1) { k = -1;
if(scan_key_down("PE1")) //判断按键按下函数,自己根据STM32的IO性质以及实际硬件电路编写 { delay(MSec(50));
if(scan_key_down("PE1")) { for(i=0;i<300;i++) { delay(MSec(100));
if(((i%5)==0)&&(i!=0)) //5的倍数才能进if,也起延时作用 { k++; if(k>9) { k = 0; //限制密码范围为9以内
} sprintf(store,"密码第%d位: %d",j+1,k); // 配合LCD输出 LCD_Show(store); }
if(read_IO("PE1")==1) //检测松开按键函数,松开按键跳出循环,k为密码的一位 { break; } } m++;
password_buf[j] = k; //密码存储 j++; if(j>5) //限制密码位数 { j=0; k=-1; } } }
if(scan_key_down("PE2"))//按下按键选定模式,用另一个按键 { delay(MSec(50));
if(scan_key_down("PE2")) { if(m%6==0&&m!=0) { LCD_Show("密码设置OK!");
for(i=0;i<6;i++) { printf("密码第%d位:%d\n",i+1,passwordBuf[i]);
eeprom_wr8((char)password_buf[i],900+i); //密码写进eeprom delay(MSec(10)); }
delay(Sec(2)); } else { LCD_Show("密码设置NG!"); LCD_Show("请重新输入密码!");
delay(Sec(2)); goto _REINPUT; //调回开始重新执行 } break; } } delay(MSec(20)); } }
欢迎爱技术的小伙伴一起交流,如有错误,希望告知,一起改正,共同进步。