Move the cursor on LCD

Status
Not open for further replies.

Mr.Cat

New Member
I am using ROHS KD8295 LCD 4bit 2x16. I don't know how to stop the cursor at the end of the first line and second line. My cursor can't go to 2nd line when it reach the last position of 1st line. Then it disappear and show at 2nd line after 20 positions from last position of first line. This is my source code for cursor.

p18f4520 pic and Mikroc
.....................................
char txt1[] = "*LCD Cursor Test";
char txt2[] = "*Use 5 Buttons";

//char i; // Loop variable

//void Move_Delay() { // Function used for text moving
//Delay_ms(500); // You can change the moving speed here
//}

void main(){
char oldstate = 0;
ADCON1 = 0x0F; // configure AN pins as digital
TRISA = 0xFF; // set PORTB to be input
TRISD = 0; // set PORTD to be output
PORTD = 0xFF; // initialize PORTD
TRISD = 0;
//TRISE = 0xFF; // set PORTE to be input
//TRISC = 0xFF;


Lcd_Init(&PORTD); // Initialize LCD
Lcd_Cmd(LCD_CLEAR); // Clear display
Lcd_Cmd(LCD_CURSOR_OFF); // Cursor off

Lcd_Out(1,1,txt1); // Write text in first row
Lcd_Out(2,2,txt2); // Write text in second row

// Cursor ON, OFF
// Moving Cursor LEFT & RIGHT , UP & DOWN

while(1)

{
if (Button(&PORTA, 1, 1, 1)) // detect logical one on RA1 pin
oldstate = 1;
if (oldstate && Button(&PORTA, 0, 1, 0)) { // Cursor move to Left, RA0
Delay_ms(200);
Lcd_Cmd(LCD_BLINK_CURSOR_ON);
Lcd_Cmd(LCD_MOVE_CURSOR_LEFT);
oldstate = 0;
}
{
if (Button(&PORTA, 1, 1, 1))
oldstate = 1;
if (oldstate && Button(&PORTA, 1, 0, 0)) { // Cursor move to Right, RA1
Delay_ms(200);
Lcd_Cmd(LCD_BLINK_CURSOR_ON);
Lcd_Cmd(LCD_MOVE_CURSOR_RIGHT);
oldstate = 0;
}
{
if (Button(&PORTE, 0, 1, 1)) // Cursor ON at First Row, RE0
oldstate = 1;
if (oldstate && Button(&PORTE, 0, 1, 0)) {
Delay_ms(200);
Lcd_Cmd(LCD_BLINK_CURSOR_ON);
Lcd_Cmd(LCD_FIRST_ROW);
oldstate = 0;
}
{
if (Button(&PORTE, 0, 1, 1)) // Cursor ON at Second Row, RE1
oldstate = 1;
if (oldstate && Button(&PORTE, 1, 0, 0)) {
Delay_ms(200);
Lcd_Cmd(LCD_BLINK_CURSOR_ON);
Lcd_Cmd(LCD_SECOND_ROW);
oldstate = 0;
}
{
if (Button(&PORTC, 0, 1, 1)) // Cursor OFF Button at RC0
oldstate = 1;
if (oldstate && Button(&PORTC, 0, 1, 0)) {
Delay_ms(100);
Lcd_Cmd(LCD_CURSOR_OFF);
oldstate = 0;
}
}
}
}
}
}
}
 
LCD's are 40 characters long, with a smaller 'window' which you can scroll along the line.

If you want to keep all output in the smaller window, you've got to manipulate the cursor position in your program.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…