EmbeddedRelated.com
Forums

LPC2378 UART 1 problem!!!

Started by DeV March 13, 2012
Hello Zdravko,

Thanks for pointing that out.. i guess i misunderstood the manual..what i
thought was that till DLAB is 0 then DLL and DLM will not affect the
baudrate...so thatswhy everytime i was trying to set and clear the DLAB
bit..thanks again..

Rgds,
Dev

On Wed, Mar 14, 2012 at 12:39 PM, Zdravko wrote:

> **
> Hi DeV,
> --- In l..., DeV wrote:
> >
> > hello all...i own a lpc2378-stk olimex board...im trying to use uart1 to
> > communicate...im having problem in receiving data...wat i want to do is
> > till valid data is not available the lcd will display "no data"...only
> wen
> > some data EXCEPT Carriage Return is sent, it will display "data
> > entered"...now once the Carriage Return key is pressed the lcd will
> display
> > "Carriage Return" till again a new character is received and the process
> is
> > repeated...
> >
> > but wat im getting is that everything is working ok untill carriage
> return
> > key...once i press the carriage return key the loop is entered only once
> > and the complete process stops!! Thanks in advance!!
> >
> > int main ()
> > {
> > char *rec;
> > PINSEL0 &= 0X3FFFFFFF;//Select Pins for PWM1.6
> > PINSEL0 |= 0X40000000;//Select Pins for PWM1.6
> >
> > PINSEL1 &= 0XFFFFFFFC;//Select Pins for PWM1.6
> > PINSEL1 |= 0X00000001;//Select Pins for PWM1.6
> >
> >
> > U1LCR = 0X83;
> > U1DLL = 4;
> > U1DLM = 0;
> > U1FDR = 0X00000085;
> >
> > U1FCR = 7;
> >
> > PCONP |= (1<<3);
> >
> > InitLcd();
> >
> > while(1)
> > {
> > if ((U1LSR & 1) == 1)
> > {
> > U1LCR &= 0x7F;
> >
> > while(U1RBR == 13)
> > {
> > LCDClearScreen();
> > U1LCR &= 0x7F;
> > LCDPutStr("Carriage Return", 0, 0, LARGE, RED, WHITE);
> > *rec = U1RBR;
> > rec++;
> > U1LCR &= 0x7F;
> > }
> > LCDClearScreen();
> > LCDPutStr("data entered", 32, 0, LARGE, RED, WHITE);
> > U1LCR |= 0x80;
> > }
> >
> > else
> > {
> > LCDClearScreen();
> > LCDPutStr("No Data", 110, 0, LARGE, GREEN, WHITE);
> > }
> > }
> > }
> >
> >
> >
> > Why you are playing with U1LCR all the time???
> The Divisor Latch Enable bit should be set when you configure the divisor
> latches and then just cleared. For example:
>
> U1LCR = 0x83;
>
> U1DLL = 4;
> U1DLM = 0;
> U1LCR = 0x03;
>
> This is not the actual problem of course. But it is some how related to
> the mess in your code.
>
> You are pooling the UART status but do you realize how match time you
> spend in the LCD routines meanwhile?
> It is very probable that you miss some UART events.
>
> Regards
> Zdravko
>
>
>

--

Dev Sampat****

Cell (Oman): (+968) - 9304 8932****

Email: d...@gmail.com


An Engineer's Guide to the LPC2100 Series

hello again...sorry for the trouble again guys but i re-coded the program
as follows and wat happens is that any non carriage return key i press, it
enters into buffer full...why is that?? shouldn't the "buffer full" loop be
entered only when the address which is pointed is of the last element of
the array i.e. s[4]?? please help me again guys.

int main ()
{
char s[5]; // Make an array
char *rec = s; // make a pointer and point it to the array

PINSEL0 &= 0X3FFFFFFF;//Select Pins for PWM1.6
PINSEL0 |= 0X40000000;//Select Pins for PWM1.6

PINSEL1 &= 0XFFFFFFFC;//Select Pins for PWM1.6
PINSEL1 |= 0X00000001;//Select Pins for PWM1.6
U1LCR = 0X83;
U1DLL = 4;
U1DLM = 0;
U1FDR = 0X00000085;
U1LCR &= 0x7F;
U1FCR = 7;

PCONP |= (1<<3);

InitLcd();
rec = &s[0];
while(1)
{
if ((U1LSR & 1) == 1)
{
while(U1RBR != 13)
{
if (rec == &s[4])
{
LCDClearScreen();
LCDPutStr("buffer full", 0, 0, LARGE, RED, WHITE);
goto label;
}
else
{
*rec = U1RBR;
rec++;
}
}
LCDPutStr(s, 32, 0, LARGE, RED, WHITE);
break;
}

else
{
LCDClearScreen();
LCDPutStr("No Data", 110, 0, LARGE, GREEN, WHITE);
}
}
label:
{}
}

On Wed, Mar 14, 2012 at 12:22 PM, Phil Young wrote:

