找回密码
 立即注册

QQ登录

只需一步,快速开始

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

单片机lcd1602液晶显示秒表精确到0.01s,注释部分我懒得修改了,已经可....

[复制链接]
跳转到指定楼层
楼主
ID:652868 发表于 2020-4-14 08:01 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit en=P3^4;
sbit rs=P3^5;
sbit rd=P3^7;
sbit s4=P3^6;
uchar fen,miao,s4num,count,mm;
uchar code table[]="    00:00:00 ";
void delay(uint z)//ÑÓʱº¯Êý
{
    uint x,y;
    for(x=z;x>0;x--)
        for(y=110;y>0;y--);
}
void write_com(uchar com)
{
    rs=0;
    en=0;
    P0=com;
    delay(1);
    en=1;
    delay(1);
    en=0;   
}
void write_data(uchar date)
{
    rs=1;
    en=0;
    P0=date;
    delay(1);
    en=1;
    delay(1);
    en=0;
}
void init()//³õʼ»¯
{
    uchar num;
    fen=00;
    miao=00;
    mm=00;
    write_com(0x38);
    delay(1);
    write_com(0x38);
    delay(1);
    write_com(0x0c);
    write_com(0x06);
    write_com(0x80+0x40);
    for(num=0;num<12;num++)
        {
            write_data(table[num]);
            delay(1);
        }
        TMOD=0x10;
        TH1=(65536-10000)/256;
        TL1=(65536-10000)%256;
        EA=1;
        ET1=1;
        TR1=0;
}
void write_jishi(uchar add,uchar date)
{
    uchar shi,ge;
    shi=date/10;
    ge=date%10;
    write_com(0x80+0x40+add);
    write_data(0x30+shi);
    write_data(0x30+ge);
}
void keyscan()
{
    rd=0;
    if(s4==0)
    {
        delay(1);
        if(s4==0)
        {
            s4num++;
            while(!s4);
            if(s4num==1)
            {
                TR1=1;
                mm++;
                if(mm==100)
                {
                    mm=0;
                    miao++;
                    if(miao==60)
                    {
                        miao=0;
                        fen++;
                        if(fen==60)
                        {
                            TR1=0;
                        }
                            write_jishi(4,fen);
                            write_com(0x80+0x40+5);
                    }
                    write_jishi(7,miao);
                    write_com(0x80+0x40+8);   
                }
                write_jishi(10,mm);
                write_com(0x80+0x40+11);
            }
            if(s4num==2)
            {
                TR1=0;
            }
            if(s4num==3)
            {
                s4num=0;
                write_com(0x0c);
                init();
            }
        }
    }
}

void main()
{
    init();
    while(1)
    {
        keyscan();
    }
}
void timer0() interrupt 3
{
    TH1=(65536-10000)/256;
    TL1=(65536-10000)%256;
    count++;
    if(count!=0)
    {
        mm++;
        if(mm==100)
        {
            mm=0;
            miao++;
            if(miao==60)
            {
                miao=0;
                fen++;
                if(fen==60)
                {
                    TR1=0;
                }
                write_jishi(4,fen);
            }
            write_jishi(7,miao);
        }
        write_jishi(10,mm);
    }        
}

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

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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