|
- /**********************
- 文件名稱:Led.c
- 作者:曹婷
- 說(shuō)明:進(jìn)行LED測(cè)試的例程
- 修改記錄:
- ***********************/
- /**********************
- 基于STC15F2K60S2系列單片機(jī)C語(yǔ)言編程實(shí)現(xiàn)
- 使用如下頭文件,不用另外再包含"REG51.H"
- ***********************/
- #include "STC15F2K60S2.H"
- #define uint unsigned int
- #define uchar unsigned char
- /**********************
- 引腳別名定義
- ***********************/
- sbit Led_sel=P2^3;
- /**********************
- 變量定義
- ***********************/
- uchar G_value;
- /**********************
- 函數(shù)名稱:Init
- 功能描述:系統(tǒng)初始化
- 入口參數(shù):無(wú)
- 出口參數(shù):無(wú)
- 備注:
- ***********************/
- void Init()
- {
- //設(shè)置推挽輸出//
- P2M1=0x00;
- P2M0=0xff;
- P0M1=0x00;
- P0M0=0xff;
- Led_sel=1;
- }
- /**********************
- 函數(shù)名稱:Delay_1ms
- 功能描述:延時(shí)
- 入口參數(shù):unsigned int t 表示要延時(shí)t個(gè)1ms
- 出口參數(shù):無(wú)
- 備注:通過(guò)參數(shù)t,控制延時(shí)的時(shí)間長(zhǎng)短
- ***********************/
- void Delay_1ms(uint t)
- {
- uchar j;
- for(;t>0;t--)
- for(j=110;j>0;j--)
- ;
- }
- /**********************
- 函數(shù)名稱:Led_test
- 功能描述:對(duì)8個(gè)二極管進(jìn)行測(cè)試,依次輪流點(diǎn)亮8個(gè)二極管
- 入口參數(shù):無(wú)
- 出口參數(shù):無(wú)
- 備注:
- ***********************/
- void Led_test()
- {
- G_value=0x01;
- while(1)
- {
- P0=G_value;
- Delay_1ms(10000);
- G_value=G_value<<1;
- if(G_value==0x00)
- {
- P0=G_value;
- Delay_1ms(10000);
- G_value=0x01;
- }
- }
- }
- void main()
- {
- Init();
- Led_test();
- }
復(fù)制代碼
|
-
-
流水燈工程.zip
2019-12-18 09:34 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
93.2 KB, 下載次數(shù): 4, 下載積分: 黑幣 -5
匯編和C源碼
|