Learning from the experience of predecessors, the problem of too many diodes was optimized. At present, 6 keys can be connected without diodes, 12 keys can be connected with 2 diodes, 18 keys can be connected with 6 diodes, and 21 keys can be connected with 9 diodes. The 22nd key should occupy 3 diodes alone, which is the least cost-effective.
The experiment uses 89S51 for the test. The circuit wiring is P1.2, P1.3, P1.4 connected to the keyboard, and P1.0 connected to the display.
(Original file name: GIF.gif)
(Original file name SC00015.JPG)
(Original file name SC00016.jpg)
/*==========================================================================*
* 3 IO connection recognition 22 keys test program *
* ------------------------------------------------ *
* MCU: AT89C2051 *
* OSC: 12M cysytel *
* Program design: Cowboy *
* Program version: V1.0 *
*========================================================================================*/
#include
//================== IO port line connection==================
sbit Bus = P1^0;
sbit IO_a = P1^4;
sbit IO_b = P1^3;
sbit IO_c = P1^2;
//==================== Variable declaration====================
unsigned char Disp_buf[3];
unsigned char Di g;
unsigned char Key_count;
unsigned char bdata Key_state;
sbit KB0 = Key_state^0;
sbit KB1 = Key_state^1;
sbit KB2 = Key_state^2;
sbit KB3 = Key_state^3;
sbit KB4 = Key_state^4;
sbit KB5 = Key_state^5;
//================= Table data====================
code unsigned char LED_font[24]=
{
0x84,0x9f,0xa2,0x8a,0x99,0xc8,0xc0,0x9e,0x80, //012345678
0x88,0x90,0xc1,0xe4,0x83,0xe0,0xf0,0xff,0xfb, //9abcdef -
};
code unsigned char Key_tab[64]= //Key code mapping table
{// 0 1 2 3 4 5 6 7 8 9
22, 0, 2, 0, 0, 0, 0, 0, 0, 0, //4X 0
, 5, 0, 0, 0, 0, 0, 0, //5X
16,12
, 7, 0, 0, 0, //6X 0, 0, 0, 0, 0, 0, 0,
0, //7X 0, 0, 0, 0, 0, 0, 0, 0, 0
, // 8X 0 , ... i; Key_count --; //Scanning order Key_count &= 3; switch (Key_count) //Process in order { case 2: //First round of scanning KB0 = IO_b; KB1 = IO_c; IO_a = 1; IO_b = 0; break; case 1: //Every second round of scanning
KB2 = IO_c;
KB3 = IO_a;
IO_b = 1;
IO_c = 0;
break;
case 0: //Scan every three rounds
KB4 = IO_a;
KB5 = IO_b;
IO_c = 1;
break;
default: //Scan every four rounds
if (!IO_a) KB0 = 0;
if (!IO_b) KB2 = 0;
if (!IO_c) KB4 = 0;
IO_a = 0;
//======Update display buffer=======
i = Key_tab[Key_state];
if (i == 0)
{
Disp_buf[2] = 0x11; //Display three horizontal lines
Disp_buf[1] = 0x11;
Disp_buf[0] = 0x11;
}
else
{
Disp_buf[2] = 0x0c; //Character "C"
Disp_buf[1] = i / 10; //ten digits of key code
Disp_buf[0] = B; //one digit of key code }
Key_state =
0 ;
}
} /
* = ... (!Dat) Bus = 0; else { Bus = 0; Bus = 1; } while(--i); //Delay 8us Bus = 1; } //=============== Bus driver ================= void Bus_drive() { unsigned char i = 0; unsigned char Sdat; Send_bit(1); //Bit6 blanking do Bus = 1; while(--i); //Delay 768us do Bus = 0; while(--i); //Delay 768us Bus = 1; Sdat = LED_font[Disp_buf[Dig++]]; //Get display data Send_bit(Sdat & 0x01); //Send bit 0 Send_bit(Sdat & 0x02); //Send bit 1 Send_bit(Sdat & 0x04); //Send bit 2 Send_bit(Sdat & 0x08); //Send bit 3 Send_bit(Sdat & 0x10); //Send bit 4 Send_bit(Sdat & 0x20); //Send bit 5 Send_bit(Dig & 0x01); //Send bit select 1 Send_bit(Dig & 0x02); //Send bit select 2 while(--i); //Delay 512us Send_bit(Sdat & 0x40); //Send bit 6 for (i = 7;i> 0;i--) Send_bit(1); //Move bit 6 to Dout if (Dig == 3) Dig = 0; }
/ * =
... / * = ...
Previous article:3 IO ports scan 16 keys
Next article:C51 interrupts and using interrupt priorities
- 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
- ASML predicts that its revenue in 2030 will exceed 457 billion yuan! Gross profit margin 56-60%
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- 【Qinheng RISC-V core CH582】BLE lighting
- EEWORLD University ---- Altium Designer 4-layer smart car complete PCB design video tutorial
- How to solve the problem of insufficient ports of 51 MCU? (without adding expansion chips)
- 【TI recommended course】#What is I2C design tool? #
- How to determine the chip output current of the op amp
- Found a bug in threadx with stmcube
- [Simulation-Physical-Test] 790 to 960 MHz Broadband 600W LDMOS Asymmetric Doherty Amplifier
- TRUWB digital receiver performance based on ADC and its FPGA implementation.pdf
- Can the number of pulses of an ultrasonic generator driven by a transformer be accurately controlled?
- The helper2416 development board driver failed to create a device node