标题:
单片机+adc0808控制pwm输出程序
[打印本页]
作者:
hufd
时间:
2022-6-20 16:26
标题:
单片机+adc0808控制pwm输出程序
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit CLK=P2^4;
sbit ST=P2^5;
sbit EOC=P2^6;
sbit OE=P2^7;
sbit PWM=P3^0;
void DelayMS(uint ms)
{
uchar i;
while(ms--) for(i=0;i<40;i++);
}
void main()
{
uchar Va1;
TMOD=0x02;
TH0=0x14;
TL0=0x00;
IE=0x82;
TR0=1;
while(1)
{
ST=0;ST=1;ST=0;
while(!EOC);
OE=1;
Va1=p1;
OE=0;
if(Va1==0)
{
PWM=0;
if(Va1==0xff);
continue;
}
if(Va1==0xff)
{
PWM=1;
DelayMS(0xfff);
continue;
}
PWM=1;
DelayMS(Va1);
PWM=0;
DelayMS(0xff-Val);
}
}
void Timer0_INT() interrupt 1
{
CLK=~CLK;
}
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1