STM32密码锁代码
STM32单片机源程序:
- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "usart.h"
- #include "lcd.h"
- #include "myiic.h"
- #include "24cxx.h"
- #include "password.h"
- #include "string.h"
- #include "OLED12864.h"
- unsigned char PSW_MAX_LEN =13 ; //密码最大长度
- unsigned char PSW_SAVE_ADDR = 96; //EEPROM(即24C02器件)中的保存地址
- unsigned char PswCnt = 0;/// //该变量用来记输入密码的个数;
- unsigned char PswSet[13]; //已设定的密码数据
- unsigned char PswBuf1[13]; //密码输入缓冲区1
- unsigned char PswBuf2[13]; //密码输入缓冲区2
- u8 status;//状态字
- u8 Password_Buff[10];
- extern void KeyDriver(void);
- int ad0 = 65530,ad1 = 65532;
- int main(void)
- {
- u8 t;
- unsigned char buf[13];
- Key_Init();//按键初始化必须放在定时器使能函数的前面;因为如果定时器使能之后,2ms就进入中断进行按键刷新;在此之前,必须先进行按键初始化,
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
- TIM3_Int_Init(19,7199);
- TIM_Cmd(TIM3 ,ENABLE);
- delay_init();
- LED_Init();
- uart_init(115200);
- LCD_Init();
-
- AT24CXX_Init();
-
- OLED_Init();
-
- OLED_Fill(0XFF);
- delay_ms(500);
- OLED_Fill(0X00);
- POINT_COLOR=RED;
- AT24CXX_Read(PSW_SAVE_ADDR,buf,PSW_MAX_LEN +1);
- CopyMemory(PswSet, buf, PSW_MAX_LEN);
- LCD_ShowString(30,140,200,16,16,"please input password: ");
- status = 0;
- FillMemory(PswBuf1, '\0', PSW_MAX_LEN);///
- FillMemory(PswBuf2, '\0', PSW_MAX_LEN);///
- while(1)
- {
- KeyDriver();
- if(USART_RX_STA&0x8000)
- {
- if(strcmp((char * )USART_RX_BUF,"lookpassword") == 0)
- {
- // USART_RX_BUF[0] = 0;
-
- AT24CXX_Read(PSW_SAVE_ADDR,Password_Buff,8);
- delay_ms(5);
- printf("下位机密码是\r\n");
- for(t = 0; t<6;t++)
- {
- USART_SendData(USART1,Password_Buff[t]);
- while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待发送结束
-
- }
- printf("\r\n");//插入换行
- }
- USART_RX_STA=0;
-
- }
-
- // OLED_Display_Number_8X16(0,0,ad0/10000);
- //OLED_Display_Number_8X16(0,8,ad0/1000%10);
- //OLED_Display_Number_8X16(0,16,ad0/100%10);
- //OLED_Display_Number_8X16(0,24,ad0/10%10);
- //OLED_Display_Number_8X16(0,32,ad0%10);
- // OLED_Display(0,8,16,16,);
- //OLED_Display(0,0,124,32,TXT);
- OLED_Display(0,0,112,16,TXT2);
- OLED_Display(16,0,112,16,TXT3);
- OLED_Display(32,0,112,16,TXT6);
- //OLED_Display(32,0,32,32,TXT7);
-
- // OLED_Display(0,64,16,16,TXT2);
- //OLED_Display_Number_8X16(16,0,ad1/10000);
- //OLED_Display_Number_8X16(16,8,ad1/1000%10);
- //OLED_Display_Number_8X16(16,16,ad1/100%10);
- //OLED_Display_Number_8X16(16,24,ad1/10%10);
- //OLED_Display_Number_8X16(16,32,ad1%10);
-
- }
- }
- /**/
复制代码
所有资料51hei提供下载:
STM32矩阵按键代码更新.rar
(364.01 KB, 下载次数: 79)
|