導航:首頁 > 軟體知識 > 電子表程序怎麼調

電子表程序怎麼調

發布時間:2024-06-25 02:52:56

『壹』 求一個關於用C語言編寫的電子時鍾的程序,內容要有鬧鍾,可以調整時間

#include<reg52.h>
#include<absacc.h>
#include<intrins.h>
#define unit unsigned int
#define uchar unsigned char
//#define HZ 12
sbit key0=P0^0; // 分鍾調整
sbit key1=P0^1; // 小時調整

sbit P2_0=P2^7; //秒 指示燈
sbit MN_RXD=P3^6;
sbit MN_TXD=P3^7;

uchar data CLOCK[4]={0,0,0,12};//存放時鍾時間(百分秒,秒,分,和時位)

//數碼管顯示表0-f 滅
uchar code TABLE[]={0xBE,0x06,0xEA,0x6E,0x56,0x7C,0xFC,0x0E,0xFE,0x7E,0x00};
//**********************************
//模擬串口發送一個位元組數據 函數
//**********************************
void SendData(unsigned char senddata)
{
unsigned char i;
for(i=0;i<8;i++)
{
if((senddata&0x01)==0)
MN_RXD=0;
else
MN_RXD=1;
_nop_();
MN_TXD=0;
_nop_();
MN_TXD=1;
senddata=senddata>>1;
}
}

//**********************************
//顯示程序函數
//**********************************
void display(void)
{
// unsigned int n;
uchar temp;
temp=CLOCK[1]; temp=temp%10; SendData(TABLE[temp]);
temp=CLOCK[1]; temp=temp/10; SendData(TABLE[temp]);
temp=CLOCK[2]; temp=temp%10; SendData(TABLE[temp]);
temp=CLOCK[2]; temp=temp/10; SendData(TABLE[temp]);
temp=CLOCK[3]; temp=temp%10; SendData(TABLE[temp]);
temp=CLOCK[3]; temp=temp/10; SendData(TABLE[temp]);

/*
for(n=0;n<5000;n++);

for(n=0;n<6;n++)
{
SendData(TABLE[10]);
}
*/
}

//**********************************
//按鍵控制函數
//**********************************
void keycan()
{
unsigned int n;
EA=0;
if(key0==0) // 分鍾調整
{
for(n=0;n<10000;n++); //延時去抖動
while(key0==0);
CLOCK[2]=CLOCK[2]+1;
if(CLOCK[2]==60) //到一時
{
CLOCK[2]=0;
}
display();

}
if(key1==0) // 小時調整
{
for(n=0;n<10000;n++); //延時去抖動
while(key1==0);
CLOCK[3]=CLOCK[3]+1;
if(CLOCK[3]==24)
{
CLOCK[3]=0;
}
display();

}
EA=1;
}

//**********************************
//T0中斷服務函數
//**********************************
void time0() interrupt 1 //using 1
{
TH0=0xD8; TL0=0xF0; //重置初值
// TH0=0xB1; TL0=0xE0;
//時鍾處理
CLOCK[0]=CLOCK[0]+1;

}
//**********************************
//主函數
//**********************************
void main()
{
EA=1;
ET0=1;
TMOD=0x01; //T0方式1定時
TH0=0xD8; TL0=0xF0; //D8F0 定時10ms
// TH0=0xB1; TL0=0xE0; //定時 20ms
TR0=1;
for(;;)
{
if(CLOCK[0]==100) //到一秒 10ms*100
{
CLOCK[0]=0;
P2_0=~P2_0;
CLOCK[1]=CLOCK[1]+1;
if(CLOCK[1]==60) //到一分
{
CLOCK[1]=0;
CLOCK[2]=CLOCK[2]+1;
if(CLOCK[2]==60) //到一時
{
CLOCK[2]=0;
CLOCK[3]=CLOCK[3]+1;
if(CLOCK[3]==24)
{
CLOCK[3]=0;
}
}
}
display();
}

keycan();
}

}

閱讀全文

與電子表程序怎麼調相關的資料

熱點內容
單招樂山職業技術學院大概多少分 瀏覽:571
唐山二手解放交易市場在哪裡 瀏覽:722
球球大作戰怎麼申請技術主播 瀏覽:839
鑫希國際多少錢拿代理 瀏覽:936
美容產品如何投放廣告 瀏覽:843
lee牌湖南省總代理在哪裡 瀏覽:465
渤海商品交易軟體在哪裡下載 瀏覽:149
什麼產品補鐵補血最好 瀏覽:168
如何查看達人幫自己帶貨的數據 瀏覽:654
海運代理哪些店賺錢 瀏覽:493
查詢車輛信息保險怎麼查 瀏覽:10
su如何改材質數據 瀏覽:991
電子支付不是什麼創新和技術革命 瀏覽:365
關於蟬的信息有哪些 瀏覽:230
網路驅動程序干什麼的 瀏覽:850
終結執行程序怎麼恢復 瀏覽:780
支付交易記錄保存多久 瀏覽:418
成都的證券交易所什麼時候成立的 瀏覽:975
超級pos做代理有什麼要求 瀏覽:636
移動安全信息停機是怎麼回事 瀏覽:982