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

電子表程序怎麼調

發布時間: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();
}

}

閱讀全文

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

熱點內容
錯過別人信息怎麼辦 瀏覽:174
電子產品不是洪水猛獸怎麼辦 瀏覽:617
一個車間生產兩種產品怎麼收費 瀏覽:835
無錫工藝技術職業學院多少分 瀏覽:227
臨汾市職業技術學院就業怎麼樣 瀏覽:96
觀音街小商品市場在哪裡 瀏覽:296
期貨交易中如何割肉 瀏覽:544
交易高手如何獲取信號 瀏覽:467
26歲程序員怎麼規劃 瀏覽:642
山西注漿技術多少錢 瀏覽:273
建設銀行停止此交易是什麼情況 瀏覽:296
有三維模型如何讓產品旋轉 瀏覽:675
微信快手小程序在哪裡找 瀏覽:43
馬邊有哪些的農貿市場 瀏覽:120
民事通則代理人身份的責任有哪些 瀏覽:743
新型藍海市場是什麼 瀏覽:872
大學校招信息在哪裡看 瀏覽:612
合肥刷一階程序要多少錢 瀏覽:141
河南市場營銷哪些學校好 瀏覽:740
印尼手機市場價格怎麼樣 瀏覽:9