"Beginner's C51 Self-study Notes" 8X8 keyboard (Line and Line or)

Publisher:风暴使者Latest update time:2022-04-22 Source: eefocusKeywords:C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In the keyboard circuit, there is this line and this thing,

Line AND and Line OR: A line and a switch, one end is high level and the other end is low level. When the switch is closed, the entire line will become low level. In general, there is a line AND relationship. As long as one end is low level and the switch is closed, the entire line will be pulled low. This is line AND; one end is Z (high configuration). After the switch is closed, the other end is high level and the entire line is high and low level, and vice versa. This is line OR;

How to program: First, P3=11110000 (11110000 from bottom to top in the figure), assuming that S1 is pressed, the upper four bits become 1110 (line AND) (ignore the lower four bits). At this time, you have determined that a key in the first column of the keyboard is pressed; then set P3=11101111, change the lower four bits to 1 (the upper four bits remain unchanged), and you have not released the key yet, because of line AND, P3=11101110; (To determine whether the key is pressed: use &0xf0)

#include

#define uchar unsigned char 

#define uint unsigned int 

 

unsigned char code smg_du[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};

unsigned char code smg_we[]={0x08,0x18,0x28,0x38,0x48,0x58,0x68,0x78};

 

//************************************************

//Delay function, at 12MHz crystal frequency

//About 50us delay

//************************************************

void delay_50us(uint t)

{

uchar j;

for(;t>0;t--)

        for(j=19;j>0;j--);

}

 

//************************************************

//Delay function, at 12MHz crystal frequency

//About 50ms delay

//************************************************

void delay_50ms(uint t)

{

uint j;

for(;t>0;t--)

for(j=6245;j>0;j--);

 

void main()

{

uchar key_l,key_h;

uchar key;

while(1)

{

P3=0xf0;//11110000

key_l=P3;

key_l=key_l&0xf0; //Determine whether the key is pressed

if(key_l!=0xf0)

{

delay_50us(100);//debounce

if(key_l!=0xf0)//Judge again

{

key_l=P3&0xf0;

key_l=key_l|0x0f;//11101111 (prepare to check the row)

P3=key_l;

key_h=P3;

key_h=key_h&0x0f;//00001110 (ignore the column)

key_l=key_l&0xf0;//11100000 (ignore the line)

key=key_h+key_l; //11101110

 

}

}

switch (key)

{

case 0xee:P1=smg_du[0];break;

case 0xde:P1=smg_du[1];break;

case 0xbe:P1=smg_du[2];break;

case 0x7e:P1=smg_du[3];break;

case 0xed:P1=smg_du[4];break;

case 0xdd:P1=smg_du[5];break;

case 0xbd:P1=smg_du[6];break;

case 0x7d:P1=smg_du[7];break;

case 0xeb:P1=smg_du[8];break;

case 0xdb:P1=smg_du[9];break;

case 0xbb:P1=smg_du[10];break;

case 0x7b:P1=smg_du[11];break;

case 0xe7:P1=smg_du[12];break;

case 0xd7:P1=smg_du[13];break;

case 0xb7:P1=smg_du[14];break;

case 0x77:P1=smg_du[15];break;

 

}

}

}

Keywords:C51 Reference address:"Beginner's C51 Self-study Notes" 8X8 keyboard (Line and Line or)

Previous article:"Beginner's C51 Self-study Notes" PS/2
Next article:"Beginner's C51 Self-study Notes" - Preliminary understanding of 89C51

Latest Microcontroller Articles
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号