PDA

View Full Version : Display Program


Philip
02-28-08, 11:18 AM
Sir

I want to display my name on my LCD with the
code below, but the code does not compile.

#include clib\common51.c
#include clib\syslib51.c
#include clib\stdio.h
#include clib\fprintf.c
#include clib\peekpoke.c
#include clib\lcdfputc.c

char string1[12]="Philip Appiah";

main() {

printf(string1);

}

nmitech
02-28-08, 12:33 PM
Makesure to include all the libraries needed for the fprintf function.

.....
#include clib\is.c
#include clib\itoa.c
#include clib\itoab.c
#include clib\atoi.c
#include clib\strlen.c
#include clib\reverse.c
.....


To look for the compiling error(s), you need to generate the listing file, <filename>.LST by using the command -l1 at the command line,

cc51 lcdtest -l1 -p <lcdtest.c >lcdtest.asm


Then use the Wordpad to open the listing file, and look for errors similar to the listing with errors below,

....
....
001771 8823 120000 LCALL .isdigit
^
***** Warning ***** undefined symbol on second pass
001772 8826 ;ADDSP
....

....

001815 8859 ;CALLm
001816 8859 120000 LCALL .atoi
^
***** Warning ***** undefined symbol on second pass
001817 885C ;ADDSP

....
....
002623 8C1F 120000 LCALL .strlen
^
***** Warning ***** undefined symbol on second pass002624 8C22 ;ADDSP
....
....
....


The lines with yellow highlight indicate the library function or its subfunction need to be included. This is the only way to look for the compiling errors.

Philip
02-28-08, 02:42 PM
Sir

Now my code compiled fine, But the lcd displays XY¥Yp AppYQX instead of Philip Appiah. Below is the code:

#include clib\common51.c
#include clib\syslib51.c
#include clib\stdio.h

#include clib\is.c
#include clib\itoa.c
#include clib\itoab.c
#include clib\atoi.c
#include clib\strlen.c
#include clib\reverse.c


#include clib\fprintf.c
#include clib\peekpoke.c
#include clib\lcdfputc.c

char string1[12]="Philip Appiah";

main() {

_lcdinit();
_lcdclear();
_OUT_ = 1;

printf(string1);

/* back to monitor prompt */
#asm
LJMP H'30
#endasm

}

nmitech
02-29-08, 10:20 AM
Instead of using the printf subfunction of the fprinitf(), I would use the subfunction _lcdput(ch) provided in the lcdfputc.c , then create a new put string function for the lcd. Here is the code,


#include clib\common51.c
#include clib\syslib51.c
#include clib\stdio.h

#include clib\peekpoke.c
#include clib\lcdfputc.c

char string1[12]="Philip Appiah";

main() {

_lcdinit();
_lcdclear();
_OUT_ = 1;

lcdfputs(string1);

/* back to monitor prompt */
#asm
LJMP H'30
#endasm

}

lcdfputs(s)
char *s;
{
while (*s)
_lcdput(*s++);
}