標題:
單片機PWM輸出程序
[打印本頁]
作者:
Ysmooth
時間:
2016-8-31 21:42
標題:
單片機PWM輸出程序
#include "reg52.h"
typedef unsigned char u8;
typedef unsigned int u16;
sbit scl=P2^1;
u16 tim=0,count=0;
void Tim1_init()
{
TMOD=0X10;
TH1=0XFF;
TL1=0XFF;//1us
TR1=1;
ET1=1;
EA=1;
}
void tim1() interrupt 3
{
TH1=0Xff;
TL1=0Xff;//1ms
tim++;
count++;
}
void main()
{
u8 fx=1;
u16 value=0;
Tim1_init();
while(1)
{
if(count>=500)
{
count=0;
if(fx==1)
{
value++;
if(value==500)
{
fx=0;
}
}
else
{
value--;
if(value==0)
{
fx=1;
}
}
}
if(tim>=500) //PWMΪ0.5s
{
tim=0;
}
if(tim<=value)
{
scl=1;
}
else
{
scl=0;
}
}
}
復制代碼
102.PWM輸出.zip
(16.67 KB, 下載次數(shù): 6)
2016-8-31 21:42 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1