找回密码
 立即注册

QQ登录

只需一步,快速开始

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

0-999秒表程序

[复制链接]
跳转到指定楼层
楼主
ID:320838 发表于 2018-5-2 22:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include <STC12C5A60S2.H>

#define ENLED P11
#define Interrupt                                                                                                                                               

unsigned char code LedChar[10] =                     
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char LedBuff[6] =                                                                                                        
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
void T0init()
{
        TMOD &= 0xF0;                                                                                               
        TMOD |= 0x01;
        TH0 = 0xF5;                                                                                                                                                       
        TR0 = 1;                                                                                                                                                               
        EA = 1;                                                                                                                                                                       
        ET0 = 1;                                                                                                                                                               
        TF0 = 0;                                                                                                                                                       
}void LED_Scan(unsigned long sec)
{
        static unsigned char i = 0;
        unsigned char j = 6;
       
        while(j)
        {
                LedBuff[j-1] = LedChar[sec%10];                                                       
                sec /= 10;j--;
        }
       
        P2 = ~0x07;                                                                                                                                                       
        P2 |= i%6;                                                                                                                                                       
        P0 = LedBuff[(i++)%6];                                                                                                       
}void main()
{
        T0init();
        ENLED = 0;
       
        while(1)
        {
                #ifndef Interrupt                                                                                                                       
                void TF0_Scan();
                TF0_Scan();
                #endif
        }
}
#ifdef Interrupt                                                                                                                                       

void interrupt_Scan() interrupt 1
{
        static unsigned int cnt = 0;
        static unsigned long sec = 0;
       
        TF0 = 0;                                                                                                                                                       
        TH0 = 0xF5;                                                                                                                                                 
        TL0 = 0x95;
       
        cnt++;
        if(cnt >=999)
        {
                cnt = 0;
                sec++;
                if(sec >9)
                {
                        P13=0;sec=0;
        }

        }
       
        LED_Scan(sec);
}
#else                                                                                                                                                                                                                void TF0_Scan()
{
        static unsigned int cnt = 0;
        static unsigned long sec = 0;
       
        if(TF0 == 1)
        {
                TF0 = 0;                                                                                                                                                               
                TH0 = 0xF5;                                                                                                                                       
                TL0 = 0x95;
               
                cnt++;
                if(cnt >= 999)
                {
                        cnt = 0;
                        sec++;
                        if(sec > 9)
                        {
                                P13=0;
                        sec=0;
}
                }
               
                LED_Scan(sec);
        }
}

#endif

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

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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