找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1932|回复: 0
打印 上一主题 下一主题
收起左侧

基于51单片机 10秒的秒表

[复制链接]
跳转到指定楼层
楼主
ID:464253 发表于 2019-1-9 22:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
十秒秒表代码如下:
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int

sbit K1 = P3^7;
uchar i,Second_Counts,Key_Flag_Idx;
bit Key_State;
uchar DSY_CODE[]=
{
        0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
};

void DelayMS(uint ms)
{
        uchar t;
        while(ms--)
        {
                 for(t=0;t<120;t++);
        }
}

void Key_Event_Handle()
{
        if(Key_State == 0)
        {
                 Key_Flag_Idx=(Key_Flag_Idx+1)%3;
                switch(Key_Flag_Idx)
                {
                         case 1:EA=1;ET0=1;TR0=1;break;
                        case 2:EA=0;ET0=0;TR0=0;break;
                        case 0:P0=0x3f;P2=0x3f;i=0;Second_Counts=0;
                }
        }
}

void main()
{
        P0 = 0x3f;
        P2 = 0x3f;
        i = 0;
        Second_Counts = 0;
        Key_State = 1;
        TMOD = 0x01;
        TH0  = (65535-50000)/256;
        TL0  = (65535-50000)%256;
        while(1)
        {
                 if(Key_State != K1)
                {
                         DelayMS(10);
                        Key_State = K1;
                        Key_Event_Handle();
                }
        }
}

void DSY_Refresh() interrupt 1
{
        TH0  = (65535-50000)/256;
        TL0  = (65535-50000)%256;
        if(++i==2)
        {
                 i = 0;
                ++Second_Counts;
                P0 = DSY_CODE[Second_Counts/10];
                P2 = DSY_CODE[Second_Counts%10];
                if(Second_Counts == 100) Second_Counts = 0;
        }
}

10秒的秒表.zip

45.04 KB, 下载次数: 8, 下载积分: 黑币 -5

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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