#include //Call the header file, you can go to the PICC18 software to find PIC18FXX2.H
while(1)
{
temp=keyscan();
}
Keywords:PIC18F452
Reference address:PIC18F452 MCU Matrix Keyboard
__CONFIG(1,XT); //Crystal oscillator is external 4M
__CONFIG(2,WDTDIS); //Watchdog off
__CONFIG(4,LVPDIS); //Disable low voltage programming
#define B7 RB7
#define B6 RB6
#define B5 RB5
#define B4 RB4
#define B3 RB3
#define B2 RB2
#define B1 RB1
#define B0 RB0
#define B PORTB
#define D PORTD
#define E2 RE2
#define E1 RE1
#define E0 RE0
#define C7 RC7
char shuma[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delayms(int x)
{
int i,j;
for(i=0;i<=30;i++)
for(j=0;j<=x;j++);
}
int keyscan()
{
B=0x7f;
if(B3==0)
{
delayms(5);
return 16;
}
if(B2==0)
{
delayms(5);
return 12;
}
if(B1==0)
{
delayms(5);
return 8;
}
if(B0==0)
{
delayms(5);
return 4;
}
delayms(5);
B=0xbf;
if(B3==0)
{
delayms(5);
return 15;
}
if(B2==0)
{
delayms(5);
return 11;
}
if(B1==0)
{
delayms(5);
return 7;
}
if(B0==0)
{
delayms(5);
return 3;
}
delayms(5);
B=0xdf;
if(B3==0)
{
delayms(5);
return 14;
}
if(B2==0)
{
delayms(5);
return 10;
}
if(B1==0)
{
delayms(5);
return 6;
}
if(B0==0)
{
delayms(5);
return 2;
}
delayms(5);
B=0xef;
if(B3==0)
{
delayms(5);
return 13;
}
if(B2==0)
{
delayms(5);
return 9;
}
if(B1==0)
{
delayms(5);
return 5;
}
if(B0==0)
{
delayms(5);
return 1;
}
delayms(5);
}
void display(int num)
{
int ge,shi;
ge=whether;
shi=num/10;
E2=0;
E1=1;E0=1;
if(shi==0&&ge==0)
D=0x00;
else D=shuma[ge];
delayms(2);
E1=1;E0=0;
if(shi==0)
D=0x00;
else D=steal[down];
delayms(2);
D=0x00;
delayms(2);
}
void main(void)
{
int temp,num=0;
ADCON1=0X06; //All IO are digital ports, analog input is prohibited
TRISB=0X0f;
TRISD=0x00;
THREE=0x00;
TRISC=0x00;
switch(temp)
{
case 1:case 2:case 3:case 4:case 5:case 6:case 7:case 8:case 9:case 10:case 11:case 12:case 13:case 14:case 15:case 16:num=temp;C7=1;break;
default:C7=0;break;
}
display(num);
}
Using the input and output changes of an I/O port, it is somewhat similar to dynamic scanning, and each row is checked in turn to see if a key is pressed.
Effect: Press a key and the number of the key will be displayed on the digital tube.
Previous article:PIC LCD1602 Display
Next article:PIC18F452 MCU Matrix Keyboard
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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
MoreDaily News
- 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
Guess you like
- There is a large supply of microcontrollers!
- Share the C language program of FIR filter implemented by MSP430 microcontroller
- [2022 Digi-Key Innovation Design Competition] CAN Communication Data Display Terminal
- How to design high frequency (>100K) ultrasonic sensor processing circuit
- A design scheme of smart water meter controlled by NFC
- Oscilloscope waveform jitter can be turned into stable waveform by setting trigger properly
- How to measure the noise floor of an oscilloscope
- PLC online monitoring control cloud configuration software SCADA
- Is this dime-sized millimeter-wave sensor evaluation board worth trying?
- Xintang M2354 Fault Injection Attack Protection