nadre25
Member level 3

Hi, i have a problem in displaying to our LCD. I'm trying to display 2 values to our lcd while using the given algorithm.
The code below is working. But when i added the comments with the arrows especially the
IntToStr(ref,text3)
LCD_Custom_Out(2,10,text3)
the program is not working.
I tried replacing the
IntToStr(sp,text)
LCD_Custom_Out(2,7,text)
to
IntToStr(ref,text3)
LCD_Custom_Out(2,10,text3)
and it worked.
i was wondering if there is a rule with regarding to using IntToStr, if its not possible in using it consecutively.
Here's the code:
unsigned int temp_res;
float fl_res;
unsigned int unsign_pwm;
float pwm, temptemp;
char text[7];
int x;
int low;
int ref;
int high;
int sp;
char text2[7];
char text3[7];
char text4[7];
unsigned int pwmplus;
//void temp(){
//
//Lcd_Custom_Out(2,6,"text4");
//}
//
//void speed(){
//Lcd_Custom_Out(2,6,"speed");
//}
void main(){
PORTC=0;
TRISC=0xF0;
Pwm1_Init(5000);
Pwm1_start();
Pwm2_Init(5000);
Pwm2_start();
ADCON1 = 0x82; // Configure analog inputs and Vref
TRISA = 0xFF; // PORTA is input
TRISB = 0x00; // PORTB is output for LCD
Lcd_Custom_Config(&PORTB,7,6,5,4,&PORTB,2,0,3); // Initialize LCD on PORTB
Lcd_Custom_Cmd(Lcd_CURSOR_OFF); // Turn off cursor
PORTB=0;
TRISD = 0XFF;
PORTD = 0;
Lcd_Custom_Out(1,1,"Mode-Tmp-Spd-Pow");
Lcd_Custom_Out(2,4,"A");
while(1){
// initialize
temp_res = Adc_Read(4); // Get results of AD conversion
fl_res=temp_res;
pwm=fl_res/1023*255;
unsign_pwm=pwm;
x=0;
low=0;
high=25;
sp=0;
//ref=1; (<----)
do{
if((unsign_pwm>=low)&&(unsign_pwm<high))
{
x++;
}
else
{
sp=sp+10;
low=low+25;
high=high+25;
//ref=ref+3; (<-----)
}
}while(x==0);
//IntToStr(ref,text3); (<----)
IntToStr(sp,text);
//Lcd_Custom_Out(2,10,text3); (<-----)
Lcd_Custom_Out(2,7,text);
Pwm1_Change_Duty(unsign_pwm);
Pwm2_Change_Duty(0);
Delay_ms(8);
Pwm1_Change_Duty(0);
Pwm2_Change_Duty(0);
Delay_ms(100);
Pwm1_Change_Duty(0);
Pwm2_Change_Duty(unsign_pwm);
Delay_ms(8);
Pwm1_Change_Duty(0);
Pwm2_Change_Duty(0);
Delay_ms(100);
}
} // end main
thanks.
The code below is working. But when i added the comments with the arrows especially the
IntToStr(ref,text3)
LCD_Custom_Out(2,10,text3)
the program is not working.
I tried replacing the
IntToStr(sp,text)
LCD_Custom_Out(2,7,text)
to
IntToStr(ref,text3)
LCD_Custom_Out(2,10,text3)
and it worked.
i was wondering if there is a rule with regarding to using IntToStr, if its not possible in using it consecutively.
Here's the code:
unsigned int temp_res;
float fl_res;
unsigned int unsign_pwm;
float pwm, temptemp;
char text[7];
int x;
int low;
int ref;
int high;
int sp;
char text2[7];
char text3[7];
char text4[7];
unsigned int pwmplus;
//void temp(){
//
//Lcd_Custom_Out(2,6,"text4");
//}
//
//void speed(){
//Lcd_Custom_Out(2,6,"speed");
//}
void main(){
PORTC=0;
TRISC=0xF0;
Pwm1_Init(5000);
Pwm1_start();
Pwm2_Init(5000);
Pwm2_start();
ADCON1 = 0x82; // Configure analog inputs and Vref
TRISA = 0xFF; // PORTA is input
TRISB = 0x00; // PORTB is output for LCD
Lcd_Custom_Config(&PORTB,7,6,5,4,&PORTB,2,0,3); // Initialize LCD on PORTB
Lcd_Custom_Cmd(Lcd_CURSOR_OFF); // Turn off cursor
PORTB=0;
TRISD = 0XFF;
PORTD = 0;
Lcd_Custom_Out(1,1,"Mode-Tmp-Spd-Pow");
Lcd_Custom_Out(2,4,"A");
while(1){
// initialize
temp_res = Adc_Read(4); // Get results of AD conversion
fl_res=temp_res;
pwm=fl_res/1023*255;
unsign_pwm=pwm;
x=0;
low=0;
high=25;
sp=0;
//ref=1; (<----)
do{
if((unsign_pwm>=low)&&(unsign_pwm<high))
{
x++;
}
else
{
sp=sp+10;
low=low+25;
high=high+25;
//ref=ref+3; (<-----)
}
}while(x==0);
//IntToStr(ref,text3); (<----)
IntToStr(sp,text);
//Lcd_Custom_Out(2,10,text3); (<-----)
Lcd_Custom_Out(2,7,text);
Pwm1_Change_Duty(unsign_pwm);
Pwm2_Change_Duty(0);
Delay_ms(8);
Pwm1_Change_Duty(0);
Pwm2_Change_Duty(0);
Delay_ms(100);
Pwm1_Change_Duty(0);
Pwm2_Change_Duty(unsign_pwm);
Delay_ms(8);
Pwm1_Change_Duty(0);
Pwm2_Change_Duty(0);
Delay_ms(100);
}
} // end main
thanks.