当前位置:编程学堂 > 利用51单片机制作电子钟的C语言程序_51单片机电子秒表程序

利用51单片机制作电子钟的C语言程序_51单片机电子秒表程序

  • 发布:2023-10-08 04:42

本文内容列表:

  • 1、谁能告诉我一个简单的51单片机24小时格式的LED数码管时钟程序(C语言版)
  • 2、找到51单片机这个时钟的C语言程序
  • 3、使用AT89C51单片机设计电子闹钟,C语言程序及仿真

谁能告诉我一个简单的51单片机24小时格式的LED数码管时钟程序(c语言版)

#include "reg52.h"

#define uint 无符号整数

#define uchar 无符号字符

uchar代码tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

uchar shi,fen,miao;

uchar时间;

无效延迟(uint x)

{

uint y;

对于(;x0;x--)

{

for(y=0;y124;y++);

}

}

虚空显示(uchar shi,uchar fen,uchar miao)

{

P2=0; //位码

P0=(tab[shi/10]); //段码

延迟(2);

P2=1;

P0=(tab[shi%10]);

延迟(2);

P2=2; //位码

P0=0x40; //段码

延迟(2);

P2=3; //位码

P0=(tab[fen/10]); //段码

延迟(2);

P2=4;

P0=(tab[fen%10]);

延迟(2);

P2=5; //位码

P0=0x40; // 段码

延迟(2);

P2=6; //位码

P0=(tab[miao/10]); // 段码

延迟(2);

P2=7;

P0=(tab[miao%10]);

延迟(2);

}

void main()

{

TMOD=0x01;

TH0=(65536-50000)/256;

TL0=(65536-50000)%256;

EA=1;

ET0=1;

TR0=1;

同时(1)

{

if(时间==20)

{

时间=0;

喵++;

if(miao==60)

{

miao=0;

分++;

if(分==60)

{

分=0;

shi++;

if(shi==24)

shi=0;

}

}

}

显示(时、分、苗);

}

}

无效定时器0()中断1

{

TH0=(65536-50000)/256;

TL0=(65536-50000)%256;

时间++;

}

/*还有什么不明白继续追加*/

51单片机求这个时钟的c语言程序

以下是四位数码管调色时带秒闪烁的c51单片机电子钟节目(c语言)。

/**** 本程序中晶振为12MHz,****/

/**** 时间控制采用定时中断控制方式。 ****/

/**** 模式和时间调整采用查询方式。 ****/

#includereg52.h

sbit P20=P2^0; //一位控制端

sbit P21=P2^1; //十位控制终端

sbit P22=P​​2^2; //个位控制端

sbit P23=P2^3; //时间、十位控制端

sbit led=P2^7; //第二个显示LED

sbit key0=P3^0; //模式设置

sbit key1=P3^1; //添加

sbit key2=P3^2; //减去

无符号字符时、分、秒、T50ms;

unsigned char modstate; //模式状态

unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};//段码

void init(); //初始化子程序声明

void延迟500us(unsigned char X); //延迟子程序声明

void display(); //显示子程序声明

void display001(); //显示子程序声明

void display002(); //显示子程序声明

void keyscan(); //按键识别子程序声明

void main()

{

init();

同时(1)

{

keyscan();

}

}

void init() //初始化子程序

{

TMOD=0x01;

TH0=(65536-49990)/256;

TL0=(65536-49990)%256;

ET0=1;

EA=1;

TR0=1;

}

无效延迟500us(无符号字符X)

{

无符号字符 i,j;

对于(i=X;i0;i--)

for(j=248;j0;j--);

}

voidtimer0()interrupt1//timer0中断服务子程序,定时时间为50ms,本程序增加了10us的时间修正

{

TMOD=0x01;

TH0=(65536-49990)/256;

TL0=(65536-49990)%256;

T50ms++;

如果(T50ms=20)

{

T50ms=0;

秒++;

如果(秒=60)

{

秒=0;

分钟++;

如果(分钟=60)

{

min=0;

小时++;

if(小时=24)小时=0;

}

}

}

}

无效显示()

{

P20=1;

P21=1;

P22=1;

P23=1;

P0=表[小时/10];

P23=0;

延迟500us(5);

P20=1;

P21=1;

P22=1;

P23=1;

P0=表[小时%10];

P22=0;

延迟500us(5);

P20=1;

P21=1;

P22=1;

P23=1;

P0=表[分钟/10];

P21=0;

延迟500us(5);

P20=1;

P21=1;

P22=1;

P23=1;

P0=表[min%10];

P20=0;

延迟500us(5);

if(T50ms=10)led=0;

if(T50ms10)led=1;

}

void display001()

{

P20=1;

P21=1;

P22=1;

P23=1;

P0=表[小时/10];

P23=0;

延迟500us(10);

P20=1;

P21=1;

P22=1;

P23=1;

P0=表[小时%10];

P22=0;

延迟500us(10);

}

void display002()

{

P20=1;

P21=1;

P22=1;

P23=1;

P0=表[分钟/10];

P21=0;

延迟500us(10);

P20=1;

P21=1;

P22=1;

P23=1;

P0=表[min%10];

P20=0;

延迟500us(10);

}

void keyscan() //按键识别钟程序

{

同时(modstate==0)

{

显示();

if(key0==0)

{

显示();

if(key0==0)modstate++; //这两句话加在一起就是一个10ms延时的软件防抖设计。

while(key0==0)display001(); //等待按键被释放。

}

}

//************************************************ *** **********************************//

同时(modstate==1)

{

display001();

if(key0==0)

{

display001();

if(key0==0)modstate++; //这两句话加在一起就是一个10ms延时的软件防抖设计。

while(key0==0)display002(); //等待按键被释放。

}

if(key1==0)

{

display001();

if(key1==0)

{

小时++;

if(小时=24)小时=0;

while(key1==0)display001();

}

}

if(key2==0)

{

display001();

if(key2==0)

{

小时--;

if(小时=24)小时=0;

while(key2==0)display001();

}

}

}

//************************************************ *** **********************************//

同时(modstate==2)

{

display002();

if(key0==0)

{

display002();

if(key0==0)modstate=0; //这两句话加在一起就是一个10ms延时的软件防抖设计。

while(key0==0)display(); //等待按键被释放。

}

if(key1==0)

{

display002();

if(key1==0)

{

分钟++;

if(min=60)min=0;

while(key1==0)display002();

}

}

if(key2==0)

{

display002();

if(key2==0)

{

分钟--;

if(min=60)min=0;

while(key2==0)display002();

}

}

}

}

使用AT89C51单片机设计一个电子闹钟,C语言程序及仿真

您好!

这是一个时钟模拟效果,可以调节时间,而且还有闹钟功能

相关文章

最新资讯