Sao cái chương trình của em em nhìn không có lỗi mà dịch trong kelic nó cứ báo lỗi syntax eror near "="
Chương trình của em đây,mấy anh xem lỗi ở đâu,em xin cảm ơn :
#include <REG51F.H>
#define stop P1^0
#define thuan P1^1
#define nghich P1^2
#define tang P1^3
#define giam P1^4
bit PWM;
unsigned char dem=0;
unsigned int phantram_PWM=10;
/* Ham tao thoi gian tre*/
void delay(unsigned int t)
{
unsigned int i,j;
for(i=0;i<100;i++)
for(j=0;j<t;j++);
}
/* Hien thi gia tri tang giam toc*/
unsigned char LED[10]={0x40,0xf9,0x24,0x30,0x19,0x12,0x02,0xf8,0x80,0x1 0};
void hienthi(unsigned char digit1, unsigned char digit2)
{
/*Hien thi so thu nhat*/
P3=LED[digit1];
P0^0=1;
delay(2);
P0^0=0;
/*Hien thi so 2*/
P3=LED[digit2];
P0^1=1;
delay(2);
P0^1=0;
}
/* Khoi tao Timer 100us*/
void khoitaohethong()
{
ES=1;
EA=0;
TMOD=0x02; // che do 8 bit tu nap
TH0=0x9b; // nap gia tri 155 ma hex
TL0=0x9b;
EA=1;
TR0=1;
ET0=1;
}
/* Ngat tao ra PWM*/
void ngat_timer0(void) interrupt 1
{
TR0=0;
TF0=0;
dem++;
if(dem>=phantram_PWM)
{
PWM=1;
}
else
{
PWM=0;
}
if(dem==20) dem=0;
TR0=1;
}
/* Ham dung dong co*/
void stopdc(void)
{
P2^0=0;
P2^1=0;
P2^2=0;
P2^3=1;
P2^4=1;
}
/* Ham quay thuan dong co*/
void quaythuan(void)
{
P2^1=0;
P2^0=PWM;
P2^3=0;
P2^2=1;
P2^4=1;
}
/* Ham quay nghich dong co*/
void quaynghich(void)
{
P2^0=0;
P2^1=PWM;
P2^4=0;
P2^3=1;
P2^2=1;
}
/* Ham dieu khien tang toc*/
unsigned char tangtoc(void)
{
if(tang==0)
{
while(tang==0)
{;}
phantram_PWM--;
delay(100);
if(phantram_PWM<1)
{
phantram_PWM=1;
} }
return (phantram_PWM);
}
/* Ham dieu khien giam toc*/
unsigned char giamtoc(void)
{
if(giam==0)
{
while(giam==0)
{;}
phantram_PWM++;
delay(100);
if(phantram_PWM>20)
phantram_PWM=20;
}
return (phantram_PWM);
}
/* Lua chon che do cua dong co*/
unsigned char n;
unsigned char chonchedo(void)
{
if(stop==0) n=1;
if(thuan==0) n=2;
if(nghich==0) n=3;
switch(n)
{
case 0: {break;}
case 1: {stopdc();break;}
case 2: {quaythuan();break;}
case 3: {quaynghich();break;}
}
return (n);
}
/* Chuong trinh chinh*/
void main()
{
khoitaohethong();
while(1)
{
tangtoc();
giamtoc();
chonchedo();
hienthi((20-phantram_PWM)/10,(20-phantram_PWM)%10);
}
}
Chương trình của em đây,mấy anh xem lỗi ở đâu,em xin cảm ơn :
#include <REG51F.H>
#define stop P1^0
#define thuan P1^1
#define nghich P1^2
#define tang P1^3
#define giam P1^4
bit PWM;
unsigned char dem=0;
unsigned int phantram_PWM=10;
/* Ham tao thoi gian tre*/
void delay(unsigned int t)
{
unsigned int i,j;
for(i=0;i<100;i++)
for(j=0;j<t;j++);
}
/* Hien thi gia tri tang giam toc*/
unsigned char LED[10]={0x40,0xf9,0x24,0x30,0x19,0x12,0x02,0xf8,0x80,0x1 0};
void hienthi(unsigned char digit1, unsigned char digit2)
{
/*Hien thi so thu nhat*/
P3=LED[digit1];
P0^0=1;
delay(2);
P0^0=0;
/*Hien thi so 2*/
P3=LED[digit2];
P0^1=1;
delay(2);
P0^1=0;
}
/* Khoi tao Timer 100us*/
void khoitaohethong()
{
ES=1;
EA=0;
TMOD=0x02; // che do 8 bit tu nap
TH0=0x9b; // nap gia tri 155 ma hex
TL0=0x9b;
EA=1;
TR0=1;
ET0=1;
}
/* Ngat tao ra PWM*/
void ngat_timer0(void) interrupt 1
{
TR0=0;
TF0=0;
dem++;
if(dem>=phantram_PWM)
{
PWM=1;
}
else
{
PWM=0;
}
if(dem==20) dem=0;
TR0=1;
}
/* Ham dung dong co*/
void stopdc(void)
{
P2^0=0;
P2^1=0;
P2^2=0;
P2^3=1;
P2^4=1;
}
/* Ham quay thuan dong co*/
void quaythuan(void)
{
P2^1=0;
P2^0=PWM;
P2^3=0;
P2^2=1;
P2^4=1;
}
/* Ham quay nghich dong co*/
void quaynghich(void)
{
P2^0=0;
P2^1=PWM;
P2^4=0;
P2^3=1;
P2^2=1;
}
/* Ham dieu khien tang toc*/
unsigned char tangtoc(void)
{
if(tang==0)
{
while(tang==0)
{;}
phantram_PWM--;
delay(100);
if(phantram_PWM<1)
{
phantram_PWM=1;
} }
return (phantram_PWM);
}
/* Ham dieu khien giam toc*/
unsigned char giamtoc(void)
{
if(giam==0)
{
while(giam==0)
{;}
phantram_PWM++;
delay(100);
if(phantram_PWM>20)
phantram_PWM=20;
}
return (phantram_PWM);
}
/* Lua chon che do cua dong co*/
unsigned char n;
unsigned char chonchedo(void)
{
if(stop==0) n=1;
if(thuan==0) n=2;
if(nghich==0) n=3;
switch(n)
{
case 0: {break;}
case 1: {stopdc();break;}
case 2: {quaythuan();break;}
case 3: {quaynghich();break;}
}
return (n);
}
/* Chuong trinh chinh*/
void main()
{
khoitaohethong();
while(1)
{
tangtoc();
giamtoc();
chonchedo();
hienthi((20-phantram_PWM)/10,(20-phantram_PWM)%10);
}
}
Comment