PIC18F452 MCU Matrix Keyboard

Publisher:数据梦想Latest update time:2016-04-11 Source: eefocusKeywords:PIC18F452 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include      //Call the header file, you can go to the PICC18 software to find PIC18FXX2.H
__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;
  while(1)
  {
    temp=keyscan();
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.
Keywords:PIC18F452 Reference address:PIC18F452 MCU Matrix Keyboard

Previous article:PIC LCD1602 Display
Next article:PIC18F452 MCU Matrix Keyboard

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号