1. Experimental task:
According to the set password, use two buttons to input the password. When the password is entered correctly, the lock will open. If the password is entered incorrectly three times, the button will be locked for 3 seconds and an alarm will sound. The button lock function will not be opened until no button is pressed for 3 times. Otherwise, if there is still a button pressed within 3 seconds, the button will be locked again for 3 seconds and an alarm will sound.
2. Circuit diagram
Figure 4.32.1
3. Hardware connection on the system board
(1). Connect P0.0/AD0 in the "MCU system" area to the SPK IN terminal in the "Audio amplifier module" area with a wire;
(2). Connect the SPK OUT terminal in the "Audio amplifier module" area to the speaker;
(3). Connect P2.0/A8-P2.7/A15 in the "MCU system" area to any ABCDEFGH terminal in the "Four-way static digital display" area with an 8-core cable;
(4). Connect P1.0 in the "MCU system" area to the L1 terminal in the "Eight-way LED module" area with a wire;
(5). Connect P3.6/WR and P3.7/RD in the "MCU system" area to the SP1 and SP2 terminals in the "Stand-alone keyboard" area with a wire;
4. Program design content
(1). Password setting: In this program, the password is fixed in the program memory ROM. Assume that the preset password is "12345", a total of 5 digits.
(2) Password input problem:
Since two keys are used to complete the password input, one of the keys is a function key and the other is a numeric key. During the input process, first enter the length of the password, then enter the number of digits of the password according to the length of the password, until all passwords of all lengths have been entered; or enter the confirmation function key to complete the password input process. Enter the password judgment and comparison processing state and give the corresponding processing process.
(3) Key prohibition function: During initialization, it is allowed to enter the password by key. When a key is pressed and starts to enter the key recognition state, the key prohibition function is activated, but the activation state occurs when the password is entered incorrectly 3 times.
5. C language source program
#include
unsigned char code ps[]={1,2,3,4,5};
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x40};
unsigned char pslen=9;
unsigned char templen ;
unsigned char digit; unsigned
char funcount;
unsigned char digitcount; unsigned char
psbuf[9];
bit cmpflag;
bit hibitflag
; bit errorflag; bit
rightflag; unsigned int
second3; unsigned
int aa ;
unsigned int bb ; oka; unsigned char okb; void main(void) { unsigned char i,j; P2=dispcode[digitcount]; TMOD=0x01; TH0=(65536-500)/256; TL0=(65536-500)%6; == 0 ) // function key { for(i=10;i>0;i--) for(j=248;j>0;j--); if (P3_6==0) { if (hibitflag==0) { funcount ++; if(funcount==pslen+2) { funcount=0; cmpflag=1; } P1=dispcode[funcount]; } else { second3=0 ; } while(P3_6==0); } } if(P3_7==0) //digit key
{
for(i=10;i>0;i--)
for(j=248;j>0;j--);
if(P3_7==0)
{
if(hibitflag==0)
{
digitcount++;
if( digitcount==10)
{
digitcount=0;
}
P2=dispcode[digitcount];
if(funcount==1)
{
pslen=digitcount;
templen=pslen;
}
else if(funcount>1)
{
psbuf[funcount-2]= digitcount;
}
}
else
{
second3=0;
}
while(P3_7==0);
}
}
}
else
{
cmpflag=0;
for(i=0;i
{
if(ps[i]!=psbuf[i])
{
hibitflag=1;
i=pslen;
errorflag=1;
rightflag=0;
cmpflag=0;
second3=0;
goto a;
}
}
cc=0;
errorflag=0;
rightflag=1;
hibitflag=0;
a: cmpflag=0;
}
}
}
void t0(void) interrupt 1 using 0
{
TH0=(65536-500)/256;
TL0=(65536-500)%6;
if((errorflag==1) && (rightflag==0))
{
bb++ ;
if(bb==800)
{
bb=0;
alarmflag=~alarmflag;
}
if(alarmflag==1)
{
P0_0=~P0_0;
}
aa++;
if(aa==800)
{
aa=0;
P0_1=~ P0_1;
}
second3++;
if(second3==6400)
{
second3=0;
hibitflag=0;
errorflag=0;
rightflag=0;
cmpflag=0;
P0_1=1;
alarmflag=0;
bb=0;
aa=0;
}
}
if((errorflag==0) && (rightflag==1))
{
P0_1=0;
cc++;
if(cc<1000)
{
okflag=1;
}
else if(cc<2000)
{
okflag=0;
}
else
{
errorflag=0;
rightflag=0;
hibitflag=0;
cmpflag=0;
P0_1=1;
cc=0;
oka=0;
okb=0;
okflag=0;
P0_0=1;
}
if(okflag==1)
{
oka++ ;
if(oka==2)
{
oka=0;
P0_0=~P0_0;
}
}
else
{
okb++;
if(okb==3)
{
okb=0;
P0_0=~P0_0;
}
}
}
}
Previous article:Design a four-digit thermometer
Next article:DIY 6-digit frequency meter
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Please analyze the diode in this circuit.
- How to draw a Karnaugh map for a logical expression with more than 4 variables
- How semiconductor technology changes the design of automotive lighting hardware
- Advantages of Sub-1 GHz Connectivity for Grid Asset Monitoring, Protection and Control
- This distance is less than 0.254mm.
- Incremental encoder engineering
- EEWORLD University ---- Open Course on Quadcopters
- [XMC4800 Relax EtherCAT Kit Review] + Getting started with DAVE, a preliminary exploration of simple UART applications
- A 45-year-old programmer posted: I am proficient in various technical systems, but it is difficult to get an interview opportunity
- Doubts about optocoupler drive circuit