标题:
c51单片机+DIY电路每5分钟显示一次时钟 源程序
[打印本页]
作者:
runrong
时间:
2020-7-12 10:59
标题:
c51单片机+DIY电路每5分钟显示一次时钟 源程序
以下时部分程序,谢谢。
制作出来的实物图如下:
51hei图片20200712105359.jpg
(283.59 KB, 下载次数: 43)
下载附件
2020-7-12 10:55 上传
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
5.jpg
(93.5 KB, 下载次数: 52)
下载附件
2020-7-12 10:55 上传
单片机源程序如下:
#include "reg52.h" //单片机头文件
#define uchar unsigned char //定义uchar 代替 unsigned char
#define uint unsigned int
sbit shi=P0;
sbit fen=P2; //位定义
sbit fenn=P1;
sbit k1=P3^4;
sbit k2=P3^5;
sbit k3=P3^6;
sbit k4=P3^7;
void display(uchar a0,uchar a1,uchar a2,uchar a3,uchar a4,uchar a5); //函数声明
//void delay(uchar mss);
//修改了数组的值
uchar code tab1[]={0x20,0x30,0x38,0x3c,0x3e,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f};
uchar code tab2[]={0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f};
//uchar code tab3[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f};
//uchar code tab4[]={0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x30,0x38,0x3c,0x3e,0x3f};
uchar code tab3[]={0x20,0x10,0x08,0x04,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00};//数组显示
uchar code tab4[]={0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20};
//uchar code tab1[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f};
//uchar code tab2[]={0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x30,0x38,0x3c,0x3e,0x3f};
//uchar code tab3[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f}; 去除的
//uchar code tab4[]={0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x30,0x38,0x3c,0x3e,0x3f}; 去除的
//uchar code tab3[]={0x01,0x02,0x04,0x08,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00};//数组显示
//uchar code tab4[]={0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01};
uchar ms=0,mg=0,fs=0,fg=0,ss=0,sg=0,m=0,f=0,s=0,ff=0,hf=0,fff=0;//定义变量
char led[4]={0}; //显示数组,修改
void delay(int i) //延时函数
{
while(i--);
}
void led4(void) //显示函数
{
char i;
for(i=0;i<4;i++) //4位
{
P0=~led[i]; //送段码 P2,P0对换了
P2=~(0x01<<i); //送位码
delay(100); //延时
P0=0xff; //关闭显示
P2=0xff; //关闭显示
}
}
char k,kk; //循环次数
long n; //移位
int h; //另外一个定时变量
main()
{
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
led4(); //调用显示函数
if(k1==0) //按键k1为低电频
{
delay(40); //延时去抖
if(k1==0) //判断k1是否按下
{
while(k1!=1); //等待按键释放
ff++; //ff,5分钟自加
fff++; //fff也自加 //秒置0
if(ff==12) //ff够12,自动置0,小时自加1
{
ff=0;
m=0;
h++;
hf++;
if(h==11)
{h=0;}
}
}
}
if(k2==0) //按键k2控制加1小时
{
delay(40);
if(k2==0)
{
while(k2!=1);
h++;
hf++;
m=0;
if(h==11)
{
h=0;
}
}
}
if(fff==1) //把fff清0返回5分钟后的效果
{
fff=0;
led[0]=tab1[k];
led[3]=tab2[k];
k++;
if(k>11) k=0;
}
复制代码
/////////////////////////////
全部资料51hei下载地址:
5分钟时钟项目.rar
(58.44 KB, 下载次数: 9)
2020-7-12 10:55 上传
点击文件名下载附件
下载积分: 黑币 -5
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1