> **
> Hi Dev,
> Then there are a number of problems with the code, since you don't store
> anything unless you get the carriage return, and when you do store it you
> use an uninitialized pointer.
> There are many ways to code this, but using pointers try the following
>
> Try first allocating an array to store the characters, i.e.
> char InString[101];
>
> then place the pointer to the start of the string
> char *rec = InString;
>
> count the characters received as you must stay in the string boundaries you
> have allocated, you could simply output the data when you get to the full
> buffer or get a carriage return
>
> char InString[101]; // 101 characters, we use 100 but allocate 101 for safe
> termination with 0
> char * rec = InString; // initialize rec, same as rec = &InString[0]
> bool OutString = false; // flag when to output data
> while(1) {
> if ((U1LSR & 1) == 1) { // check if a character received
> *rec = U1RBR; // the only access to RBR, copies the character so
> don't access RBR again
> U1LCR &= 0x7F;
> if (*rec == 13) {
> OutString = true; // when received just flag output
> } else {
> rec++; // increment pointer
> if (rec == 100 + InString){ // same as if (rec == &InString[101])
> OutString = true; // flag to output data as buffer is full
> }
> }
> If(OutString){
> // when buffer is full, or CR received output the data and reset
> the buffer pointers and flags
> *rec = 0; // terminate the received string with 0
> LCDClearScreen();
> LCDPutStr(InString, 0, 0, LARGE, RED, WHITE);
> rec = InString;
> OutString = false;
> }
> }
> }
>
> Regards
>
> Phil.
>
> -----Original Message-----
> From: l... [mailto:l...] On Behalf
> Of
> DeV
> Sent: 14 March 2012 07:26
> To: l...
> Subject: Re: [lpc2000] LPC2378 UART 1 problem!!!
>
> Hi Phil,
>
> U1RBR is the receiver register of uart1..so it stores the last byte
> received..now wat i want to do is that using hyper terminal on my pc, i
> want
> to send a string...e.g.e hello...so after i type the string, i should press
> enter...so this same thing the uC needs to understand...that wen i press
> enter key (carriage return key), it should sense the end of string..hence
> for this case i am using the pointer...which will store character after
> character like an array...hence after carriage return key, the pointer will
> stop storing further characters and then we can display all the characters
> like a string...hope i have been able to explain well...so pls guide me wat
> to do next..
>
> thanks,
> Dev
>
> On Wed, Mar 14, 2012 at 11:19 AM, Phil Young
> wrote:
>
> > **
>
> >
> >
> > Hi Dev,
> >
> > I'm not sure what you're trying to do with rec, just comment out the
> > lines that use it.
> >
> > Or declare
> >
> > char rec;
> >
> > and
> >
> > rec = U1RBR;
> >
> > since it looks like all you are trying to do is discard the carriage
> > return.
> >
> >
> > Regards
> >
> > Phil.
> >
> > From: l... [mailto:l...] On
> > Behalf Of Michael Anton
> > Sent: 14 March 2012 05:15
> >
> > To: l...
> > Subject: RE: [lpc2000] LPC2378 UART 1 problem!!!
> >
> > Actually, it is slightly worse, as automatics are not usually zeroed
> > on startup, or at least I haven't seen a compiler do this, unless it
> > is also declared as static, so it could point to anything.
> >
> > Mike
> >
> > -----Original Message-----
> > From: l...
> > [mailto:l... ]On
> > Behalf Of Phil Young
> > Sent: Tuesday, March 13, 2012 1:19 PM
> > To: l...
> > Subject: RE: [lpc2000] LPC2378 UART 1 problem!!!
> >
> > You have created a char pointer *rec, but have not initialized it, it
> > will be on the stack as it's local and probably zero since the startup
> > code usually zero's memory.
> >
> > When a CR is pressed you write to memory using it then increment it.
> >
> > It's likely that writing to memory using an uninitialized pointer is
> > crashing the processor at that point.
> >
> > Regards
> >
> > Phil.
> >
> > From: l...
> > [mailto:l... ]
> > On
> >
> > Behalf Of
> > DeV
> > Sent: 13 March 2012 08:22
> > To: l...
> > Subject: [lpc2000] LPC2378 UART 1 problem!!!
> >
> > hello all...i own a lpc2378-stk olimex board...im trying to use uart1
> > to communicate...im having problem in receiving data...wat i want to
> > do is till valid data is not available the lcd will display "no
> > data"...only wen some data EXCEPT Carriage Return is sent, it will
> > display "data entered"...now once the Carriage Return key is pressed
> > the lcd will display "Carriage Return" till again a new character is
> > received and the process is repeated...
> >
> > but wat im getting is that everything is working ok untill carriage
> > return key...once i press the carriage return key the loop is entered
> > only once and the complete process stops!! Thanks in advance!!
> >
> > int main ()
> > {
> > char *rec;
> > PINSEL0 &= 0X3FFFFFFF;//Select Pins for PWM1.6
> > PINSEL0 |= 0X40000000;//Select Pins for PWM1.6
> >
> > PINSEL1 &= 0XFFFFFFFC;//Select Pins for PWM1.6
> > PINSEL1 |= 0X00000001;//Select Pins for PWM1.6
> >
> > U1LCR = 0X83;
> > U1DLL = 4;
> > U1DLM = 0;
> > U1FDR = 0X00000085;
> >
> > U1FCR = 7;
> >
> > PCONP |= (1<<3);
> >
> > InitLcd();
> >
> > while(1)
> > {
> > if ((U1LSR & 1) == 1)
> > {
> > U1LCR &= 0x7F;
> >
> > while(U1RBR == 13)
> > {
> > LCDClearScreen();
> > U1LCR &= 0x7F;
> > LCDPutStr("Carriage Return", 0, 0, LARGE, RED, WHITE); *rec = U1RBR;
> > rec++;
> > U1LCR &= 0x7F;
> > }
> > LCDClearScreen();
> > LCDPutStr("data entered", 32, 0, LARGE, RED, WHITE); U1LCR |= 0x80; }
> >
> > else
> > {
> > LCDClearScreen();
> > LCDPutStr("No Data", 110, 0, LARGE, GREEN, WHITE); } } }
> >
> >
> >
> >
> >
> >
> >
> >
It's because you have a while loop checking rec, but the reading of a new
character is outside of the while loop.

while(U1RBR != 13) should be changed to an if, the outer while is the only
while loop required.

Regards

Phil.
-----Original Message-----
From: l... [mailto:l...] On Behalf Of
DeV
Sent: 14 March 2012 12:17
To: l...
Subject: Re: [lpc2000] LPC2378 UART 1 problem!!!

hello again...sorry for the trouble again guys but i re-coded the program as
follows and wat happens is that any non carriage return key i press, it
enters into buffer full...why is that?? shouldn't the "buffer full" loop be
entered only when the address which is pointed is of the last element of the
array i.e. s[4]?? please help me again guys.

int main ()
{
char s[5]; // Make an array
char *rec = s; // make a pointer and point it to the array

PINSEL0 &= 0X3FFFFFFF;//Select Pins for PWM1.6
PINSEL0 |= 0X40000000;//Select Pins for PWM1.6

PINSEL1 &= 0XFFFFFFFC;//Select Pins for PWM1.6
PINSEL1 |= 0X00000001;//Select Pins for PWM1.6
U1LCR = 0X83;
U1DLL = 4;
U1DLM = 0;
U1FDR = 0X00000085;
U1LCR &= 0x7F;
U1FCR = 7;

PCONP |= (1<<3);

InitLcd();
rec = &s[0];
while(1)
{
if ((U1LSR & 1) == 1)
{
while(U1RBR != 13)
{
if (rec == &s[4])
{
LCDClearScreen();
LCDPutStr("buffer full", 0, 0, LARGE, RED, WHITE); goto label; } else { *rec
= U1RBR;
rec++;
}
}
LCDPutStr(s, 32, 0, LARGE, RED, WHITE);
break;
}

else
{
LCDClearScreen();
LCDPutStr("No Data", 110, 0, LARGE, GREEN, WHITE); } }
label:
{}
}

On Wed, Mar 14, 2012 at 12:22 PM, Phil Young
wrote:

