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)
2017-12-13 20:27 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|