jaiminpatel1234
Newbie level 1
- Joined
- Mar 31, 2014
- Messages
- 1
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 40
i am unable to display the rpm speed of my motor on LCD screen. While debugging in keil, I get all values correct. But when i load the program in the 8051 controller IC, it doesnt display value on LCD screen. It shows 0 rpm continuously.
Here is the code. please help.
#include<reg51.h>
#define LCDDATA P2
sbit BUSY=P2^7;
sbit RS=P3^7;
sbit RW=P3^6;
sbit EN=P3^5;
sbit MOUT=P0^7;
sbit UP_KEY=P1^0;
sbit DOWN_KEY=P1^1;
sbit in=P3^2;
//bit addresable area
bit INT0_Flag=0x10;
bit time_flag=0x11;
bit update_flag=0x12;
bit pulse_flag=0x13;
bit pulsetime_flag=0x14;
bit timecount_flag=0x15;
unsigned char int0_count;
unsigned int time_count;
unsigned int high_count;
unsigned int low_count;
unsigned int period,RPM;
unsigned char shift,COUNT;
void Init_LCD();
void Init_INT0();
void Init_Timer1();
void BusyCheck();
void msdelay(unsigned int itime);
void LCDCMD(unsigned char CMD);
void LCDData(unsigned char Data);
void LCDString(unsigned char *str);
void display(unsigned int num);
void LCDNUM(unsigned int NUM);
void delay();
void timer0_delay(int time);
void PWM_DELAY();
void speed_display(int shift);
void ISR_INT0() interrupt 0
{
if(update_flag==1)
{
Init_Timer1();
level3:int0_count++;
if(int0_count==2)
{
ET1=0;
TR1=0;
high_count=TH1;
low_count=TL1;
update_flag=0;
int0_count=0;
timecount_flag=1;
EA=0;
IE0=0;
}
else
{
ET1=1;
TR1=1;
level:if(in==1)
{
while(TF1==0)
{if(IE0==1)
{
goto level3;
}
}
if(TF1==1)
{
time_count=time_count+1;
TF1=0;
}
goto level;
}
}
}
}
//void Timer1_isr() interrupt 1
//{
//time_count=time_count+1;
//}
void PWM_DELAY()
{
MOUT=0;
timer0_delay(shift);
MOUT=1;
timer0_delay(100-shift);
}
void timer0_delay(int time)
{
int t;
for(t=0;t<time;t++)
{
TMOD=0x11;
TH0=0xFF;
TL0=0xBE;
TR0=1;
while(TF0==0);
TF0=0;
TR0=0;
}
}
void delay2()
{
int p,q;
for(p=0;p<500;p++)
for(q=0;q<800;q++);
}
void main()
{
P1=0xFF;
P2=0xFF;
P3=0xFF;
P0=0xFF;
Init_LCD();
Init_INT0();
Init_Timer1();
time_flag=0;
timecount_flag=0;
INT0_Flag=0;
int0_count=0;
time_count=0;
MOUT=1;
COUNT=0;
LCDCMD(0x80);
LCDString(" BLDC MOTOR ");
LCDCMD(0xC0);
LCDString(" SPEED CONTROL ");
delay2();
shift=0;
LCDCMD(0x01);
LCDCMD(0x80);
LCDString(" 0% of SPEED ");
LCDCMD(0xC0);
LCDString(" MOTOR_RPM=0 ");
while(1)
{
//PWM_DELAY();
if(timecount_flag==1)
{
//EA=0;
period=((time_count*71)+(((256*high_count)+low_count)*0.001085));
if(period==0)
{
RPM=0;
}
else
{
RPM=((60000)/period);
}
COUNT=COUNT+1;
if(COUNT==10)
{
COUNT=0;
LCDCMD(0xC0);
LCDNUM(RPM);
}
TH1=0x00;
TL1=0x00;
time_count=0;
timecount_flag=0;
update_flag=1;
EA=1;
}
PWM_DELAY();
if(UP_KEY==0)
{
shift=shift+10;
if(shift>100)
{
shift=100;
}
speed_display(shift);
msdelay(80);
}
if(DOWN_KEY==0)
{
shift=shift-10;
if(shift<0)
{
shift=0;
}
speed_display(shift);
msdelay(80);
}
}
}
void speed_display(int shift)
{
if(shift==0)
{
LCDCMD(0x80);
LCDString(" 0% of speed ");
}
else if(shift==10)
{
LCDCMD(0x80);
LCDString(" 10% of speed ");
}
else if(shift==20)
{
LCDCMD(0x80);
LCDString(" 20% of speed ");
}
else if(shift==30)
{
LCDCMD(0x80);
LCDString(" 30% of speed ");
}
else if(shift==40)
{
LCDCMD(0x80);
LCDString(" 40% of speed ");
}
else if(shift==50)
{
LCDCMD(0x80);
LCDString(" 50% of speed ");
}
else if(shift==60)
{
LCDCMD(0x80);
LCDString(" 60% of speed ");
}
else if(shift==70)
{
LCDCMD(0x80);
LCDString(" 70% of speed ");
}
else if(shift==80)
{
LCDCMD(0x80);
LCDString(" 80% of speed ");
}
else if(shift==90)
{
LCDCMD(0x80);
LCDString(" 90% of speed ");
}
else if(shift==100)
{
LCDCMD(0x80);
LCDString(" 100% of speed ");
}
}
void LCDNUM(unsigned int NUM)
{
unsigned char Buff[5]={'0'},i=0;
while(NUM)
{
Buff[i++]=(NUM%10)+0x30;
NUM=NUM/10;
}
if(!i)
{
LCDData('0');
LCDString(" ");
}
else
{
while(i--)
{
LCDData(Buff);
LCDCMD(0x06);
}
LCDString(" ");
}
}
void Init_INT0()
{
//in=1;
EA=1;
EX0=1;
IT0=1;
PX0=1;
//PT1=0x02;
}
void Init_Timer1()
{
ET1=1;
TMOD=0x10;
TH1=0x00;
TL1=0x00;
PT1=1;
}
void Init_LCD()
{
LCDCMD(0x38);
LCDCMD(0x06);
LCDCMD(0x0C);
LCDCMD(0x02);
}
void LCDCMD(unsigned char CMD)
{
LCDDATA=CMD;
RS=0;
RW=0;
EN=1;
msdelay(1);
EN=0;
//return;
}
void LCDData(unsigned char Data)
{
LCDDATA=Data;
RS=1;
RW=0;
EN=1;
msdelay(1);
EN=0;
//return;
}
void LCDString(unsigned char *str)
{
while(*str)
{
LCDData(*str++);
}
}
void BusyCheck()
{
BUSY=1;
RS=0;
RW=1;
while(BUSY==1)
{
EN=0;
msdelay(1);
EN=1;
}
}
void msdelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
Here is the code. please help.
#include<reg51.h>
#define LCDDATA P2
sbit BUSY=P2^7;
sbit RS=P3^7;
sbit RW=P3^6;
sbit EN=P3^5;
sbit MOUT=P0^7;
sbit UP_KEY=P1^0;
sbit DOWN_KEY=P1^1;
sbit in=P3^2;
//bit addresable area
bit INT0_Flag=0x10;
bit time_flag=0x11;
bit update_flag=0x12;
bit pulse_flag=0x13;
bit pulsetime_flag=0x14;
bit timecount_flag=0x15;
unsigned char int0_count;
unsigned int time_count;
unsigned int high_count;
unsigned int low_count;
unsigned int period,RPM;
unsigned char shift,COUNT;
void Init_LCD();
void Init_INT0();
void Init_Timer1();
void BusyCheck();
void msdelay(unsigned int itime);
void LCDCMD(unsigned char CMD);
void LCDData(unsigned char Data);
void LCDString(unsigned char *str);
void display(unsigned int num);
void LCDNUM(unsigned int NUM);
void delay();
void timer0_delay(int time);
void PWM_DELAY();
void speed_display(int shift);
void ISR_INT0() interrupt 0
{
if(update_flag==1)
{
Init_Timer1();
level3:int0_count++;
if(int0_count==2)
{
ET1=0;
TR1=0;
high_count=TH1;
low_count=TL1;
update_flag=0;
int0_count=0;
timecount_flag=1;
EA=0;
IE0=0;
}
else
{
ET1=1;
TR1=1;
level:if(in==1)
{
while(TF1==0)
{if(IE0==1)
{
goto level3;
}
}
if(TF1==1)
{
time_count=time_count+1;
TF1=0;
}
goto level;
}
}
}
}
//void Timer1_isr() interrupt 1
//{
//time_count=time_count+1;
//}
void PWM_DELAY()
{
MOUT=0;
timer0_delay(shift);
MOUT=1;
timer0_delay(100-shift);
}
void timer0_delay(int time)
{
int t;
for(t=0;t<time;t++)
{
TMOD=0x11;
TH0=0xFF;
TL0=0xBE;
TR0=1;
while(TF0==0);
TF0=0;
TR0=0;
}
}
void delay2()
{
int p,q;
for(p=0;p<500;p++)
for(q=0;q<800;q++);
}
void main()
{
P1=0xFF;
P2=0xFF;
P3=0xFF;
P0=0xFF;
Init_LCD();
Init_INT0();
Init_Timer1();
time_flag=0;
timecount_flag=0;
INT0_Flag=0;
int0_count=0;
time_count=0;
MOUT=1;
COUNT=0;
LCDCMD(0x80);
LCDString(" BLDC MOTOR ");
LCDCMD(0xC0);
LCDString(" SPEED CONTROL ");
delay2();
shift=0;
LCDCMD(0x01);
LCDCMD(0x80);
LCDString(" 0% of SPEED ");
LCDCMD(0xC0);
LCDString(" MOTOR_RPM=0 ");
while(1)
{
//PWM_DELAY();
if(timecount_flag==1)
{
//EA=0;
period=((time_count*71)+(((256*high_count)+low_count)*0.001085));
if(period==0)
{
RPM=0;
}
else
{
RPM=((60000)/period);
}
COUNT=COUNT+1;
if(COUNT==10)
{
COUNT=0;
LCDCMD(0xC0);
LCDNUM(RPM);
}
TH1=0x00;
TL1=0x00;
time_count=0;
timecount_flag=0;
update_flag=1;
EA=1;
}
PWM_DELAY();
if(UP_KEY==0)
{
shift=shift+10;
if(shift>100)
{
shift=100;
}
speed_display(shift);
msdelay(80);
}
if(DOWN_KEY==0)
{
shift=shift-10;
if(shift<0)
{
shift=0;
}
speed_display(shift);
msdelay(80);
}
}
}
void speed_display(int shift)
{
if(shift==0)
{
LCDCMD(0x80);
LCDString(" 0% of speed ");
}
else if(shift==10)
{
LCDCMD(0x80);
LCDString(" 10% of speed ");
}
else if(shift==20)
{
LCDCMD(0x80);
LCDString(" 20% of speed ");
}
else if(shift==30)
{
LCDCMD(0x80);
LCDString(" 30% of speed ");
}
else if(shift==40)
{
LCDCMD(0x80);
LCDString(" 40% of speed ");
}
else if(shift==50)
{
LCDCMD(0x80);
LCDString(" 50% of speed ");
}
else if(shift==60)
{
LCDCMD(0x80);
LCDString(" 60% of speed ");
}
else if(shift==70)
{
LCDCMD(0x80);
LCDString(" 70% of speed ");
}
else if(shift==80)
{
LCDCMD(0x80);
LCDString(" 80% of speed ");
}
else if(shift==90)
{
LCDCMD(0x80);
LCDString(" 90% of speed ");
}
else if(shift==100)
{
LCDCMD(0x80);
LCDString(" 100% of speed ");
}
}
void LCDNUM(unsigned int NUM)
{
unsigned char Buff[5]={'0'},i=0;
while(NUM)
{
Buff[i++]=(NUM%10)+0x30;
NUM=NUM/10;
}
if(!i)
{
LCDData('0');
LCDString(" ");
}
else
{
while(i--)
{
LCDData(Buff);
LCDCMD(0x06);
}
LCDString(" ");
}
}
void Init_INT0()
{
//in=1;
EA=1;
EX0=1;
IT0=1;
PX0=1;
//PT1=0x02;
}
void Init_Timer1()
{
ET1=1;
TMOD=0x10;
TH1=0x00;
TL1=0x00;
PT1=1;
}
void Init_LCD()
{
LCDCMD(0x38);
LCDCMD(0x06);
LCDCMD(0x0C);
LCDCMD(0x02);
}
void LCDCMD(unsigned char CMD)
{
LCDDATA=CMD;
RS=0;
RW=0;
EN=1;
msdelay(1);
EN=0;
//return;
}
void LCDData(unsigned char Data)
{
LCDDATA=Data;
RS=1;
RW=0;
EN=1;
msdelay(1);
EN=0;
//return;
}
void LCDString(unsigned char *str)
{
while(*str)
{
LCDData(*str++);
}
}
void BusyCheck()
{
BUSY=1;
RS=0;
RW=1;
while(BUSY==1)
{
EN=0;
msdelay(1);
EN=1;
}
}
void msdelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}