搜索
热搜: ROHM 模拟 车载
查看: 2028|回复: 3

51单片机模拟实现普通电子表功能的设计

  [复制链接]

该用户从未签到

1347

主题

6657

帖子

0

精华

论坛元老

最后登录
2020-7-26
发表于 2020-1-8 14:53:49 | 显示全部楼层 |阅读模式
                                                                                                                       

[color=rgb(51, 51, 51) !important]此程序模拟普通的电子表的功能,实现了时,分,秒的显示,并有调表功能。程序简单,好多地方并没有注意细节,只是实现了部分功能。

[color=rgb(51, 51, 51) !important]//数码管为8位七段共阳数码管,数据端接在P0口,选择端接P2口

[color=rgb(51, 51, 51) !important]//外部中断0,选择调时,分或秒,并闪烁,外部中断1,闪烁位加1,实现调表

[color=rgb(51, 51, 51) !important]//注:些程序只是模拟,并无精确校准

[color=rgb(51, 51, 51) !important]

[color=rgb(51, 51, 51) !important]#include

[color=rgb(51, 51, 51) !important]unsigned char LED7Code[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,

[color=rgb(51, 51, 51) !important]0x80,0x90,0x88,0x83,0x0c6,0xa1,0x86,0x8e,

[color=rgb(51, 51, 51) !important]0xbf, //‘-’

[color=rgb(51, 51, 51) !important]}; //七段共阳数码管的编码0-f

[color=rgb(51, 51, 51) !important]unsigned char LED7Addr[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //数码管的地址

[color=rgb(51, 51, 51) !important]unsigned char flag=0;

[color=rgb(51, 51, 51) !important]unsigned char loop=0;

[color=rgb(51, 51, 51) !important]unsigned char second=0;

[color=rgb(51, 51, 51) !important]unsigned char minute=0;

[color=rgb(51, 51, 51) !important]unsigned char hour=0;

[color=rgb(51, 51, 51) !important]void delay(unsigned int n) //n=10000,延时90.05毫秒

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]while(n--);

[color=rgb(51, 51, 51) !important]}

[color=rgb(51, 51, 51) !important]void display(unsigned char addr,unsigned char LEDCode) //通用显示函数

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]P2=LED7Addr[addr]; //P2送数码管的地址

[color=rgb(51, 51, 51) !important]P0=LED7Code[LEDCode]; //P0送要显示的数据

[color=rgb(51, 51, 51) !important]delay(500); //延时

[color=rgb(51, 51, 51) !important]}

[color=rgb(51, 51, 51) !important]void INT_EX0() interrupt 0

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]delay(2000);

[color=rgb(51, 51, 51) !important]if (!P3_2)

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]if(flag++》=3) flag=0;

[color=rgb(51, 51, 51) !important]}

[color=rgb(51, 51, 51) !important]}

[color=rgb(51, 51, 51) !important]void INT_EX1() interrupt 2

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]delay(2000);

[color=rgb(51, 51, 51) !important]if (!P3_3)

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]if(flag==1) second++;

[color=rgb(51, 51, 51) !important]if(flag==2) minute++;

[color=rgb(51, 51, 51) !important]if(flag==3) hour++;

[color=rgb(51, 51, 51) !important]}

[color=rgb(51, 51, 51) !important]}

[color=rgb(51, 51, 51) !important]void INT_T0() interrupt 1 //定时器0

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]TL0=0xb0; //装入初值,15536,定时50000us

[color=rgb(51, 51, 51) !important]TH0=0x3c;

[color=rgb(51, 51, 51) !important]loop++;

[color=rgb(51, 51, 51) !important]}

[color=rgb(51, 51, 51) !important]void main()

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]TMOD=0x01; //定时器0,工作方式2,16位定时器

[color=rgb(51, 51, 51) !important]TL0=0xb0; //装入初值,15536,定时50000us

[color=rgb(51, 51, 51) !important]TH0=0x3c;

[color=rgb(51, 51, 51) !important]ET0=1;

[color=rgb(51, 51, 51) !important]TR0=1;

[color=rgb(51, 51, 51) !important]EX0=1;

[color=rgb(51, 51, 51) !important]EX1=1;

[color=rgb(51, 51, 51) !important]IT0=1; //跳变方式

[color=rgb(51, 51, 51) !important]IT1=1;

[color=rgb(51, 51, 51) !important]EA=1;

[color=rgb(51, 51, 51) !important]while (1)

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]if(loop》=20)

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]second++;

[color=rgb(51, 51, 51) !important]loop=0;

[color=rgb(51, 51, 51) !important]}

[color=rgb(51, 51, 51) !important]if (second》=60)

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]second=0;

[color=rgb(51, 51, 51) !important]minute++;

[color=rgb(51, 51, 51) !important]}

[color=rgb(51, 51, 51) !important]if (minute==60)

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]minute=0;

[color=rgb(51, 51, 51) !important]hour++;

[color=rgb(51, 51, 51) !important]}

[color=rgb(51, 51, 51) !important]if (!(flag==3&&loop《10))

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]display(0,hour/10);

[color=rgb(51, 51, 51) !important]display(1,hour%10);

[color=rgb(51, 51, 51) !important]}

[color=rgb(51, 51, 51) !important]display(2,16);

[color=rgb(51, 51, 51) !important]if (!(flag==2&&loop《10))

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]display(3,minute/10);

[color=rgb(51, 51, 51) !important]display(4,minute%10);

[color=rgb(51, 51, 51) !important]}

[color=rgb(51, 51, 51) !important]display(5,16);

[color=rgb(51, 51, 51) !important]if (!(flag==1&&loop《10))

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]display(6,second/10);

[color=rgb(51, 51, 51) !important]display(7,second%10);

[color=rgb(51, 51, 51) !important]}

[color=rgb(51, 51, 51) !important]}

[color=rgb(51, 51, 51) !important]}


                                                                               

回复

使用道具 举报

该用户从未签到

2248

主题

1万

帖子

1

精华

论坛元老

最后登录
2024-4-24
发表于 2020-1-9 08:17:44 | 显示全部楼层
不错的资料
回复 支持 反对

使用道具 举报

该用户从未签到

2248

主题

1万

帖子

1

精华

论坛元老

最后登录
2024-4-24
发表于 2020-1-9 08:18:58 | 显示全部楼层
不错的资料
回复 支持 反对

使用道具 举报

该用户从未签到

2384

主题

9837

帖子

0

精华

论坛元老

最后登录
2024-4-23
发表于 2020-1-9 11:18:28 | 显示全部楼层
学习学习51单片机模拟实现普通电子表功能的设计
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条

Archiver|手机版|小黑屋|罗姆半导体技术社区

GMT+8, 2024-4-25 03:13 , Processed in 0.089037 second(s), 14 queries , MemCache On.

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.

快速回复 返回顶部 返回列表