1. Experimental tasks
(1. When powered on, the display shows “0”
(2. When the button is pressed for the first time, "D1" is displayed; when it is pressed for the second time, "D1D2" is displayed; when it is pressed for the third time, "D1D2D3" is displayed. When all 8 are displayed, a "beep" tone is given when the button is pressed again.
2. Circuit diagram
Figure 4.23.1
3. Hardware connection on the system board
(1. Connect the P1.0 port in the "MCU System" area to the SPK IN port in the "Audio Amplifier Module" area with a wire;
(2. Connect the P3.0-P3.7 ports in the "MCU System" area to the C1-C4 R1-R4 ports in the "4X4 Column Keyboard" area using an 8-core cable;
(3. Connect the P0.0-P0.7 ports in the "MCU System" area to the A-H ports in the "Dynamic Digital Display" area using an 8-core cable;
(4. Connect the P2.0-P2.7 ports in the "MCU System:" area to the S1-S8 ports in the "Dynamic Digital Display" area using an 8-core cable;
4. Related programming content
(1. Determinant keyboard input and key function setting;
(2. Dynamic digital display;
(3. Digital display processing;
5. Assembly source program
(slightly)
6. C language source program
#include
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
unsigned char code dispbitcode[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char dispbuf[8]={0,16,16,16,16,16,16,16};
unsigned char dispbitcount;
unsigned char temp;
unsigned char i,j;
unsigned char key;
unsigned char keypos;
bit alarmflag;
void change(unsigned char *p,unsigned char count)
{
while(count>0)
{
*(p+count)=*(p+count-1);
count--;
}
} [page]
void main(void)
{
TMOD=0x01;
TH0=(65536-4000) / 256;
TL0=(65536-4000) % 256;
TR0=1;
ET0=1;
EA=1;
while(1)
{
P3=0xff;
P3_4=0;
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f)
{
for(i=50;i>0;i--)
for(j=200;j>0;j--);
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f)
{
temp=P3;
temp=temp & 0x0f;
switch(temp)
{
case 0x0e:
key=7;
break;
case 0x0d:
key=8;
break;
case 0x0b:
key=9;
break;
case 0x07:
key=10;
break;
}
if ((key>=0) && (key<10))
{
keypos++;
if(keypos<8)
{
change(dispbuf,keypos);
dispbuf[0]=key;
}
else
{
keypos=8;
alarmflag=1;
}
}
temp=P3;
P1_0=~P1_0;
temp=temp & 0x0f;
while(temp!=0x0f)
{
temp=P3;
temp=temp & 0x0f;
}
alarmflag=0;
}
}
P3=0xff;
P3_5=0;
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f)
{
for(i=50;i>0;i--)
for(j=200;j>0;j--);
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f)
{
temp=P3;
temp=temp & 0x0f;
switch(temp)
{
case 0x0e:
key=4;
break;
case 0x0d:
key=5;
break;
case 0x0b:
key=6;
break;
case 0x07:
key=11;
break;
}
if ((key>=0) && (key<10))
{
keypos++;
if(keypos<8)
{
change(dispbuf,keypos);
dispbuf[0]=key;
}
else
{
keypos=8;
alarmflag=1;
}
}
temp=P3;
P1_0=~P1_0;
temp=temp & 0x0f;
while(temp!=0x0f)
{
temp=P3;
temp=temp & 0x0f;
}
alarmflag=0;
}
} [page]
P3=0xff;
P3_6=0;
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f)
{
for(i=50;i>0;i--)
for(j=200;j>0;j--);
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f)
{
temp=P3;
temp=temp & 0x0f;
switch(temp)
{
case 0x0e:
key=1;
break;
case 0x0d:
key=2;
break;
case 0x0b:
key=3;
break;
case 0x07:
key=12;
break;
}
if ((key>=0) && (key<10))
{
keypos++;
if(keypos<8)
{
change(dispbuf,keypos);
dispbuf[0]=key;
}
else
{
keypos=8;
alarmflag=1;
}
}
temp=P3;
P1_0=~P1_0;
temp=temp & 0x0f;
while(temp!=0x0f)
{
temp=P3;
temp=temp & 0x0f;
}
alarmflag=0;
}
}
P3=0xff;
P3_7=0;
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f)
{
for(i=50;i>0;i--)
for(j=200;j>0;j--);
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f)
{
temp=P3;
temp=temp & 0x0f;
switch(temp)
{
case 0x0e:
key=0;
break;
case 0x0d:
key=13;
break;
case 0x0b:
key=14;
break;
case 0x07:
key=15;
break;
}
if ((key>=0) && (key<10))
{
keypos++;
if(keypos<8)
{
change(dispbuf,keypos);
dispbuf[0]=key;
}
else
{
keypos=8;
alarmflag=1;
}
}
temp=P3;
P1_0=~P1_0;
temp=temp & 0x0f;
while(temp!=0x0f)
{
temp=P3;
temp=temp & 0x0f;
}
alarmflag=0;
}
}
}
}
void t0(void) interrupt 1 using 0
{
TH0=(65536-4000) / 256;
TL0=(65536-4000) % 256;
P0=dispcode[dispbuf[dispbitcount]];
P2=dispbitcode[dispbitcount];
dispbitcount++;
if (dispbitcount==8)
{
dispbitcount=0;
}
if (alarmflag==1)
{
P1_1=~P1_1;
}
}
Previous article:Design of single chip digital clock
Next article:DS18B20 Digital Thermometer Microcontroller Interface Application
Recommended ReadingLatest update time:2024-11-16 22:42
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- 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
- ST's sensors can be purchased at the STM32 Tmall official flagship store
- "Dating in Spring" + "Just Strolling"
- How to build a Keil project using the LPC8xx ROM?
- C2000 CLA FAQ: Architecture and Configuration
- Analysis of China Mobile and China Unicom packages: choosing the wrong package will lead to wasted money
- New infrared temperature measurement thermal imager is coming! AutoNavi holds a press conference in Beijing!
- RF amplifier performance test
- What kind of feedback is introduced in the following circuit?
- What is the significance of connecting two capacitors in series?
- Storage time of different surface treatment processes for circuit boards