> **
> Hi Dev,
> Then there are a number of problems with the code, since you don't
> store anything unless you get the carriage return, and when you do
> store it you use an uninitialized pointer.
> There are many ways to code this, but using pointers try the following
>
> Try first allocating an array to store the characters, i.e.
> char InString[101];
>
> then place the pointer to the start of the string char *rec > InString;
>
> count the characters received as you must stay in the string
> boundaries you have allocated, you could simply output the data when
> you get to the full buffer or get a carriage return
>
> char InString[101]; // 101 characters, we use 100 but allocate 101 for
> safe termination with 0 char * rec = InString; // initialize rec, same
> as rec = &InString[0] bool OutString = false; // flag when to output
> data
> while(1) {
> if ((U1LSR & 1) == 1) { // check if a character received *rec = U1RBR;
> // the only access to RBR, copies the character so don't access RBR
> again U1LCR &= 0x7F; if (*rec == 13) { OutString = true; // when
> received just flag output } else {
> rec++; // increment pointer
> if (rec == 100 + InString){ // same as if (rec == &InString[101])
> OutString = true; // flag to output data as buffer is full } }
> If(OutString){ // when buffer is full, or CR received output the data
> and reset the buffer pointers and flags *rec = 0; // terminate the
> received string with 0 LCDClearScreen(); LCDPutStr(InString, 0, 0,
> LARGE, RED, WHITE); rec = InString; OutString = false; } } }
>
> Regards
>
> Phil.
>
> -----Original Message-----
> From: l... [mailto:l...] On
> Behalf Of DeV
> Sent: 14 March 2012 07:26
> To: l...
> Subject: Re: [lpc2000] LPC2378 UART 1 problem!!!
>
> Hi Phil,
>
> U1RBR is the receiver register of uart1..so it stores the last byte
> received..now wat i want to do is that using hyper terminal on my pc,
> i want to send a string...e.g.e hello...so after i type the string, i
> should press enter...so this same thing the uC needs to
> understand...that wen i press enter key (carriage return key), it
> should sense the end of string..hence for this case i am using the
> pointer...which will store character after character like an
> array...hence after carriage return key, the pointer will stop storing
> further characters and then we can display all the characters like a
> string...hope i have been able to explain well...so pls guide me wat
> to do next..
>
> thanks,
> Dev
>
> On Wed, Mar 14, 2012 at 11:19 AM, Phil Young
> wrote:
>
> > **
>
> >
> >
> > Hi Dev,
> >
> > I'm not sure what you're trying to do with rec, just comment out the
> > lines that use it.
> >
> > Or declare
> >
> > char rec;
> >
> > and
> >
> > rec = U1RBR;
> >
> > since it looks like all you are trying to do is discard the carriage
> > return.
> >
> >
> > Regards
> >
> > Phil.
> >
> > From: l... [mailto:l...] On
> > Behalf Of Michael Anton
> > Sent: 14 March 2012 05:15
> >
> > To: l...
> > Subject: RE: [lpc2000] LPC2378 UART 1 problem!!!
> >
> > Actually, it is slightly worse, as automatics are not usually zeroed
> > on startup, or at least I haven't seen a compiler do this, unless it
> > is also declared as static, so it could point to anything.
> >
> > Mike
> >
> > -----Original Message-----
> > From: l...
> > [mailto:l...
> > ]On Behalf Of Phil Young
> > Sent: Tuesday, March 13, 2012 1:19 PM
> > To: l...
> > Subject: RE: [lpc2000] LPC2378 UART 1 problem!!!
> >
> > You have created a char pointer *rec, but have not initialized it,
> > it will be on the stack as it's local and probably zero since the
> > startup code usually zero's memory.
> >
> > When a CR is pressed you write to memory using it then increment it.
> >
> > It's likely that writing to memory using an uninitialized pointer is
> > crashing the processor at that point.
> >
> > Regards
> >
> > Phil.
> >
> > From: l...
> > [mailto:l... ]
> > On
> >
> > Behalf Of
> > DeV
> > Sent: 13 March 2012 08:22
> > To: l...
> > Subject: [lpc2000] LPC2378 UART 1 problem!!!
> >
> > hello all...i own a lpc2378-stk olimex board...im trying to use
> > uart1 to communicate...im having problem in receiving data...wat i
> > want to do is till valid data is not available the lcd will display
> > "no data"...only wen some data EXCEPT Carriage Return is sent, it
> > will display "data entered"...now once the Carriage Return key is
> > pressed the lcd will display "Carriage Return" till again a new
> > character is received and the process is repeated...
> >
> > but wat im getting is that everything is working ok untill carriage
> > return key...once i press the carriage return key the loop is
> > entered only once and the complete process stops!! Thanks in advance!!
> >
> > int main ()
> > {
> > char *rec;
> > PINSEL0 &= 0X3FFFFFFF;//Select Pins for PWM1.6
> > PINSEL0 |= 0X40000000;//Select Pins for PWM1.6
> >
> > PINSEL1 &= 0XFFFFFFFC;//Select Pins for PWM1.6
> > PINSEL1 |= 0X00000001;//Select Pins for PWM1.6
> >
> > U1LCR = 0X83;
> > U1DLL = 4;
> > U1DLM = 0;
> > U1FDR = 0X00000085;
> >
> > U1FCR = 7;
> >
> > PCONP |= (1<<3);
> >
> > InitLcd();
> >
> > while(1)
> > {
> > if ((U1LSR & 1) == 1)
> > {
> > U1LCR &= 0x7F;
> >
> > while(U1RBR == 13)
> > {
> > LCDClearScreen();
> > U1LCR &= 0x7F;
> > LCDPutStr("Carriage Return", 0, 0, LARGE, RED, WHITE); *rec = U1RBR;
> > rec++;
> > U1LCR &= 0x7F;
> > }
> > LCDClearScreen();
> > LCDPutStr("data entered", 32, 0, LARGE, RED, WHITE); U1LCR |= 0x80;
> > }
> >
> > else
> > {
> > LCDClearScreen();
> > LCDPutStr("No Data", 110, 0, LARGE, GREEN, WHITE); } } }
> >
> >
> >
> >
> >
> >
> >
> >
But then i am trying to use inner while loop to check rec address...if it
is not the address of last element of the array then we read the
U1RBR...but if rec has reached the address of the last element of the
array, then straight away end the program displaying buffer full and
jumping to the end...isnt this correct in my code?

On Wed, Mar 14, 2012 at 4:46 PM, Phil Young wrote:

> **
> It's because you have a while loop checking rec, but the reading of a new
> character is outside of the while loop.
>
> while(U1RBR != 13) should be changed to an if, the outer while is the only
> while loop required.
> Regards
>
> Phil.
> -----Original Message-----
> From: l... [mailto:l...] On Behalf
> Of
> DeV
> Sent: 14 March 2012 12:17
> To: l...
> Subject: Re: [lpc2000] LPC2378 UART 1 problem!!!
>
> hello again...sorry for the trouble again guys but i re-coded the program
> as
> follows and wat happens is that any non carriage return key i press, it
> enters into buffer full...why is that?? shouldn't the "buffer full" loop be
> entered only when the address which is pointed is of the last element of
> the
> array i.e. s[4]?? please help me again guys.
>
> int main ()
> {
> char s[5]; // Make an array
> char *rec = s; // make a pointer and point it to the array
>
> PINSEL0 &= 0X3FFFFFFF;//Select Pins for PWM1.6
> PINSEL0 |= 0X40000000;//Select Pins for PWM1.6
>
> PINSEL1 &= 0XFFFFFFFC;//Select Pins for PWM1.6
> PINSEL1 |= 0X00000001;//Select Pins for PWM1.6
>
> U1LCR = 0X83;
> U1DLL = 4;
> U1DLM = 0;
> U1FDR = 0X00000085;
> U1LCR &= 0x7F;
> U1FCR = 7;
>
> PCONP |= (1<<3);
>
> InitLcd();
> rec = &s[0];
> while(1)
> {
> if ((U1LSR & 1) == 1)
> {
> while(U1RBR != 13)
> {
> if (rec == &s[4])
> {
> LCDClearScreen();
> LCDPutStr("buffer full", 0, 0, LARGE, RED, WHITE); goto label; } else {
> *rec
> = U1RBR;
> rec++;
> }
> }
> LCDPutStr(s, 32, 0, LARGE, RED, WHITE);
> break;
> }
>
> else
> {
> LCDClearScreen();
> LCDPutStr("No Data", 110, 0, LARGE, GREEN, WHITE); } }
> label:
> {}
> }
>
> On Wed, Mar 14, 2012 at 12:22 PM, Phil Young
> wrote:
>
> > **
>
> >
> >
> > Hi Dev,
> > Then there are a number of problems with the code, since you don't
> > store anything unless you get the carriage return, and when you do
> > store it you use an uninitialized pointer.
> > There are many ways to code this, but using pointers try the following
> >
> > Try first allocating an array to store the characters, i.e.
> > char InString[101];
> >
> > then place the pointer to the start of the string char *rec > > InString;
> >
> > count the characters received as you must stay in the string
> > boundaries you have allocated, you could simply output the data when
> > you get to the full buffer or get a carriage return
> >
> > char InString[101]; // 101 characters, we use 100 but allocate 101 for
> > safe termination with 0 char * rec = InString; // initialize rec, same
> > as rec = &InString[0] bool OutString = false; // flag when to output
> > data
> > while(1) {
> > if ((U1LSR & 1) == 1) { // check if a character received *rec = U1RBR;
> > // the only access to RBR, copies the character so don't access RBR
> > again U1LCR &= 0x7F; if (*rec == 13) { OutString = true; // when
> > received just flag output } else {
> > rec++; // increment pointer
> > if (rec == 100 + InString){ // same as if (rec == &InString[101])
> > OutString = true; // flag to output data as buffer is full } }
> > If(OutString){ // when buffer is full, or CR received output the data
> > and reset the buffer pointers and flags *rec = 0; // terminate the
> > received string with 0 LCDClearScreen(); LCDPutStr(InString, 0, 0,
> > LARGE, RED, WHITE); rec = InString; OutString = false; } } }
> >
> > Regards
> >
> > Phil.
> >
> > -----Original Message-----
> > From: l... [mailto:l...] On
> > Behalf Of DeV
> > Sent: 14 March 2012 07:26
> > To: l...
> > Subject: Re: [lpc2000] LPC2378 UART 1 problem!!!
> >
> > Hi Phil,
> >
> > U1RBR is the receiver register of uart1..so it stores the last byte
> > received..now wat i want to do is that using hyper terminal on my pc,
> > i want to send a string...e.g.e hello...so after i type the string, i
> > should press enter...so this same thing the uC needs to
> > understand...that wen i press enter key (carriage return key), it
> > should sense the end of string..hence for this case i am using the
> > pointer...which will store character after character like an
> > array...hence after carriage return key, the pointer will stop storing
> > further characters and then we can display all the characters like a
> > string...hope i have been able to explain well...so pls guide me wat
> > to do next..
> >
> > thanks,
> > Dev
> >
> > On Wed, Mar 14, 2012 at 11:19 AM, Phil Young
> > wrote:
> >
> > > **
> >
> > >
> > >
> > > Hi Dev,
> > >
> > > I'm not sure what you're trying to do with rec, just comment out the
> > > lines that use it.
> > >
> > > Or declare
> > >
> > > char rec;
> > >
> > > and
> > >
> > > rec = U1RBR;
> > >
> > > since it looks like all you are trying to do is discard the carriage
> > > return.
> > >
> > >
> > > Regards
> > >
> > > Phil.
> > >
> > > From: l... [mailto:l...] On
> > > Behalf Of Michael Anton
> > > Sent: 14 March 2012 05:15
> > >
> > > To: l...
> > > Subject: RE: [lpc2000] LPC2378 UART 1 problem!!!
> > >
> > > Actually, it is slightly worse, as automatics are not usually zeroed
> > > on startup, or at least I haven't seen a compiler do this, unless it
> > > is also declared as static, so it could point to anything.
> > >
> > > Mike
> > >
> > > -----Original Message-----
> > > From: l...
> > > [mailto:l...
> > > ]On Behalf Of Phil Young
> > > Sent: Tuesday, March 13, 2012 1:19 PM
> > > To: l...
> > > Subject: RE: [lpc2000] LPC2378 UART 1 problem!!!
> > >
> > > You have created a char pointer *rec, but have not initialized it,
> > > it will be on the stack as it's local and probably zero since the
> > > startup code usually zero's memory.
> > >
> > > When a CR is pressed you write to memory using it then increment it.
> > >
> > > It's likely that writing to memory using an uninitialized pointer is
> > > crashing the processor at that point.
> > >
> > > Regards
> > >
> > > Phil.
> > >
> > > From: l...
> > > [mailto:l... ]
> > > On
> > >
> > > Behalf Of
> > > DeV
> > > Sent: 13 March 2012 08:22
> > > To: l...
> > > Subject: [lpc2000] LPC2378 UART 1 problem!!!
> > >
> > > hello all...i own a lpc2378-stk olimex board...im trying to use
> > > uart1 to communicate...im having problem in receiving data...wat i
> > > want to do is till valid data is not available the lcd will display
> > > "no data"...only wen some data EXCEPT Carriage Return is sent, it
> > > will display "data entered"...now once the Carriage Return key is
> > > pressed the lcd will display "Carriage Return" till again a new
> > > character is received and the process is repeated...
> > >
> > > but wat im getting is that everything is working ok untill carriage
> > > return key...once i press the carriage return key the loop is
> > > entered only once and the complete process stops!! Thanks in advance!!
> > >
> > > int main ()
> > > {
> > > char *rec;
> > > PINSEL0 &= 0X3FFFFFFF;//Select Pins for PWM1.6
> > > PINSEL0 |= 0X40000000;//Select Pins for PWM1.6
> > >
> > > PINSEL1 &= 0XFFFFFFFC;//Select Pins for PWM1.6
> > > PINSEL1 |= 0X00000001;//Select Pins for PWM1.6
> > >
> > > U1LCR = 0X83;
> > > U1DLL = 4;
> > > U1DLM = 0;
> > > U1FDR = 0X00000085;
> > >
> > > U1FCR = 7;
> > >
> > > PCONP |= (1<<3);
> > >
> > > InitLcd();
> > >
> > > while(1)
> > > {
> > > if ((U1LSR & 1) == 1)
> > > {
> > > U1LCR &= 0x7F;
> > >
> > > while(U1RBR == 13)
> > > {
> > > LCDClearScreen();
> > > U1LCR &= 0x7F;
> > > LCDPutStr("Carriage Return", 0, 0, LARGE, RED, WHITE); *rec = U1RBR;
> > > rec++;
> > > U1LCR &= 0x7F;
> > > }
> > > LCDClearScreen();
> > > LCDPutStr("data entered", 32, 0, LARGE, RED, WHITE); U1LCR |= 0x80;
> > > }
> > >
> > > else
> > > {
> > > LCDClearScreen();
> > > LCDPutStr("No Data", 110, 0, LARGE, GREEN, WHITE); } } }
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
Actually, there is a bigger problem with the code.

You are looping reading U1RBR, but each time you read a character from the
UART buffer it is removed from it ONLY if there is another character in the
receive fifo.
The receive buffer indication gets cleared, but not the receive buffer
register only changes when there is a new character in the receive fifo to
store into it.

So you must read from RBR into a local char only once per character, then
test that value, not U1RBR.

And when there are no more characters received, U1RBR will not be updated on
read so will continue to return the last character read.

The main while loop must be testing for a receive character valid, and the
inner part of this loop should read the character once then work on the
local copy.

Inside the loop you only ever have 1 new character, so there should be no
inner while loops.

Regards

Phil.

-----Original Message-----
From: l... [mailto:l...] On Behalf Of
DeV
Sent: 14 March 2012 12:58
To: l...
Subject: Re: [lpc2000] LPC2378 UART 1 problem!!!

But then i am trying to use inner while loop to check rec address...if it is
not the address of last element of the array then we read the U1RBR...but if
rec has reached the address of the last element of the array, then straight
away end the program displaying buffer full and jumping to the end...isnt
this correct in my code?

On Wed, Mar 14, 2012 at 4:46 PM, Phil Young
wrote:

> **
> It's because you have a while loop checking rec, but the reading of a
> new character is outside of the while loop.
>
> while(U1RBR != 13) should be changed to an if, the outer while is the
> only while loop required.
> Regards
>
> Phil.
> -----Original Message-----
> From: l... [mailto:l...] On
> Behalf Of DeV
> Sent: 14 March 2012 12:17
> To: l...
> Subject: Re: [lpc2000] LPC2378 UART 1 problem!!!
>
> hello again...sorry for the trouble again guys but i re-coded the
> program as follows and wat happens is that any non carriage return key
> i press, it enters into buffer full...why is that?? shouldn't the
> "buffer full" loop be entered only when the address which is pointed
> is of the last element of the array i.e. s[4]?? please help me again
> guys.
>
> int main ()
> {
> char s[5]; // Make an array
> char *rec = s; // make a pointer and point it to the array
>
> PINSEL0 &= 0X3FFFFFFF;//Select Pins for PWM1.6
> PINSEL0 |= 0X40000000;//Select Pins for PWM1.6
>
> PINSEL1 &= 0XFFFFFFFC;//Select Pins for PWM1.6
> PINSEL1 |= 0X00000001;//Select Pins for PWM1.6
>
> U1LCR = 0X83;
> U1DLL = 4;
> U1DLM = 0;
> U1FDR = 0X00000085;
> U1LCR &= 0x7F;
> U1FCR = 7;
>
> PCONP |= (1<<3);
>
> InitLcd();
> rec = &s[0];
> while(1)
> {
> if ((U1LSR & 1) == 1)
> {
> while(U1RBR != 13)
> {
> if (rec == &s[4])
> {
> LCDClearScreen();
> LCDPutStr("buffer full", 0, 0, LARGE, RED, WHITE); goto label; } else
> { *rec = U1RBR;
> rec++;
> }
> }
> LCDPutStr(s, 32, 0, LARGE, RED, WHITE); break; }
>
> else
> {
> LCDClearScreen();
> LCDPutStr("No Data", 110, 0, LARGE, GREEN, WHITE); } }
> label:
> {}
> }
>
> On Wed, Mar 14, 2012 at 12:22 PM, Phil Young
> wrote:
>
> > **
>
> >
> >
> > Hi Dev,
> > Then there are a number of problems with the code, since you don't
> > store anything unless you get the carriage return, and when you do
> > store it you use an uninitialized pointer.
> > There are many ways to code this, but using pointers try the
> > following
> >
> > Try first allocating an array to store the characters, i.e.
> > char InString[101];
> >
> > then place the pointer to the start of the string char *rec > > InString;
> >
> > count the characters received as you must stay in the string
> > boundaries you have allocated, you could simply output the data when
> > you get to the full buffer or get a carriage return
> >
> > char InString[101]; // 101 characters, we use 100 but allocate 101
> > for safe termination with 0 char * rec = InString; // initialize
> > rec, same as rec = &InString[0] bool OutString = false; // flag when
> > to output data
> > while(1) {
> > if ((U1LSR & 1) == 1) { // check if a character received *rec > > U1RBR; // the only access to RBR, copies the character so don't
> > access RBR again U1LCR &= 0x7F; if (*rec == 13) { OutString = true;
> > // when received just flag output } else {
> > rec++; // increment pointer
> > if (rec == 100 + InString){ // same as if (rec == &InString[101])
> > OutString = true; // flag to output data as buffer is full } }
> > If(OutString){ // when buffer is full, or CR received output the
> > data and reset the buffer pointers and flags *rec = 0; // terminate
> > the received string with 0 LCDClearScreen(); LCDPutStr(InString, 0,
> > 0, LARGE, RED, WHITE); rec = InString; OutString = false; } } }
> >
> > Regards
> >
> > Phil.
> >
> > -----Original Message-----
> > From: l... [mailto:l...] On
> > Behalf Of DeV
> > Sent: 14 March 2012 07:26
> > To: l...
> > Subject: Re: [lpc2000] LPC2378 UART 1 problem!!!
> >
> > Hi Phil,
> >
> > U1RBR is the receiver register of uart1..so it stores the last byte
> > received..now wat i want to do is that using hyper terminal on my
> > pc, i want to send a string...e.g.e hello...so after i type the
> > string, i should press enter...so this same thing the uC needs to
> > understand...that wen i press enter key (carriage return key), it
> > should sense the end of string..hence for this case i am using the
> > pointer...which will store character after character like an
> > array...hence after carriage return key, the pointer will stop
> > storing further characters and then we can display all the
> > characters like a string...hope i have been able to explain
> > well...so pls guide me wat to do next..
> >
> > thanks,
> > Dev
> >
> > On Wed, Mar 14, 2012 at 11:19 AM, Phil Young
> > wrote:
> >
> > > **
> >
> > >
> > >
> > > Hi Dev,
> > >
> > > I'm not sure what you're trying to do with rec, just comment out
> > > the lines that use it.
> > >
> > > Or declare
> > >
> > > char rec;
> > >
> > > and
> > >
> > > rec = U1RBR;
> > >
> > > since it looks like all you are trying to do is discard the
> > > carriage return.
> > >
> > >
> > > Regards
> > >
> > > Phil.
> > >
> > > From: l... [mailto:l...] On
> > > Behalf Of Michael Anton
> > > Sent: 14 March 2012 05:15
> > >
> > > To: l...
> > > Subject: RE: [lpc2000] LPC2378 UART 1 problem!!!
> > >
> > > Actually, it is slightly worse, as automatics are not usually
> > > zeroed on startup, or at least I haven't seen a compiler do this,
> > > unless it is also declared as static, so it could point to anything.
> > >
> > > Mike
> > >
> > > -----Original Message-----
> > > From: l...
> > > [mailto:l...
> > > ]On Behalf Of Phil Young
> > > Sent: Tuesday, March 13, 2012 1:19 PM
> > > To: l...
> > > Subject: RE: [lpc2000] LPC2378 UART 1 problem!!!
> > >
> > > You have created a char pointer *rec, but have not initialized it,
> > > it will be on the stack as it's local and probably zero since the
> > > startup code usually zero's memory.
> > >
> > > When a CR is pressed you write to memory using it then increment it.
> > >
> > > It's likely that writing to memory using an uninitialized pointer
> > > is crashing the processor at that point.
> > >
> > > Regards
> > >
> > > Phil.
> > >
> > > From: l...
> > > [mailto:l...
> > > ] On
> > >
> > > Behalf Of
> > > DeV
> > > Sent: 13 March 2012 08:22
> > > To: l...
> > > Subject: [lpc2000] LPC2378 UART 1 problem!!!
> > >
> > > hello all...i own a lpc2378-stk olimex board...im trying to use
> > > uart1 to communicate...im having problem in receiving data...wat i
> > > want to do is till valid data is not available the lcd will
> > > display "no data"...only wen some data EXCEPT Carriage Return is
> > > sent, it will display "data entered"...now once the Carriage
> > > Return key is pressed the lcd will display "Carriage Return" till
> > > again a new character is received and the process is repeated...
> > >
> > > but wat im getting is that everything is working ok untill
> > > carriage return key...once i press the carriage return key the
> > > loop is entered only once and the complete process stops!! Thanks in
advance!!
> > >
> > > int main ()
> > > {
> > > char *rec;
> > > PINSEL0 &= 0X3FFFFFFF;//Select Pins for PWM1.6
> > > PINSEL0 |= 0X40000000;//Select Pins for PWM1.6
> > >
> > > PINSEL1 &= 0XFFFFFFFC;//Select Pins for PWM1.6
> > > PINSEL1 |= 0X00000001;//Select Pins for PWM1.6
> > >
> > > U1LCR = 0X83;
> > > U1DLL = 4;
> > > U1DLM = 0;
> > > U1FDR = 0X00000085;
> > >
> > > U1FCR = 7;
> > >
> > > PCONP |= (1<<3);
> > >
> > > InitLcd();
> > >
> > > while(1)
> > > {
> > > if ((U1LSR & 1) == 1)
> > > {
> > > U1LCR &= 0x7F;
> > >
> > > while(U1RBR == 13)
> > > {
> > > LCDClearScreen();
> > > U1LCR &= 0x7F;
> > > LCDPutStr("Carriage Return", 0, 0, LARGE, RED, WHITE); *rec > > > U1RBR;
> > > rec++;
> > > U1LCR &= 0x7F;
> > > }
> > > LCDClearScreen();
> > > LCDPutStr("data entered", 32, 0, LARGE, RED, WHITE); U1LCR |> > > 0x80; }
> > >
> > > else
> > > {
> > > LCDClearScreen();
> > > LCDPutStr("No Data", 110, 0, LARGE, GREEN, WHITE); } } }
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
ok i got a rough idea on what u are explaining..i have tried to use if else
statements and have tried the following program...here all the loops are
correctly entered...the problem is with the displaying the final string...i
think u can have a look at the function LCD too since that too incorporates
a pointer...

The main program:

InitLcd();
//rec = &s[0];
while(1)
{//LCDClearScreen();
//if((U1LSR & 1) == 1)
//{
//LCDPutStr("Overvoltage ", 100, 0, LARGE, RED, WHITE);

if ((U1LSR & 1) == 1)
{
if(rec != &s[4])
{
if (U1RBR != 13)
{*rec = U1RBR;
rec++;
}
else
{
LCDClearScreen();
LCDPutStr("Enter Key Pressed", 0, 0, LARGE, RED, WHITE);
goto label;
}
}
else
{
LCDClearScreen();
LCDPutStr("buffer full", 20, 0, LARGE, RED, WHITE);
goto label;
}
}
else
{
LCDClearScreen();
LCDPutStr("No Data", 40, 0, LARGE, GREEN, WHITE);
}
}

label:
LCDPutStr(s, 100, 0, LARGE, RED, WHITE);
}

**************************************************************
The LCD functions:

void LCDPutChar(char c, int x, int y, int size, int fColor, int bColor)
{
// extern const unsigned char FONT6x8[97][8];
// extern const unsigned char FONT8x8[97][8];
// extern const unsigned char FONT8x16[97][16];
extern const unsigned char *FontTable[];

int i;
unsigned int j;
unsigned int nCols;
unsigned int nRows;
unsigned int nBytes;
unsigned char PixelRow;
unsigned char Mask;
unsigned int Word0;
unsigned int Word1;
unsigned char *pFont;
unsigned char *pChar;
// unsigned char *FontTable[] = { (unsigned char *)FONT6x8,
// (unsigned char *)FONT8x8,
// (unsigned char *)FONT8x16};

// get pointer to the beginning of the selected font table
pFont = (unsigned char *)FontTable[size];
// get the nColumns, nRows and nBytes
nCols = *pFont;
nRows = *(pFont + 1);
nBytes = *(pFont + 2);
// get pointer to the last byte of the desired character
// pChar = pFont + (nBytes * (c - 0x1F)) + nBytes - 1;

// get pointer to the first byte of the desired character
pChar = pFont + (nBytes * (c - 0x1F)) ;

// Row address set (command 0x2B)
WriteSpiCommand(PASET);
WriteSpiData(x);
WriteSpiData(x + nRows - 1 );
// Column address set (command 0x2A)
WriteSpiCommand(CASET);
WriteSpiData(y);
WriteSpiData(y + nCols - 1);
// WRITE MEMORY
WriteSpiCommand(RAMWR);

// loop on each row, working from the top to the bottom
for (i = nRows - 1; i >= 0; i--)
{
// copy pixel row from font table and then decrement row
PixelRow = *pChar++;
// loop on each pixel in the row (left to right)
// Note: we do two pixels each loop
Mask = 0x80;
for (j = 0; j < nCols; j += 2)
{
// if pixel bit set, use foreground color; else use the background color
// now get the pixel color for two successive pixels
if ((PixelRow & Mask) == 0)
Word0 = bColor;
else
Word0 = fColor;

Mask = Mask >> 1;

if ((PixelRow & Mask) == 0)
Word1 = bColor;
else
Word1 = fColor;

Mask = Mask >> 1;
// use this information to output three data bytes
WriteSpiData((Word0 >> 4) & 0xFF);
WriteSpiData(((Word0 & 0xF) << 4) | ((Word1 >> 8) & 0xF));
WriteSpiData(Word1 & 0xFF);
}
}

// terminate the Write Memory command
WriteSpiCommand(NOP);
}

void LCDPutStr(char *pString, int x, int y, int Size, int fColor, int
bColor)
{ int z = y;
// loop until null-terminator is seen
while (*pString != 0x00)
{
// draw the character
LCDPutChar(*pString++, x, y, Size, fColor, bColor);

// advance the y position
if (Size == SMALL)
{y = y + 6;
if(y > 123)
{y = z;
x = x + 16;}
}
else if (Size == MEDIUM)
{y = y + 8;
if(y > 123)
{y = z;
x = x + 16;}
}
else
{y = y + 8;
if(y > 123)
{y = z;
x = x + 16;}
}

// bail out if x and y exceeds 131
if (y > 131) //break;
{if(x>131)
{break;}
else
{x = x + 16;
y = z;
}
}

}
}


But you still have the same problem.

if (U1RBR != 13)
{*rec = U1RBR;
rec++;
}

change it to read to a char first.

char Temp = U1RBR;

if (Temp != 13)
{*rec = Temp;
rec++;
}

From: l... [mailto:l...] On Behalf Of
DeV
Sent: 14 March 2012 13:30
To: l...
Subject: Re: [lpc2000] LPC2378 UART 1 problem!!!

ok i got a rough idea on what u are explaining..i have tried to use if else
statements and have tried the following program...here all the loops are
correctly entered...the problem is with the displaying the final string...i
think u can have a look at the function LCD too since that too incorporates
a pointer...

The main program:

InitLcd();
//rec = &s[0];
while(1)
{//LCDClearScreen();
//if((U1LSR & 1) == 1)
//{
//LCDPutStr("Overvoltage ", 100, 0, LARGE, RED, WHITE);

if ((U1LSR & 1) == 1)
{
if(rec != &s[4])
{
if (U1RBR != 13)
{*rec = U1RBR;
rec++;
}
else
{
LCDClearScreen();
LCDPutStr("Enter Key Pressed", 0, 0, LARGE, RED, WHITE);
goto label;
}
}
else
{
LCDClearScreen();
LCDPutStr("buffer full", 20, 0, LARGE, RED, WHITE);
goto label;
}
}
else
{
LCDClearScreen();
LCDPutStr("No Data", 40, 0, LARGE, GREEN, WHITE);
}
}

label:
LCDPutStr(s, 100, 0, LARGE, RED, WHITE);
}

**************************************************************
The LCD functions:

void LCDPutChar(char c, int x, int y, int size, int fColor, int bColor)
{
// extern const unsigned char FONT6x8[97][8];
// extern const unsigned char FONT8x8[97][8];
// extern const unsigned char FONT8x16[97][16];
extern const unsigned char *FontTable[];

int i;
unsigned int j;
unsigned int nCols;
unsigned int nRows;
unsigned int nBytes;
unsigned char PixelRow;
unsigned char Mask;
unsigned int Word0;
unsigned int Word1;
unsigned char *pFont;
unsigned char *pChar;
// unsigned char *FontTable[] = { (unsigned char *)FONT6x8,
// (unsigned char *)FONT8x8,
// (unsigned char *)FONT8x16};

// get pointer to the beginning of the selected font table
pFont = (unsigned char *)FontTable[size];
// get the nColumns, nRows and nBytes
nCols = *pFont;
nRows = *(pFont + 1);
nBytes = *(pFont + 2);
// get pointer to the last byte of the desired character
// pChar = pFont + (nBytes * (c - 0x1F)) + nBytes - 1;

// get pointer to the first byte of the desired character
pChar = pFont + (nBytes * (c - 0x1F)) ;

// Row address set (command 0x2B)
WriteSpiCommand(PASET);
WriteSpiData(x);
WriteSpiData(x + nRows - 1 );

// Column address set (command 0x2A)
WriteSpiCommand(CASET);
WriteSpiData(y);
WriteSpiData(y + nCols - 1);
// WRITE MEMORY
WriteSpiCommand(RAMWR);

// loop on each row, working from the top to the bottom
for (i = nRows - 1; i >= 0; i--)
{
// copy pixel row from font table and then decrement row
PixelRow = *pChar++;
// loop on each pixel in the row (left to right)
// Note: we do two pixels each loop
Mask = 0x80;
for (j = 0; j < nCols; j += 2)
{
// if pixel bit set, use foreground color; else use the background color
// now get the pixel color for two successive pixels
if ((PixelRow & Mask) == 0)
Word0 = bColor;
else
Word0 = fColor;

Mask = Mask >> 1;

if ((PixelRow & Mask) == 0)
Word1 = bColor;
else
Word1 = fColor;

Mask = Mask >> 1;
// use this information to output three data bytes
WriteSpiData((Word0 >> 4) & 0xFF);
WriteSpiData(((Word0 & 0xF) << 4) | ((Word1 >> 8) & 0xF));
WriteSpiData(Word1 & 0xFF);
}
}

// terminate the Write Memory command
WriteSpiCommand(NOP);
}

void LCDPutStr(char *pString, int x, int y, int Size, int fColor, int
bColor)
{ int z = y;
// loop until null-terminator is seen
while (*pString != 0x00)
{
// draw the character
LCDPutChar(*pString++, x, y, Size, fColor, bColor);

// advance the y position
if (Size == SMALL)
{y = y + 6;
if(y > 123)
{y = z;
x = x + 16;}
}
else if (Size == MEDIUM)
{y = y + 8;
if(y > 123)
{y = z;
x = x + 16;}
}
else
{y = y + 8;
if(y > 123)
{y = z;
x = x + 16;}
}

// bail out if x and y exceeds 131
if (y > 131) //break;
{if(x>131)
{break;}
else
{x = x + 16;
y = z;
}
}

}
}





hey thanks somuch Phil..my problem is solved now..its working
perfect!...thanks again..cheers!

On Wed, Mar 14, 2012 at 6:05 PM, Phil Young wrote:

> **
> But you still have the same problem.
> if (U1RBR != 13)
> {*rec = U1RBR;
> rec++;
> }
>
> change it to read to a char first.
>
> char Temp = U1RBR;
>
> if (Temp != 13)
> {*rec = Temp;
> rec++;
>
> }
>
> From: l... [mailto:l...] On Behalf
> Of
> DeV
> Sent: 14 March 2012 13:30
>
> To: l...
> Subject: Re: [lpc2000] LPC2378 UART 1 problem!!!
>
> ok i got a rough idea on what u are explaining..i have tried to use if else
> statements and have tried the following program...here all the loops are
> correctly entered...the problem is with the displaying the final string...i
> think u can have a look at the function LCD too since that too incorporates
> a pointer...
>
> The main program:
>
> InitLcd();
> //rec = &s[0];
> while(1)
> {//LCDClearScreen();
> //if((U1LSR & 1) == 1)
> //{
> //LCDPutStr("Overvoltage ", 100, 0, LARGE, RED, WHITE);
>
> if ((U1LSR & 1) == 1)
> {
> if(rec != &s[4])
> {
> if (U1RBR != 13)
> {*rec = U1RBR;
> rec++;
> }
> else
> {
> LCDClearScreen();
> LCDPutStr("Enter Key Pressed", 0, 0, LARGE, RED, WHITE);
> goto label;
> }
> }
> else
> {
> LCDClearScreen();
> LCDPutStr("buffer full", 20, 0, LARGE, RED, WHITE);
> goto label;
> }
> }
> else
> {
> LCDClearScreen();
> LCDPutStr("No Data", 40, 0, LARGE, GREEN, WHITE);
> }
> }
>
> label:
> LCDPutStr(s, 100, 0, LARGE, RED, WHITE);
> }
>
> **************************************************************
> The LCD functions:
>
> void LCDPutChar(char c, int x, int y, int size, int fColor, int bColor)
> {
> // extern const unsigned char FONT6x8[97][8];
> // extern const unsigned char FONT8x8[97][8];
> // extern const unsigned char FONT8x16[97][16];
> extern const unsigned char *FontTable[];
>
> int i;
> unsigned int j;
> unsigned int nCols;
> unsigned int nRows;
> unsigned int nBytes;
> unsigned char PixelRow;
> unsigned char Mask;
> unsigned int Word0;
> unsigned int Word1;
> unsigned char *pFont;
> unsigned char *pChar;
> // unsigned char *FontTable[] = { (unsigned char *)FONT6x8,
> // (unsigned char *)FONT8x8,
> // (unsigned char *)FONT8x16};
>
> // get pointer to the beginning of the selected font table
> pFont = (unsigned char *)FontTable[size];
> // get the nColumns, nRows and nBytes
> nCols = *pFont;
> nRows = *(pFont + 1);
> nBytes = *(pFont + 2);
> // get pointer to the last byte of the desired character
> // pChar = pFont + (nBytes * (c - 0x1F)) + nBytes - 1;
>
> // get pointer to the first byte of the desired character
> pChar = pFont + (nBytes * (c - 0x1F)) ;
>
> // Row address set (command 0x2B)
> WriteSpiCommand(PASET);
> WriteSpiData(x);
> WriteSpiData(x + nRows - 1 );
>
> // Column address set (command 0x2A)
> WriteSpiCommand(CASET);
> WriteSpiData(y);
> WriteSpiData(y + nCols - 1);
> // WRITE MEMORY
> WriteSpiCommand(RAMWR);
>
> // loop on each row, working from the top to the bottom
> for (i = nRows - 1; i >= 0; i--)
> {
> // copy pixel row from font table and then decrement row
> PixelRow = *pChar++;
> // loop on each pixel in the row (left to right)
> // Note: we do two pixels each loop
> Mask = 0x80;
> for (j = 0; j < nCols; j += 2)
> {
> // if pixel bit set, use foreground color; else use the background color
> // now get the pixel color for two successive pixels
> if ((PixelRow & Mask) == 0)
> Word0 = bColor;
> else
> Word0 = fColor;
>
> Mask = Mask >> 1;
>
> if ((PixelRow & Mask) == 0)
> Word1 = bColor;
> else
> Word1 = fColor;
>
> Mask = Mask >> 1;
> // use this information to output three data bytes
> WriteSpiData((Word0 >> 4) & 0xFF);
> WriteSpiData(((Word0 & 0xF) << 4) | ((Word1 >> 8) & 0xF));
> WriteSpiData(Word1 & 0xFF);
> }
> }
>
> // terminate the Write Memory command
> WriteSpiCommand(NOP);
> }
>
> void LCDPutStr(char *pString, int x, int y, int Size, int fColor, int
> bColor)
> { int z = y;
> // loop until null-terminator is seen
> while (*pString != 0x00)
> {
> // draw the character
> LCDPutChar(*pString++, x, y, Size, fColor, bColor);
>
> // advance the y position
> if (Size == SMALL)
> {y = y + 6;
> if(y > 123)
> {y = z;
> x = x + 16;}
> }
> else if (Size == MEDIUM)
> {y = y + 8;
> if(y > 123)
> {y = z;
> x = x + 16;}
> }
> else
> {y = y + 8;
> if(y > 123)
> {y = z;
> x = x + 16;}
> }
>
> // bail out if x and y exceeds 131
> if (y > 131) //break;
> {if(x>131)
> {break;}
> else
> {x = x + 16;
> y = z;
> }
> }
>
> }
> }
>
>
>
>
>
>
>

--

Dev Sampat****

Cell (Oman): (+968) - 9304 8932****

Email: d...@gmail.com


On 03/17/2012 06:35 AM, DeV wrote:
> hey thanks somuch Phil..my problem is solved now..its working
> perfect!...thanks again..cheers!

Congratulations - we just did this guy's homework!

Ralph