大家能看一下我的程序有什么问题吗,求大神帮忙修改
时间:10-02
整理:3721RD
点击:
#include <reg52.h>#define uint unsigned int
#define uchar unsigned char
/**************************
LED段码表
************************************/
uchar code LEDData[]=
{
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
};
/****************************************
定义全局变量
**************************************/
uchar AD_DATA[4];
sbit OE = P1^3;
sbit EOC = P1^4;
sbit ST = P1^5;
sbit CLK = P1^2;
sbit CW1=P2^4;
sbit CLK1=P2^5;
sbit CW2=P2^6;
sbit CLK2=P2^7;
int k,i;
int m,n,e1,e2;
uint h;
/***********************************
延时函数
****************************************/
void DelayMS(uint ms)
{
uchar i;
while(ms--)
{
for(i=0;i<120;i++);
}
}
delay(){
for(m=0;m<10000;m++){;}
for(m=0;m<10000;m++){;}
for(m=0;m<10000;m++){;}
for(m=0;m<10000;m++){;}
for(m=0;m<10000;m++){;}
}
/***********************************
LED数码管显示程序
***********************************/
void Display_Result(uchar d)
{ for(i=0;i<100;i++)
{
P2 = 0xf7;
P0 = LEDData[d%10];
DelayMS(5);
P2 = 0xfb;
P0 = LEDData[d%100/10];
DelayMS(5);
P2 = 0xfd;
P0 = LEDData[d/100];
DelayMS(5);
}
}
/*********************************
步进电机控制程序
********************************/
void Dianji(void)
{
TMOD=0x01;
CW1=0;
CW2=0;
CLK1=0;
CLK2=0;
h=1;
delay();
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
EA=1;
ET0=1;
TR0=1;
do {}
while (1);
}
void timer0(void) interrupt 1 using 1
{
if((AD_DATA[0]>AD_DATA[2])&&((AD_DATA[0]-AD_DATA[2])>=e1))
{ n=AD_DATA[0]-AD_DATA[2];
if (h<=1080*n) /*脉冲数*/
{
TR0=0;
CLK1=!CLK1;
for(m=0;m<30;m++)
{
;
}
CLK1=!CLK1;
h++;
}
}
else if((AD_DATA[0]<AD_DATA[2])&&((AD_DATA[2]-AD_DATA[0])>=e1))
{ n=AD_DATA[2]-AD_DATA[0];
CW1=1;
if (h<=1080*n) /*脉冲数*/
{
TR0=0;
CLK1=!CLK1;
for(m=0;m<30;m++)
{
;
}
CLK1=!CLK1;
h++;
}
}
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
TR0=1;
if((AD_DATA[1]>AD_DATA[3])&&((AD_DATA[1]-AD_DATA[3])>=e2))
{ n=AD_DATA[1]-AD_DATA[3];
if (i<=1080*n) /*脉冲数*/
{
TR0=0;
CLK2=!CLK2;
for(m=0;m<30;m++)
{
;
}
CLK2=!CLK2;
i++;
}
}
else if((AD_DATA[1]<AD_DATA[3])&&((AD_DATA[3]-AD_DATA[1])>=e2))
{ n=AD_DATA[3]-AD_DATA[1];
CW2=1;
if (i<=1080*n) /*脉冲数*/
{
TR0=0;
CLK2=!CLK2;
for(m=0;m<30;m++)
{
;
}
CLK2=!CLK2;
i++;
}
}
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
TR0=1;
}
void Init_ADC()
{
TMOD = 0x02;
TH0 = 0x14;
TL0 = 0x00;
IE = 0x82;
TR0 = 1;
}
/************************************
AD转换程序
***************************************/
void ADC()
{
while(1)
{
P1 = 0x3f;
ST = 0;
ST = 1;
ST = 0;
while(EOC == 0);
OE = 1;
AD_DATA[0]=P3;
Display_Result(AD_DATA[0]);
OE = 0;
DelayMS(500);
P1 = 0x3e;
ST = 0;
ST = 1;
ST = 0;
while(EOC == 0);
OE = 1;
AD_DATA[1]=P3;
Display_Result(AD_DATA[1]);
OE = 0;
DelayMS(500);
P1 = 0x3d;
ST = 0;
ST = 1;
ST = 0;
while(EOC == 0);
OE = 1;
AD_DATA[2]=P3;
Display_Result(AD_DATA[2]);
OE = 0;
DelayMS(500);
P1 = 0x3c;
ST = 0;
ST = 1;
ST = 0;
while(EOC == 0);
OE = 1;
AD_DATA[3]=P3;
Display_Result(AD_DATA[3]);
OE = 0;
DelayMS(500);
}
}
void Timer0_INT() interrupt 1
{
CLK = !CLK;
}
void main()
{
e1=3;
e2=3;
Init_ADC();
ADC();
Dianji();
}
#define uchar unsigned char
/**************************
LED段码表
************************************/
uchar code LEDData[]=
{
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
};
/****************************************
定义全局变量
**************************************/
uchar AD_DATA[4];
sbit OE = P1^3;
sbit EOC = P1^4;
sbit ST = P1^5;
sbit CLK = P1^2;
sbit CW1=P2^4;
sbit CLK1=P2^5;
sbit CW2=P2^6;
sbit CLK2=P2^7;
int k,i;
int m,n,e1,e2;
uint h;
/***********************************
延时函数
****************************************/
void DelayMS(uint ms)
{
uchar i;
while(ms--)
{
for(i=0;i<120;i++);
}
}
delay(){
for(m=0;m<10000;m++){;}
for(m=0;m<10000;m++){;}
for(m=0;m<10000;m++){;}
for(m=0;m<10000;m++){;}
for(m=0;m<10000;m++){;}
}
/***********************************
LED数码管显示程序
***********************************/
void Display_Result(uchar d)
{ for(i=0;i<100;i++)
{
P2 = 0xf7;
P0 = LEDData[d%10];
DelayMS(5);
P2 = 0xfb;
P0 = LEDData[d%100/10];
DelayMS(5);
P2 = 0xfd;
P0 = LEDData[d/100];
DelayMS(5);
}
}
/*********************************
步进电机控制程序
********************************/
void Dianji(void)
{
TMOD=0x01;
CW1=0;
CW2=0;
CLK1=0;
CLK2=0;
h=1;
delay();
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
EA=1;
ET0=1;
TR0=1;
do {}
while (1);
}
void timer0(void) interrupt 1 using 1
{
if((AD_DATA[0]>AD_DATA[2])&&((AD_DATA[0]-AD_DATA[2])>=e1))
{ n=AD_DATA[0]-AD_DATA[2];
if (h<=1080*n) /*脉冲数*/
{
TR0=0;
CLK1=!CLK1;
for(m=0;m<30;m++)
{
;
}
CLK1=!CLK1;
h++;
}
}
else if((AD_DATA[0]<AD_DATA[2])&&((AD_DATA[2]-AD_DATA[0])>=e1))
{ n=AD_DATA[2]-AD_DATA[0];
CW1=1;
if (h<=1080*n) /*脉冲数*/
{
TR0=0;
CLK1=!CLK1;
for(m=0;m<30;m++)
{
;
}
CLK1=!CLK1;
h++;
}
}
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
TR0=1;
if((AD_DATA[1]>AD_DATA[3])&&((AD_DATA[1]-AD_DATA[3])>=e2))
{ n=AD_DATA[1]-AD_DATA[3];
if (i<=1080*n) /*脉冲数*/
{
TR0=0;
CLK2=!CLK2;
for(m=0;m<30;m++)
{
;
}
CLK2=!CLK2;
i++;
}
}
else if((AD_DATA[1]<AD_DATA[3])&&((AD_DATA[3]-AD_DATA[1])>=e2))
{ n=AD_DATA[3]-AD_DATA[1];
CW2=1;
if (i<=1080*n) /*脉冲数*/
{
TR0=0;
CLK2=!CLK2;
for(m=0;m<30;m++)
{
;
}
CLK2=!CLK2;
i++;
}
}
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
TR0=1;
}
void Init_ADC()
{
TMOD = 0x02;
TH0 = 0x14;
TL0 = 0x00;
IE = 0x82;
TR0 = 1;
}
/************************************
AD转换程序
***************************************/
void ADC()
{
while(1)
{
P1 = 0x3f;
ST = 0;
ST = 1;
ST = 0;
while(EOC == 0);
OE = 1;
AD_DATA[0]=P3;
Display_Result(AD_DATA[0]);
OE = 0;
DelayMS(500);
P1 = 0x3e;
ST = 0;
ST = 1;
ST = 0;
while(EOC == 0);
OE = 1;
AD_DATA[1]=P3;
Display_Result(AD_DATA[1]);
OE = 0;
DelayMS(500);
P1 = 0x3d;
ST = 0;
ST = 1;
ST = 0;
while(EOC == 0);
OE = 1;
AD_DATA[2]=P3;
Display_Result(AD_DATA[2]);
OE = 0;
DelayMS(500);
P1 = 0x3c;
ST = 0;
ST = 1;
ST = 0;
while(EOC == 0);
OE = 1;
AD_DATA[3]=P3;
Display_Result(AD_DATA[3]);
OE = 0;
DelayMS(500);
}
}
void Timer0_INT() interrupt 1
{
CLK = !CLK;
}
void main()
{
e1=3;
e2=3;
Init_ADC();
ADC();
Dianji();
}
不是很理解,再看看