欢迎光临MCUWAY! 本站网名:单片机之路  永久域名:www.mcuway.com

设为首页

加入收藏

电子基础 初学MCU 单片机类型 MCU程序 MCU应用 设计软件 测控电路 技术论坛
 您现在的位置: 单片机之路 >> 单片机应用 >> 应用实例 >> 文章正文

单片机键盘程序(4×4矩阵式)

6. C语言源程序

#include

unsigned char code table[]={0x3f,0x06,0x5b,0x4f,

0x66,0x6d,0x7d,0x07,

0x7f,0x6f,0x77,0x7c,

0x39,0x5e,0x79,0x71};

unsigned char temp;

unsigned char key;

unsigned char i,j;

void main(void)

{

while(1)

{

P3=0xff;

P3_4=0;

temp=P3;

temp=temp & 0x0f;

if (temp!=0x0f)

{

for(i=50;i>0;i--)

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

temp=P3;

temp=temp & 0x0f;

if (temp!=0x0f)

{

temp=P3;

temp=temp & 0x0f;

switch(temp)

{

case 0x0e:

key=7;

break;

case 0x0d:

key=8;

break;

case 0x0b:

key=9;

break;

case 0x07:

key=10;

break;

}

temp=P3;

P1_0=~P1_0;

P0=table[key];

temp=temp & 0x0f;

while(temp!=0x0f)

{

temp=P3;

temp=temp & 0x0f;

}

}

}

P3=0xff;

P3_5=0;

temp=P3;

temp=temp & 0x0f;

if (temp!=0x0f)

{

for(i=50;i>0;i--)

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

temp=P3;

temp=temp & 0x0f;

if (temp!=0x0f)

{

temp=P3;

temp=temp & 0x0f;

switch(temp)

{

case 0x0e:

key=4;

break;

case 0x0d:

key=5;

break;

case 0x0b:

key=6;

break;

case 0x07:

key=11;

break;

}

temp=P3;

P1_0=~P1_0;

P0=table[key];

temp=temp & 0x0f;

while(temp!=0x0f)

{

temp=P3;

temp=temp & 0x0f;

}

}

}

P3=0xff;

P3_6=0;

temp=P3;

temp=temp & 0x0f;

if (temp!=0x0f)

{

for(i=50;i>0;i--)

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

temp=P3;

temp=temp & 0x0f;

if (temp!=0x0f)

{

temp=P3;

temp=temp & 0x0f;

switch(temp)

{

case 0x0e:

key=1;

break;

case 0x0d:

key=2;

break;

case 0x0b:

key=3;

break;

case 0x07:

key=12;

break;

}

temp=P3;

P1_0=~P1_0;

P0=table[key];

temp=temp & 0x0f;

while(temp!=0x0f)

{

temp=P3;

temp=temp & 0x0f;

}

}

}

P3=0xff;

P3_7=0;

temp=P3;

temp=temp & 0x0f;

if (temp!=0x0f)

{

for(i=50;i>0;i--)

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

temp=P3;

temp=temp & 0x0f;

if (temp!=0x0f)

{

temp=P3;

temp=temp & 0x0f;

switch(temp)

{

case 0x0e:

key=0;

break;

case 0x0d:

key=13;

break;

case 0x0b:

key=14;

break;

case 0x07:

key=15;

break;

}

temp=P3;

P1_0=~P1_0;

P0=table[key];

temp=temp & 0x0f;

while(temp!=0x0f)

{

temp=P3;

temp=temp & 0x0f;

}

}

}

}

}

上一页  [1] [2] [3] 

普通文章28课:单片机音乐汇编程序设计
普通文章27课:单片机的一些基本概念
普通文章26课:单片机矩阵式键盘接口技术
普通文章51单片机教程(从原理开始基于汇编)
普通文章1课:单片机概述
普通文章2课:8051单片机引脚介绍
普通文章3课:单片机存储器结构结构分析
普通文章4课:第一个单片机小程序
普通文章5课:单片机延时程序分析
普通文章6课:单片机并行口结构
普通文章7课:单片机的特殊功能寄存器
普通文章8课:单片机寻址方式与指令系统
普通文章9课:单片机数据传递类指令
普通文章10课:单片机数据传送类指令
普通文章11课:单片机算术运算指令
普通文章12课:单片机逻辑运算类指令
普通文章13课:单片机逻辑与或异或指令祥解
普通文章14课:单片机条件转移指令
普通文章15课:单片机位操作指令
普通文章16课:单片机定时器与计数器
普通文章17课:单片机定时器/计数器的方式控制
普通文章18课:单片机的中断系统
普通文章19课:单片机定时器、中断试验
普通文章20课:单片机定时/计数器实验
普通文章21课:单片机串行口介绍

  • 上一篇文章:
  • 下一篇文章:
  • 更多精彩内容>>>

    普通文章电流单位
    普通文章功率单位
    普通文章什么是达林顿管?
    普通文章晶闸管的作用与原理

    学习单片机的必经之路——单片机之路,永久域名:www.mcuway.com