久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 4463|回復(fù): 5
收起左側(cè)

51單片機(jī)數(shù)字時(shí)鐘

[復(fù)制鏈接]
ID:789341 發(fā)表于 2020-6-26 00:08 | 顯示全部樓層 |閱讀模式
#include<reg51.h>
#define uChar unsigned char
#define uInt unsigned int
uChar a[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uChar b[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uChar second=50,minute=59,hour=12,year=18,month=07,day=21,count;
sbit Key1 = P3^0; //計(jì)時(shí)停止
sbit Key2 = P3^1; //調(diào)位
sbit Key3 = P3^2; //加一
sbit Key4 = P3^3; //切換  
sbit Buzzer=P1^1;
/*********************延遲函數(shù)********************/
void Delay(uInt t)
{
        while(t)
        {
                t--;
        }
}
/*********************時(shí)分秒顯示函數(shù)*******************/
void Dispaly1(uChar second,uChar minute,uChar hour)
{
/*********************第一位數(shù)碼管*********************/
        P2=b[0];
        P0=a[hour/10];
        Delay(10);
/*********************第二位數(shù)碼管*********************/
        P2=b[1];
        P0=a[hour%10];
        Delay(10);
/*********************第三位數(shù)碼管*********************/
        P2=b[2];
        P0=0x40;
        Delay(10);
/*********************第四位數(shù)碼管*********************/
        P2=b[3];
        P0=a[minute/10];
        Delay(10);
/*********************第五位數(shù)碼管*********************/
        P2=b[4];
        P0=a[minute%10];
        Delay(10);
/*********************第六位數(shù)碼管*********************/
        P2=b[5];
        P0=0x40;
        Delay(10);
/*********************第七位數(shù)碼管*********************/
        P2=b[6];
        P0=a[second/10];
        Delay(10);
/*********************第八位數(shù)碼管*********************/
        P2=b[7];;
        P0=a[second%10];
        Delay(10);
}
/*********************年月日顯示函數(shù)********************/
void Dispaly2(uChar day,uChar month,uChar year)
{
        P2=b[0];
        P0=a[day/10];
        Delay(10);

        P2=b[1];
        P0=a[day%10];
        Delay(10);

        P2=b[2];
        P0=0x40;
        Delay(10);

        P2=b[3];
        P0=a[month/10];
        Delay(10);

        P2=b[4];
        P0=a[month%10];
        Delay(10);

        P2=b[5];
        P0=0x40;
        Delay(10);

        P2=b[6];
        P0=a[year/10];
        Delay(10);

        P2=b[7];
        P0=a[year%10];
        Delay(10);
}
/*********************時(shí)鐘按鍵掃描函數(shù)*********************/
void Keyscan1()
{
        static uChar i=0,j=0;
        if(Key1==0)
        {
                Delay(10); //消抖
                if(Key1==0)
                        while(!Key1); //等待按鍵彈
                i++;
        }
/*時(shí)鐘暫停功能*/
        if(i%2==1)
        {
                TR0=0;/*如果是奇數(shù)次按鍵自然關(guān)閉定時(shí)器0*/
        }
        if(i%2==0)
        {
                TR0=1;/*如果是偶數(shù)次按鍵則打開定時(shí)器0*/
        }
/*時(shí)鐘調(diào)位和數(shù)值加一功能*/
        if(Key2==0)
        {                       
                Delay(10);
                if(Key2==0)
                        while(!Key2);
                j++;
        }
        if(j%4==1)
        {
                if(Key3==0)
                {
                Delay(10);
                if(Key3==0)
                while(!Key3);
                second++;
                if(second==60)
                second=0;
                }
        }
        if(j%4==2)
        {
        if(Key3==0)
        {
                Delay(10);
                if(Key3==0)
                        while(!Key3);
                minute++;
                if(minute==60)
                        minute=0;
        }
        }
if(j%4==3)
{
if(Key3==0)
{
Delay(10);
if(Key3==0)
while(!Key3);
hour++;
if(hour==24)
hour=0;
}
}
}
/*日期按鍵掃描函數(shù)*/
void Keyscan2()
{
static uChar m=0,n=0;
if(Key1==0)
{
Delay(10);
if(Key1==0)
while(!Key3);
m++;
}
if(m%2==1)
{
TR0=0;/*奇數(shù)次按鍵則關(guān)閉定時(shí)器0*/
}

if(m%2==0)
{
TR0=1;/*偶數(shù)次按鍵則打開定時(shí)器0*/
}
if(Key2==0)
{
Delay(10);
if(Key2==0)
while(!Key2);
n++;
}
/*日期調(diào)位和日期加一功能*/
if(n%4==1)
{
if(Key3==0)
{
Delay(10);
if(Key3==0)
while(!Key3);
day++;
if(day==30)
day=0;
}
}
if(n%4==2)
{
if(Key3==0)
{
Delay(10);
if(Key3==0)
while(!Key3);
month++;
if(month==12)
month=0;
}
}
if(n%4==3)
{
if(Key3==0)
{
Delay(10);
if(Key3==0)
while(!Key3);
year++;
if(year==99)
year=0;
}
}
}

/************************************************/
/***************主函數(shù)***************************/
/************************************************/
void main()
{                                               
TMOD=0x01;          /*定時(shí)器以方式一工作*/
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;/*10ms計(jì)時(shí)*/
EA=1;
ET0=1;/*允許定時(shí)器0中斷*/
TR0=1;/*打開定時(shí)器0*/
while(1)
{
static uChar h=0;
/*時(shí)鐘和日期切換功能*/
if(Key4==0)
{
Delay(10);
if(Key4==0)
while(!Key4);
h++;
}
if(h%2==0)/*如果按鍵偶數(shù)次則顯示時(shí)鐘*/
{
Dispaly1(second,minute,hour);
Keyscan1();
}

if(h%2==1)/*如果按鍵奇數(shù)次則顯示日期*/
{
Dispaly2(year,month,day);
Keyscan2();
}
}
}
/**********************中斷函數(shù)**************************/
void time0_int(void) interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
count++;
if(count==100)/*10ms??ê±£???100′??ò??o?1s*/
{
count=0;
second++;
if(second==60)
{
second=0;
minute++;
if(minute==60)
{
minute=0;
hour++;
if(hour==24)
{
hour=0;
day++;
if(day==30)
{
day=0;
month++;
if(month==12)
{
month=0;
year++;
if(year==99)
{
year=0;
}
}
}
}
}
}
}
/*判斷整點(diǎn)提醒*/
if(second==00&&minute==00)                                                                  
Buzzer=0;
else
Buzzer=1;
}




單片機(jī)發(fā)帖png.png
回復(fù)

使用道具 舉報(bào)

ID:984923 發(fā)表于 2021-12-6 22:42 | 顯示全部樓層
運(yùn)行起來為什么數(shù)字顯示不全而且沒有時(shí)間顯示
回復(fù)

使用道具 舉報(bào)

ID:931783 發(fā)表于 2022-10-20 10:59 | 顯示全部樓層
插眼.....
回復(fù)

使用道具 舉報(bào)

ID:1058667 發(fā)表于 2022-12-22 10:05 | 顯示全部樓層
插眼看一看后續(xù)
回復(fù)

使用道具 舉報(bào)

ID:863362 發(fā)表于 2022-12-22 17:52 | 顯示全部樓層
代碼和原理圖都需要修改一下才能顯示正確。
回復(fù)

使用道具 舉報(bào)

ID:894868 發(fā)表于 2023-2-10 15:29 | 顯示全部樓層
模擬了一下不正常的程序···
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 天堂综合网久久 | 免费一区在线观看 | 亚洲一在线 | 深夜福利影院 | 天堂中文在线播放 | 久久精品国产久精国产 | 成人在线一级片 | 亚洲中午字幕 | 国产日韩欧美电影 | 日韩久久久久久久久久久 | 国产精品999| 国产精品欧美日韩 | 国产一区二区在线视频 | 日本精品999| 国内精品伊人久久久久网站 | 日韩在线中文字幕 | 99精品国产一区二区三区 | 在线观看黄色电影 | 懂色中文一区二区三区在线视频 | 欧美亚洲视频 | 日本一道本视频 | 国产乱码精品1区2区3区 | 黄色福利 | 日本中文在线 | 国产精品小视频在线观看 | 精品久久久久一区二区国产 | 欧美综合一区二区三区 | 国产成人久久av免费高清密臂 | 91精品国产综合久久久久久 | 国产日韩久久 | 一区二区三区在线免费 | 欧美国产精品一区二区三区 | 国产成人综合亚洲欧美94在线 | 日日综合| 欧美精品一区二区三区蜜桃视频 | 日韩欧美国产精品一区 | 久久精品国产久精国产 | 亚洲福利在线观看 | 韩日在线| 天堂一区二区三区四区 | 午夜国产一区 |