Just trying to progress my C somewhat...so I've been working with the LCD routines. The chip in question is the 16f673a if that's any good to anyone.
The idea was to write a program that would just display 'Hello!'
then on the line underneath say "2+2=" and then it would parse an integer (with a value of 4) into a string and display it.
So I should get:
"Hello!
2+2=4"
What I'm actually getting in Proteus simulation:
"Hello!
4"
This is the code:
If you're sharp, you'll notice I commented out this line:
The reason i did this was so the code wouldn't attempt to display the answer (4).
....It still does? There's no code in there to display the string containing the parsed integer '4', but it still does!
Could this be a bug in the compiler perhaps, or am I missing something totally fundamental?
cheers
Kristian
The idea was to write a program that would just display 'Hello!'
then on the line underneath say "2+2=" and then it would parse an integer (with a value of 4) into a string and display it.
So I should get:
"Hello!
2+2=4"
What I'm actually getting in Proteus simulation:
"Hello!
4"
This is the code:
Code:
//lcd prep
//define lcd system
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;
//set pin directions (align to tris values)
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
//define text
char text[] = "";
void main() {
//initialise stuff here:
TRISA = 0b11111; //set porta to input
TRISB = 0b00000000; //set portb to output
PORTB = 0b00000000; //initialise portb
unsigned int number2 = 4; // this is the int answer to '2+2'
InttoStr(number2,text); //parse it to string, so the lcd can display it
//initialise lcd
Lcd_Init();
//clear lcd
Lcd_Cmd(_LCD_CLEAR);
// disable cursor
Lcd_Cmd(_LCD_CURSOR_OFF);
//main loop
while(1){
LCD_Cmd(_Lcd_Clear); //clear lcd - lets update display
LCD_Out(1,1,"Hello!"); //say hello on line one
LCD_Out(2,1,"2+2= "); //display string of sum on line 2
//LCD_Out(2,6,text); //display parsed value of integer 'number2'
//wait a second between updates
delay_ms(1000);
}
}
If you're sharp, you'll notice I commented out this line:
//LCD_Out(2,6,text); //display parsed value of integer 'number2'
The reason i did this was so the code wouldn't attempt to display the answer (4).
....It still does? There's no code in there to display the string containing the parsed integer '4', but it still does!
Could this be a bug in the compiler perhaps, or am I missing something totally fundamental?
cheers
Kristian
Last edited: