4*4 keyboard input, can change password, 24C02 is used to store password. I use 6 digits. You can also use more digits by changing the corresponding variables. It's very simple. I have written the initial password 2 3 4 6 7 0 in 24C02 in advance. Debugging is successful and can be used directly. STC89C51RC single chip microcomputer, universal board welding
// The data {2,3,4,6,7,0} has been written to 24C02 on the experimental board
#include
#include
#define uchar unsigned char
#define uint unsigned int
char code SKEY[16]={4,8,11,15,3,7,10,14,2,6,0,13,1,5,9,12};
char code act[4]={0xfe,0xfd,0xfb,0xf7};
char data rd[6]={1,9,8,5,1,1};
char ct=0;
sbit contel=P2^1;
sbit cin=P0^3;
sbit set=P0^4;
sbit wrong=P0^5;
sbit SDA=P2^6;
sbit SCL=P2^7;
bdata char com_data;
sbit mos_bit=com_data^7;
sbit low_bit=com_data^0;
void delay_iic(int n);
uchar rd_24c01(char a);
void wr_24c01(char a,char b);
void wtsec();
/**************************************/
void delay_iic(int n)
{
int
for(i= 1;i
void delay(unsigned int k)
{
unsigned int data i,j;
for(i=0;i
for(j=0;j<121;j++)
{;}
}
}
//************************************
void start()
{
SDA=1;_nop_();_nop_();_nop_();_nop_();
SCL=1;_nop_();_nop_();_nop_();_nop_(); SDA
=0;_nop_();_nop_();_nop_();_nop_( ) ;
_();_nop_();_nop_ ();_nop_(); SCL = 1 ;_nop_();_nop_();_nop_();
_ nop_(); _nop_() ;_nop_() ; SCL=0;_nop_();_nop_();_nop_();_nop_(); } //****************************** void shift8(char a) { data uchar i; com_data=a; for(i=0;i<8;i++) { SDA=mos_bit; SCL=1;_nop_();_nop_();_nop_();_nop_();_nop_();_ nop_(); SCL=0;_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); com_data=com_data*2; } } //****************** uchar rd_24c01(char a) { data uchar i,command; SDA=1;_nop_();_nop_();_nop_();_no p_(); SCL=0;_nop_();_nop_();_nop_();_nop_(); start(); command=160; shift8(command); ack(); shift8(a); ack(); start(); command=161; shift8(command); ack(); SDA=1;_nop_();_nop_();_nop_();_nop_(); for(i=0;i<8;i++) {
com_data=com_data*2;
SCL=1;_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
low_bit=SDA;
SCL=0;_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();
}
stop();
return(com_data);
}
//******************
void wr_24c01(char a,char b)
{
data uchar command;
_nop_();_nop_();_nop_();_nop_();_nop_();
SDA=1;_nop_();_nop_();_nop_();_nop_();
SCL=0;_nop_();_nop_();_nop_();_nop_();
start();
command=160;
shift8(command);
ack();
shift8(a);
ack();
shift8(b);
ack();
stop();
_nop_();_nop_();_nop_();_nop_();_nop_();
}
//Keyboard Scan
char scan_key(void)
{
char i,j,in,ini=0,inj=0,temp,del;
bit find=0;
P1=0x0f;
temp=P1;
if(temp!=0x0f) //The key is pressed Release
for(del=10;del>0;del--); //Keyboard debounce delay
if(temp!=0x0f)
{
for(i=0;i<4;i++)
{
P1=act;
in =P1;
in=in>>4;
in=in|0xf0;
for(j=0;j<4;j++)
{
if(act[j]==in)
{find=1;
inj=j;ini= i;
}
}
}
}
if(find==0)return -1;
return (ini*4+inj);
}
//Input function
void put_secret()
{
char wrt[6];
char et,ft;
char wt,x=1;
char * p,*t;
p=rd;
t=wrt;
for(wt=0;wt<6;)
{
et=scan_key();
if(et!=-1)
{
wrt[wt]=SKEY[et];
wt=wt+x;
cin=0;
delay(200);
cin=1;
}
}
ct=0;
for (ft=0;ft<6;)
{
if(wrt==rd)
{ct=ct+x ; }
ft=ft+x;
}
if(ct==6)
contel=1;
else
wrong=0;
}
void wtsec()
{
char t[6];
char e,f,i=10;
char w,x =1;
char *m,*n;
m=rd;
n=t;
for(w=0;w<6;)
{
e=scan_key();
if(e!=-1)
{
t[w]=SKEY[e] ;
w=w+x;
cin=0;
delay(200);
cin=1;
}
}
for (f=0;f<6;)
{
wr_24c01(i,t[f]);
delay_iic(250);
rd [f]=rd_24c01(i);
delay_iic(250);
f=f+x;
i=i+x;
}
}
//==================== ========
void main(void)
{
char c,f, key_val,x=1,ii=10;
contel=0;
wrong=1;
cin=1;
set=0;
delay(2000);
for (f=0;f<6;)
{
rd[ f]=rd_24c01(ii);
delay_iic(250);
f=f+x;
ii=ii+x;
}
set=1;
delay(1000);
while(1)
{
c=scan_key();
if(c! =-1)
key_val=SKEY[c];
switch(key_val)
{
case 12:cin=0;delay(1000);cin=1;put_secret();break ;
case 13:ct=0;wrong=1;contel =0;cin=1;set=1;break;
case 14:if(ct==6){set=0;wtsec();set=1;} set=1;ct=0;break;
default:break ;
}
}
}
Previous article:Application of eeprom inside STC89C52 MCU
Next article:7219 chip drives LED electronic clock
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- FPGA Deep Analysis.pdf
- C51 uses macro definition to replace printf function
- Understanding the CAN bus from the bottom up
- Cheats
- [STM32WB55 Review] +USB Dongle Bricked
- STM32F429 USB_OTG_FS (PA11, PA12) read USB disk problem
- Digital Signal Processing Tutorial - Second Edition.asp
- PoE and PoE+, an article to understand Power over Ethernet
- How to control trace impedance of PCB for signal integrity?
- Disassembling the USB wireless network card, the circuit scheme is very classic