#include #define uint unsigned int #define uchar unsigned char #define output P1 #define input P1 //Easy to transplant to other circuit boards, my circuit uses P1 port as keyboard input interface //Define 16 buttons enum KEY{key0,key1,key2,key3,key4,key5,key6,key7,key8,key9,key10,key11,key12,key13,key14,key15}; uchar code table[]={ //array definition, display digital tube 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00}; unsigned int code Freqtab[] = { //initial value of timing half cycle 64021,64103,64260,64400, //Bass 3 4 5 6 64524,64580,64684,64777, //Bass 7, Midrange 1 2 3 64820,64898,64968,65030, // Middle 4 5 6 7 65058,65110,65157,65178}; //treble 1 2 3 4 uint FreqTemp; //The buzzer sound is not very good, so we use a speaker, connected to P3.7 port sbit SPEAK = P3^7; void delay1ms(uint n) //error 0us, delay n milliseconds { uint a,b,c; for(c=n;c>0;c--) for(b=199;b>0;b--) for(a=1;a>0;a--); } uint key_input(void) { uchar temp1, temp2; //temporarily save the read row or column uchar num = 16; //Return the value of the key output = 0x0f; temp1 = input; //Read the line first if(0x0f != temp1) //button pressed { delay1ms(5); //delay to eliminate jitter temp1 = input; // read line again if(0x0f != temp1) //Indicates that the button is pressed { temp1 = temp1 & 0x0f; //Retain the lower 4 bits output = 0xf0; //Ready to read the column delay1ms(1); //Delay to prevent the next sentence from being missed temp2 = input; //Read the column directly temp2 = temp2 & 0xf0; //Reserve the upper 4 bits temp1 = temp1 | temp2; //Merge the values of temp1 and temp2 } } switch(temp1) { case 0xee:num=0;break; case 0xde:num=1;break; case 0xbe:num=2;break; case 0x7e:num=3;break; case 0xed:num=4;break; case 0xdd:num=5;break; case 0xbd:num=6;break; case 0x7d:num=7;break; case 0xeb:num=8;break; case 0xdb:num=9;break; case 0xbb:num=10;break; case 0x7b:num=11;break; case 0xe7:num=12;break; case 0xd7:num=13;break; case 0xb7:num=14;break; case 0x77:num=15;break; default:break; } return num; } void T0_INT(void) interrupt 1 { TL0 = FreqTemp; //Load the initial value of the timing half cycle TH0 = FreqTemp >> 8; SPEAK = ~SPEAK; //pronunciation } int main() { TMOD = 0X01; //Timer T0 is set to mode 1 EA = 1; ET0 = 1; TR0 = 0; while(1) { uint num,temp; num = key_input(); temp = num; P0 = table[num]; if(16 != num) { FreqTemp = Freqtab[num]; TR0 = 1; while(0xf0 != output); //Detect button release TR0 = 0; SPEAK = 1; } } return 0; }
Previous article:Design of temperature and humidity monitoring system based on single chip microcomputer (program)
Next article:Design of digital clock system based on single chip microcomputer
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
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
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Problem with the serial port receiving data of stm32?
- TVP5150 video decoding chip debugging summary
- Finally someone has explained smart manufacturing and Industry 4.0 clearly
- Share a wireless Modbus communication routine of Inovance PLC with source code and instructions, download at the required speed
- Hangshun chip-HK32F030F4P6
- Graduation project on designing a car passive pedestrian protection control system based on AT89C51 single chip pressure sensor
- [Sipeed LicheeRV 86 Panel Review]——Review Summary
- The other party pressed a key during a call! How can I identify the key pressed by the other party?
- Homemade STEVAL-IPM05F 3Sh board: FOC motor control 400V/8A non-sensing/sensing Hall/sensing encoder and other reference programs...
- Application of supercapacitors in smart water meters