資源簡介
這個是數碼管驅動,2個IO口驅6位數碼管,而且同時還能外接12個按鍵

代碼片段和文件信息
/*
?*單片機型號:?AT89S52
?*開發環境:???Keil?uVision3
?*晶震頻率:???12M
?*功能:?????TM1637做時鐘顯示,可以由按鍵控制數碼屏顯示0-9
*/
#include
#include
#include
#define?uchar?unsigned?char
#define?uint??unsigned?int
uchar?CODE[16]?=?{0x3f0x060x5b0x4f0x660x6d0x7d0x070x7f0x6f0x770x7c0x390x5e0x790x71};
uchar?show_LED[6]key;
uchar?TIME_count;
uchar?TIME_secondsseconds_2sub_1sub_2;?//時間寄存器依次從秒個位至分十位
/**********************************
?????定時中斷函數入口
功能:?每50MS中斷一次
**********************************/??
void?time0(void)?interrupt?1?using?2
{
??TH0=0x3c;
??TL0=0xb0;
??TIME_count++;
??if(TIME_count==20)
??{
????TIME_count?=?0;
????TIME_seconds++; //?秒寄存器加1
???}
}????
/*********************************
?????時鐘函數
功能:?處理時鐘顯示
**********************************/
void?TIME_show()
{
??show_LED[0]?=?CODE[TIME_seconds];//?數碼屏上最后一個“8”字,依次下去
??show_LED[1]?=?CODE[seconds_2];???//數碼屏倒數第二個“8”字,
??show_LED[2]?=?CODE[sub_1];
??show_LED[3]?=?CODE[sub_2];
??if(TIME_seconds?==?10) ??//對時間數據進行處理,以免溢出。
???{
?????TIME_seconds?=?0;
?seconds_2+=1;
}
??if(seconds_2?==?6)
???{
?????seconds_2?=?0;
?sub_1?+=1;
}
??if(sub_1?==?10)
???{
?????sub_1?=?0;
?sub_2?+=1;
}
??if(sub_2?==?6)
???{
?sub_2?=?0;
?sub_1?=?0;
?seconds_2?=?0;
}
}
/*********************************
????延時函數
功能:?1ms延時
**********************************/
void?delay_ms(uchar?cyc)
{
//cyc=1的時候延時1ms
uchar?iijj;
for(jj=1;jj<=cyc;jj++)
{
for(ii=0;ii<200;ii++)
{
nop;
}
}
}?
//----------主函數-----------------
void?main()
{
?P1=0xff;//初始化單片機I/O口
?TH0=0x3c;
?TL0=0xb0;
?TMOD=0x01;??//定時器設置
?IE=0x82;
?EA=1;
?ET0=1;
?TR0=1;
?while(1)//循環
?{
?key=readkey();
?if?(key?!=255)??show_LED[5]?=?CODE[key];
?TIME_show();
?showled(show_LED);
?delay_ms(50);
?}
} ????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????12569??2010-03-23?17:32??ok!TM1637-c51數碼管顯示演示代碼\tm1637
?????文件???????2008??2010-10-31?11:48??ok!TM1637-c51數碼管顯示演示代碼\tm1637.c
?????文件???????3820??2010-03-23?17:18??ok!TM1637-c51數碼管顯示演示代碼\TM1637.H
?????文件???????2254??2010-03-23?17:32??ok!TM1637-c51數碼管顯示演示代碼\tm1637.hex
?????文件?????????44??2010-03-23?17:32??ok!TM1637-c51數碼管顯示演示代碼\tm1637.lnp
?????文件???????4966??2010-03-23?17:32??ok!TM1637-c51數碼管顯示演示代碼\tm1637.LST
?????文件??????15469??2010-03-23?17:32??ok!TM1637-c51數碼管顯示演示代碼\tm1637.M51
?????文件??????13966??2010-03-23?17:32??ok!TM1637-c51數碼管顯示演示代碼\tm1637.OBJ
?????文件???????1450??2010-04-07?22:20??ok!TM1637-c51數碼管顯示演示代碼\tm1637.Opt
?????文件????????268??2010-04-07?22:20??ok!TM1637-c51數碼管顯示演示代碼\tm1637.plg
?????文件???????2009??2010-04-07?21:25??ok!TM1637-c51數碼管顯示演示代碼\tm1637.Uv2
?????文件???????1450??2010-04-07?21:25??ok!TM1637-c51數碼管顯示演示代碼\tm1637_Opt.Bak
?????文件???????1995??2010-03-23?16:30??ok!TM1637-c51數碼管顯示演示代碼\tm1637_Uv2.Bak
?????目錄??????????0??2010-06-02?18:31??ok!TM1637-c51數碼管顯示演示代碼
-----------?---------??----------?-----??----
????????????????62268????????????????????14
- 上一篇:ant design pro動態菜單
- 下一篇:用prolog解決農夫過河問題
評論
共有 條評論