|
/*********************************************************************************************************
** 工程功能 :呼吸燈實(shí)驗(yàn)
** 工程作者 :Blue Sky Teams——ZZL
** 工程版本 :V1.0
** 工程說(shuō)明 :此程序?yàn)镻WM(脈寬調(diào)制)的應(yīng)用之一,詳細(xì)的原理會(huì)在后面講解PWM模塊程序的時(shí)候介紹
**
*********************************************************************************************************/
#include<STC12C5A60S2.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit LED0 = P0^0; //定義呼吸燈連接的端口
/*********************************************************************************************************
** 函數(shù)功能 :延時(shí)函數(shù)
** 函數(shù)說(shuō)明 :利用軟件延時(shí),占用CPU
** 入口參數(shù) :time:需要延時(shí)的時(shí)間
** 出口參數(shù) :無(wú)
*********************************************************************************************************/
void Delay(uint time)
{
uint i;
for(i = time;i> 0;i --);
}
void main()
{
uint temp , i;
while(1)
{
//通過(guò)不斷循環(huán)連續(xù)改變輸出脈沖的占空比來(lái)調(diào)整供給LED燈的支流功率,如脈沖占空比越大,脈沖的直流功率越大
for(temp = 0;temp <= 300;temp ++)
{
for(i=0;i<10;i++)
{
LED0 = 1;
Delay(temp);
LED0 = 0;
Delay(300-temp);
}
}
for(temp = 300;temp > 0;temp--)
{
for(i=0;i<10;i++)
{
LED0 = 1;
Delay(temp);
LED0 = 0;
Delay(300-temp);
}
}
}
}
/************************** (C) COPYRIGHT 2011 Blue Sky Teams *****END OF FILE*****************************/
|
評(píng)分
-
查看全部評(píng)分
|