标题: 怎么让开关机时数码管不显示数字,按下开关后才显示数字 [打印本页]
作者: 陌路狂花 时间: 2017-10-31 22:29
标题: 怎么让开关机时数码管不显示数字,按下开关后才显示数字
按下16个矩阵键盘依次在数码管上显示1-16的平方。如按下第一个显示1,第二个显示4--- , 怎么改 怎么让开关机时数码管不显示数字,按下开关后才显示数字。# include <reg52.h>
# define uint unsigned int
# define uchar unsigned char
sbit P_HC595_SER = P2^7; //pin 14 SER data input
sbit P_HC595_RCLK = P2^5; //pin 12 RCLk store (latch) clock
sbit P_HC595_SRCLK = P2^6; //pin 11 SRCLK Shift data clock
uchar code t_display[]={
// 0 1 2 3 4 5 6 7 8 9 A B C D E F //
0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71, 0x76, 0x79, 0x38, 0x3f, 0}; // ¶ÎÂë
uchar code wei[] = {0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f};
uchar temp;
uint num, num1;
void Send_595(uchar);
void delay(uint);
uint dage();
void display(uchar);
void we(uchar, uchar, uchar);
void main()
{
Send_595(0xff);
Send_595(0xff);
P_HC595_RCLK = 0;
P_HC595_RCLK = 1;
while(1)
{
num1 = dage();
we(num1/100, num1%100/10, num1%10);
}
}
void Send_595(uchar dat)
{
uint i;
for(i=0; i<8; i++)
{
if(dat & 0x80) P_HC595_SER = 1;
else P_HC595_SER = 0;
P_HC595_SRCLK = 0;
P_HC595_SRCLK = 1;
dat = dat << 1;
}
}
void delay(uint z)
{
uint x, y;
for(x=z; x>0; x--)
for(y=110; y>0; y--);
}
uint dage()
{
P3 = 0xfe;
temp = P3;
temp = temp&0xf0;
while( temp != 0xf0)
{
delay(5);
temp = P3;
temp = temp&0xf0;
while( temp != 0xf0)
{
temp = P3;
switch(temp)
{
case 0xee : num = 1;
break;
case 0xde : num = 4;
break;
case 0xbe : num = 9;
break;
case 0x7e : num = 16;
break;
}
while( temp != 0xf0)
{
temp = P3;
temp = temp&0xf0;
}
}
}
P3 = 0xfd;
temp = P3;
temp = temp&0xf0;
while( temp != 0xf0)
{
delay(5);
temp = P3;
temp = temp&0xf0;
while( temp != 0xf0)
{
temp = P3;
switch(temp)
{
case 0xed : num = 25;
break;
case 0xdd : num = 36;
break;
case 0xbd : num = 49;
break;
case 0x7d : num = 64;
break;
}
while( temp != 0xf0)
{
temp = P3;
temp = temp&0xf0;
}
}
}
P3 = 0xfb;
temp = P3;
temp = temp&0xf0;
while( temp != 0xf0)
{
delay(5);
temp = P3;
temp = temp&0xf0;
while( temp != 0xf0)
{
temp = P3;
switch(temp)
{
case 0xeb : num = 81;
break;
case 0xdb : num = 100;
break;
case 0xbb : num = 121;
break;
case 0x7b : num = 144;
break;
}
while( temp != 0xf0)
{
temp = P3;
temp = temp&0xf0;
}
}
}
P3 = 0xf7;
temp = P3;
temp = temp&0xf0;
while( temp != 0xf0)
{
delay(5);
temp = P3;
temp = temp&0xf0;
while( temp != 0xf0)
{
temp = P3;
switch(temp)
{
case 0xe7 : num = 169;
break;
case 0xd7 : num = 196;
break;
case 0xb7 : num = 225;
break;
case 0x77 : num = 256;
break;
}
while( temp != 0xf0)
{
temp = P3;
temp = temp&0xf0;
}
}
}
return num;
}
void we(uchar aa, uchar bb, uchar cc)
{
Send_595(0xfe);
Send_595(t_display[aa]);
P_HC595_RCLK = 0;
P_HC595_RCLK = 1;
Send_595(0xfd);
Send_595(t_display[bb]);
P_HC595_RCLK = 0;
P_HC595_RCLK = 1;
Send_595(0xfb);
Send_595(t_display[cc]);
P_HC595_RCLK = 0;
P_HC595_RCLK = 1;
}
-
-
JW-51开发板.pdf
99.63 KB, 下载次数: 4
作者: cjjcjj1 时间: 2017-11-1 06:10
提示: 作者被禁止或删除 内容自动屏蔽
作者: 陌路狂花 时间: 2017-11-1 18:02
如果在后面加一个延迟函数后, 为什么还会出现000 ? 初学者,多多指教
作者: zl2168 时间: 2017-11-1 18:44
本帖最后由 zl2168 于 2017-11-1 18:47 编辑
你的问题在下例中找到答案
实例5 4种不同方式键控信号灯
按键按能否锁定可分为有锁按键和无锁按键。有锁按键是按下即能锁定闭合状态,只有再次按一下才能解除闭合状态,回归断开状态。无锁按键不能锁定闭合状态,除非按住键不予释放,典型的例子就是电脑键盘上的按键。
单片机应用系统中,根据按键闭合和释放状态,有多种不同的键控方式,可编写不同的程序予以实现。本例要求按以下4种不同方式分别键控VD0~ VD3。
① 无锁按键:S0按下,VD0亮;S0释放,VD0暗;
② 无锁按键(前沿有效):S1按下,VD1亮;S1释放,VD1延时2s后暗。
③ 无锁按键(后沿有效):S2按下,VD2不亮;S2释放,VD2亮,并延时2s后暗。
④ 模拟有锁按键:S3按第一次,VD3亮,并继续保持;按第二次,VD3才暗。
先
Proteus仿真一下,确认有效。
实例5 不同方式键控灯.rar
(31.72 KB, 下载次数: 6)
以上摘自张志良编著《
80C51单片机仿真设计实例教程——基于Keil C和Proteus》清华大学出版社ISBN 978-7-302-41682-1.书中电路和程序设计有详细说明,程序语句条条有注解。
作者: 陌路狂花 时间: 2017-11-1 21:11
怎么改, 能不能写详细点
欢迎光临 (http://www.51hei.com/bbs/) |
Powered by Discuz! X3.1 |