找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1878|回復: 0
打印 上一主題 下一主題
收起左側

單片機lcd1602液晶顯示秒表精確到0.01s,注釋部分我懶得修改了,已經(jīng)可....

[復制鏈接]
跳轉到指定樓層
樓主
ID:652868 發(fā)表于 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空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表