STC89C52單片機的定時器使用
/////////////////////////////////////////////////////////////////////////
#include
#define uchar unsigned char
#define uint
uchar cTime_10ms_counter;
uchar cTime_1s_ok;
uchar uDis_buff[6];
uchar cTime[3];
#define Time_1s_Sign 100
sbit led=P1^0;
sbit Duan=P2^6;
sbit Wei =P2^7;
#define Digital_tube_Wei_Enable Wei=1;
#define Digital_tube_Wei_Disable Wei=0;
#define Digital_tube_Duan_Enable Duan=1;
#define Digital_tube_Duan_Disable Duan=0;
#define Digital_tube_Duan P0
uchar code Dis_table[]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40,0x00};
uchar code Dis_Position[]=
{0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
/////////////////////////////////////////////////////////////////////////
函數(shù)名稱:毫秒延時函數(shù)
函數(shù)功能:實現(xiàn)毫秒級的延時
參數(shù)介紹:Delay_MS: 定義需要延時的毫秒的數(shù)值
返回值:
注意事項:本實驗是在所用晶振為12M的前提下實現(xiàn)的毫秒延時,本函數(shù)是通過循環(huán)的形
/////////////////////////////////////////////////////////////////////////
void DelayMs(uint Delay_MS)
{
}
/////////////////////////////////////////////////////////////////////////
函數(shù)名稱:One_DigitalTube_display
函數(shù)功能:完成在實驗板上數(shù)碼管指定顯示,即在特定的數(shù)碼管上顯示特定的數(shù)字,比
參數(shù)介紹:cData:要顯示的數(shù)字的BCD碼數(shù)組
返回值:
注意事項:實驗板上的數(shù)碼管是共陰極的數(shù)碼管,如果使用共陽極的數(shù)碼管,請注意不
/////////////////////////////////////////////////////////////////////////
void One_DigitalTube_display(uchar cData,uchar cNumber)
{
}
/////////////////////////////////////////////////////////////////////////
函數(shù)名稱:Time_to_disbuffer
函數(shù)功能:把要在數(shù)碼管上顯示的數(shù)值,進行取余、取整,即對數(shù)值進行分割,這樣以
參數(shù)介紹:cNumber1:
返回值:
注意事項:無
/////////////////////////////////////////////////////////////////////////
void Time_to_disbuffer()
{
}
/////////////////////////////////////////////////////////////////////////
函數(shù)名稱:Init_time2
函數(shù)功能:配置定時器2,配置的模式是定時器1采用16位定時器模式,在定時器1的輸入
參數(shù)介紹:無
返回值:
注意事項:無
/////////////////////////////////////////////////////////////////////////
void Init_time1(void)
{
}
/////////////////////////////////////////////////////////////////////////
函數(shù)名稱:Timer_Display
函數(shù)功能:把顯示緩沖區(qū)的數(shù)值顯示在數(shù)碼管上
參數(shù)介紹:cNumber:記錄for語句的循環(huán)次數(shù)
返回值:
注意事項:無
/////////////////////////////////////////////////////////////////////////
void Timer_Display()
{
}
/////////////////////////////////////////////////////////////////////////
函數(shù)名稱:main
函數(shù)功能:利用定時器2中斷,實現(xiàn)準確的時鐘系統(tǒng),然后在數(shù)碼管上顯示實現(xiàn)
參數(shù)介紹:無
返回值:
注意事項:無
/////////////////////////////////////////////////////////////////////////
void main()
{
}
/////////////////////////////////////////////////////////////////////////
函數(shù)名稱:Interrupt_handler_time2
函數(shù)功能:重新給寄存器TH2和TL2賦值,判斷是否到達一秒,如果到一秒了,把相應的
參數(shù)介紹:無
返回值:
注意事項:無
/////////////////////////////////////////////////////////////////////////
void Interrupt_handler_time2(void) interrupt 5
{
}
評論