1个回答
展开全部
#include <REGX52.H>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define DataPort P0
#define RS_CLR RS = 0
#define RS_SET RS = 1
#define RW_CLR RW = 0
#define RW_SET RW = 1
#define EN_CLR EN = 0
#define EN_SET EN = 1
sbit RS = P1^3; //定义端口
sbit RW = P1^4;
sbit EN = P1^5;
sbit wx = P2^6;
sbit dx = P2^7;
sbit beep = P2^2;
unsigned char code table[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71};
/*
* 功 能:延时,若干毫秒
* 参 数:毫秒数
* 返回值:无
*/
void DelayMs(unsigned int i) //一个延时函数,这个函数在11.0592M晶振下的延时时间大概为1ms
{
unsigned int j,k;
for(j=i; j>0; j--)
for(k=114; k>0; k--);
}
/*
* 功 能:延时
* 参 数:延时的数量
* 返回值:无
*/
void delay(uint x)
{
uint a,b;
for(a=x; a>0; a--)
for(b=10; b>0; b--);
}
/*
* 功 能:显示计时的秒数
* 参 数:无
* 返回值:无
*/
void display(uchar d2, uchar d1)
{
P0 = table[d2];
dx = 1;
dx = 0;
P0 = 0xfe;
wx = 1;
wx = 0;
delay(5);
P0 = table[d1];
dx = 1;
dx = 0;
P0 = 0xfd;
wx = 1;
wx = 0;
delay(5);
}
void main()
{
uchar i, second=0, d1, d2, dat=0xFF;
while(1)
{
DelayMs(1000);
second++;
dat--;
P1 = dat;
if(second == 60)
{
second = 0;
}
d2 = second / 10;
d1 = second % 10;
for(i=50; i>0; i--)
{
display(d2, d1);
}
}
}
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define DataPort P0
#define RS_CLR RS = 0
#define RS_SET RS = 1
#define RW_CLR RW = 0
#define RW_SET RW = 1
#define EN_CLR EN = 0
#define EN_SET EN = 1
sbit RS = P1^3; //定义端口
sbit RW = P1^4;
sbit EN = P1^5;
sbit wx = P2^6;
sbit dx = P2^7;
sbit beep = P2^2;
unsigned char code table[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71};
/*
* 功 能:延时,若干毫秒
* 参 数:毫秒数
* 返回值:无
*/
void DelayMs(unsigned int i) //一个延时函数,这个函数在11.0592M晶振下的延时时间大概为1ms
{
unsigned int j,k;
for(j=i; j>0; j--)
for(k=114; k>0; k--);
}
/*
* 功 能:延时
* 参 数:延时的数量
* 返回值:无
*/
void delay(uint x)
{
uint a,b;
for(a=x; a>0; a--)
for(b=10; b>0; b--);
}
/*
* 功 能:显示计时的秒数
* 参 数:无
* 返回值:无
*/
void display(uchar d2, uchar d1)
{
P0 = table[d2];
dx = 1;
dx = 0;
P0 = 0xfe;
wx = 1;
wx = 0;
delay(5);
P0 = table[d1];
dx = 1;
dx = 0;
P0 = 0xfd;
wx = 1;
wx = 0;
delay(5);
}
void main()
{
uchar i, second=0, d1, d2, dat=0xFF;
while(1)
{
DelayMs(1000);
second++;
dat--;
P1 = dat;
if(second == 60)
{
second = 0;
}
d2 = second / 10;
d1 = second % 10;
for(i=50; i>0; i--)
{
display(d2, d1);
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询