#include
#define uchar unsigned char
#define uint unsigned int
void delay(uint);
void sysini(void);
/************************************************************
*本程序版权所有
*http://www.51hei.com 荣誉出品
*c语言编写的单片机抢答器程序已经测试成功,大家烧写到芯片中就可以直接使用了
*************************************************************/
void main(void)
{sysini();
while(1)
{
P2=0x3f;
P2=0x3f;
if(P1!=0xff)
{P2=0x7c;
P3_1=0;
delay(65535);
P3_1=1;
continue;
}
while(P1==0xff); //循环判断 等待按键,同时显示0
//读取数据
switch(P1)
{case 0xfe:P2=0x03;break; //1
case 0xfd:P2=0x6d;break; //2
case 0xfb:P2=0x67;break; //3
case 0xf7:P2=0x53;break; //4
case 0xef:P2=0x76;break; //5
case 0xdf:P2=0x7e;break; //6
case 0xbf:P2=0x23;break; //7
case 0x7f:P2=0x7f;break; //8
default: P2=0x7c;
}
P3_1=0;
delay(65535);
P3_1=1;
while(P3_2)
{if(!P3_2) break;
if(!P3_2) break;
if(!P3_2) break;
if(!P3_2) break;
}
}
}
void delay(uint a)
{uint i;
for(i=0;i ;
}
void sysini(void)
{P2=0x00;delay(10000);
P2=0x01;delay(10000);
P2=0x02;delay(10000);
P2=0x04;delay(10000);
P2=0x08;delay(10000);
P2=0x10;delay(10000);
P2=0x20;delay(10000);
P2=0x00;delay(40000);
P2=0x38;delay(40000);
P2=0x00;delay(40000);
P2=0x7b;delay(40000);
P2=0x00;delay(40000);
P2=0x7b;delay(40000);
P2=0x00;delay(40000);
P2=0x01;delay(30000);
P2=0x03;delay(30000);
P2=0x07;delay(30000);
P2=0x0f;delay(30000);
P2=0x1f;delay(30000);
P2=0x3f;delay(30000);
}
---------下面还介绍一个汇编语言编程的单片机抢答器程序原理请读者自行分析-------------------
C0002:
MOV P2,#0C0H
C0004:
MOV A,P1
CPL A
JZ C0004
C0005:
MOV R7,P1
MOV A,R7
ADD A,#081H
JZ C0014
ADD A,#0C0H
JZ C0013
ADD A,#0E0H
JZ C0012
ADD A,#0F0H
JZ C0011
ADD A,#0F8H
JZ C0010
ADD A,#0FCH
JZ C0009
ADD A,#0FEH
JZ C0008
DEC A
JNZ C0015
C0007:
MOV P2,#0FCH
SJMP C0016
C0008:
MOV P2,#092H
SJMP C0016
C0009:
MOV P2,#098H
SJMP C0016
C0010:
MOV P2,#0ACH
SJMP C0016
C0011:
MOV P2,#089H
SJMP C0016
C0012:
MOV P2,#081H
SJMP C0016
C0013:
MOV P2,#0DCH
SJMP C0016
C0014:
MOV P2,#080H
SJMP C0016
C0015:
MOV P2,#088H
C0016:
JNB P3_1,C0002
SJMP C0016m
推荐阅读最新更新时间:2024-03-16 13:15
- 热门资源推荐
- 热门放大器推荐
设计资源 培训 开发板 精华推荐
- Allegro MicroSystems 在 2024 年德国慕尼黑电子展上推出先进的磁性和电感式位置感测解决方案
- 左手车钥匙,右手活体检测雷达,UWB上车势在必行!
- 狂飙十年,国产CIS挤上牌桌
- 神盾短刀电池+雷神EM-i超级电混,吉利新能源甩出了两张“王炸”
- 浅谈功能安全之故障(fault),错误(error),失效(failure)
- 智能汽车2.0周期,这几大核心产业链迎来重大机会!
- 美日研发新型电池,宁德时代面临挑战?中国新能源电池产业如何应对?
- Rambus推出业界首款HBM 4控制器IP:背后有哪些技术细节?
- 村田推出高精度汽车用6轴惯性传感器
- 福特获得预充电报警专利 有助于节约成本和应对紧急情况