Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

lcd output works sometimes and others showes odd things

Status
Not open for further replies.

sean2k5

Newbie level 2
Newbie level 2
Joined
Jan 5, 2013
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,300
well my code to get pretend voltage from a 10k pot works great sometimes but others it will show random things even sometimes on the wrong line

im using mikroC and a pic 18f4550

what i thing is wrong is FloatToStr because if i remove that part of the code everything is great


please help me and thank you

sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

int raw ;
float convert;
float volts ;
char strDisplay;



void main(){


OSCCON = 0x72; // OSCOLATOR
ADCON1 = 0x0E; // all pins digital but AN0
CMCON |=0x07; // Disable comparators


TRISA.F0 = 1; // Switch Location set to in

Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);

while (1){



raw = ADC_Read(0);
convert = raw * 0.0048875855327468;
volts = convert * 4.0;

FloatToStr(volts, strDisplay);

Lcd_Out(1, 1, "Pretend Volts is");
Lcd_Out(2, 2, strDisplay);
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
}
}
 

The shown code can't work. strDisplay must be of type *char, e.g. strDisplay[15] or larger.
 
thank you that fixed it !!!
well im learning this with out any help but the internet so can you point me to a website or explain it to me why i had to add the [15] to the end of char?
 

char strDisplay will allocate only 1 byte for storage, but you need more storage than this for your string conversion. char strDisplay[xx] will allocate xx bytes of storage, and then passing variable strDisplay to LCD_Out it will be a pointer, which is what is required.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top