用KEIL软件编写控制单片机的程序,TLC549A/D转换,电位器 10
电位器接A/D转换接单片机,需要用KEIL编写串口程序,下载到单片机中,在串口助手上显示电位器的电压.求KEIL里的程序...
电位器接A/D转换接单片机,需要用KEIL编写串口程序,下载到单片机中,在串口助手上显示电位器的电压.求KEIL里的程序
展开
3个回答
展开全部
我可以给你两套源程序:
(1)
/*************** writer:shopping.w ******************/
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
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<120;i++);
}
}
void main()
{
uchar Val;
TMOD = 0x02;
TH0 = 0x14;
TL0 = 0x00;
IE = 0x82;
TR0 = 1;
while(1)
{
ST = 0;
ST = 1;
ST = 0;
while(!EOC);
OE = 1;
Val = P1;
OE = 0;
if(Val == 0)
{
PWM = 0;
DelayMS(0xff);
continue;
}
if(Val == 0xff)
{
PWM = 1;
DelayMS(0xff);
continue;
}
PWM = 1;
DelayMS(Val);
PWM = 0;
DelayMS(0xff - Val);
}
}
void Timer0_INT() interrupt 1
{
CLK = !CLK;
}
(2)
/*************** writer:shopping.w ******************/
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
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<120;i++);
}
}
void main()
{
uchar Val;
TMOD = 0x02;
TH0 = 0x14;
TL0 = 0x00;
IE = 0x82;
TR0 = 1;
while(1)
{
ST = 0;
ST = 1;
ST = 0;
while(!EOC);
OE = 1;
Val = P1;
OE = 0;
if(Val == 0)
{
PWM = 0;
DelayMS(0xff);
continue;
}
if(Val == 0xff)
{
PWM = 1;
DelayMS(0xff);
continue;
}
PWM = 1;
DelayMS(Val);
PWM = 0;
DelayMS(0xff - Val);
}
}
void Timer0_INT() interrupt 1
{
CLK = !CLK;
}
(1)
/*************** writer:shopping.w ******************/
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
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<120;i++);
}
}
void main()
{
uchar Val;
TMOD = 0x02;
TH0 = 0x14;
TL0 = 0x00;
IE = 0x82;
TR0 = 1;
while(1)
{
ST = 0;
ST = 1;
ST = 0;
while(!EOC);
OE = 1;
Val = P1;
OE = 0;
if(Val == 0)
{
PWM = 0;
DelayMS(0xff);
continue;
}
if(Val == 0xff)
{
PWM = 1;
DelayMS(0xff);
continue;
}
PWM = 1;
DelayMS(Val);
PWM = 0;
DelayMS(0xff - Val);
}
}
void Timer0_INT() interrupt 1
{
CLK = !CLK;
}
(2)
/*************** writer:shopping.w ******************/
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
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<120;i++);
}
}
void main()
{
uchar Val;
TMOD = 0x02;
TH0 = 0x14;
TL0 = 0x00;
IE = 0x82;
TR0 = 1;
while(1)
{
ST = 0;
ST = 1;
ST = 0;
while(!EOC);
OE = 1;
Val = P1;
OE = 0;
if(Val == 0)
{
PWM = 0;
DelayMS(0xff);
continue;
}
if(Val == 0xff)
{
PWM = 1;
DelayMS(0xff);
continue;
}
PWM = 1;
DelayMS(Val);
PWM = 0;
DelayMS(0xff - Val);
}
}
void Timer0_INT() interrupt 1
{
CLK = !CLK;
}
追问
已经解决了,谢谢~
追答
其实你不懂,我是来删除我的回复的!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询