Page 178 - ARM Based Microcontroller Projects Using MBED
P. 178
164 8. INTERMEDIATE LEVEL PROJECTS
In some applications, we may want to position the cursor at desired coordinates of the
screen. Also, we may want to clear the screen or home the cursor position. The following es-
cape codes can be used in such applications (these are also known as VT100 terminal cursor
control codes):
esc[H Home the cursor (top-left position)
esc[2J Clear the screen
esc[r;cH Move cursor to row r, column c
Notice that esc is the ASCII escape character, having hexadecimal value 0x1B. We can cre-
ate the following functions to help use the cursor control characters (assuming that the Com
port is named MyPC):
//
// Clear the screen
//
void clrscr()
{
char clrscr[] ¼ {0x1B, ’[’, ’2’ , ’J’,0};
MyPC.printf(clrscr);
}
//
// Home the cursor
//
void homescr()
{
char homescr[] ¼ {0x1B, ’[’ , ’H’ , 0};
MyPC.printf(homescr);
}
//
// Goto specified line and column
//
void gotoscr(int line, int column)
{
char scr[] ¼ {0x1B, ’[’, 0x00, ’;’ ,0x00, ’H’, 0};
scr[2] ¼ line;
scr[4] ¼ column;
MyPC.printf(scr);
}