?????C????????????? ADC0808 ???? PWM ???
/* ??????? ADC0808 ???? PWM ???
??????????????о? ADC0808?????????????? RV1 ??????????????
???г??????????????????????????仯??
*/
#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; //PWM ???
//???
void DelayMS(uint ms)
{
uchar i;
while(ms--) for(i=0;i<40;i++);
}
//??????
void main()
{
uchar Val;
TMOD=0x02; //T1 ?????? 2
TH0=0x14;
TL0=0x00;
IE=0x82;
TR0=1;
while(1)
{
ST=0;ST=1;ST=0; //???? A/D ???
while(!EOC); //?????????
OE=1;
Val=P1; //??????
OE=0;
if(Val==0) //PWM ?????????? 0%??
{
PWM=0;
DelayMS(0xff);
continue;
if(Val==0xff) //PWM ?????????? 100%??
{
PWM=1;
DelayMS(0xff);
continue;
}
}
//T0 ??????ж?? ADC0808 ????????
void Timer0_INT() interrupt 1
{
CLK=~CLK;
}
PWM=1; //PWM ?????????? 0%~100%??
DelayMS(Val);
PWM=0;
DelayMS(0xff-Val);
???????????????C??????????

????admin ?????????2018-05-19