CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

sending ASCII characters

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
axmanjr



Joined: 07 Aug 2007
Posts: 25
Location: Las Vegas, NV

View user's profile Send private message

sending ASCII characters
PostPosted: Tue Aug 07, 2007 9:30 am     Reply with quote

I have a very noob-ish question. How do you send ASCII characters? I am using a PIC chip and am interfacing it with a serial graphic LCD (DX160, from Sparkfun). The data/info sheet says to send ASCII[186], or whatever number, to do certain tasks such as clear screen and so on. For right now, I want to write a very simple code to test the LCD screen. I have the serial wire from the LCD plugged into PIN_B2 of the chip. I have:

#use rs232(baud=9600, parity=N, xmit=PIN_B2, rcv=PIN_B3, stream=LCD, bits=8)

at the top of my code and have tried to send data to it by using:

fputc(186,LCD);

Is this the best/proper way of doing this? Any help is appreciated.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 07, 2007 1:39 pm     Reply with quote

Quote:
fputc(186,LCD);
Is this the best/proper way of doing this?

Yes, that's correct.

But I have a question about your connections between the PIC and
the DX160. The DX160 data sheet says:
Quote:

To connect it directly to a micro controller, connect the position marked
TTL to the MCU’s TX pin.
Connection to PC is done using the terminal marked RS232.

Is your PIC's TX pin (pin B2) connected directly to the "TTL" pin on the
DX160 ? That's one way to connect it. The other way is via a MAX232.
If your board has a MAX232 chip on it, and you're using the MAX232's
output, then you must connect it to the "RS232" pin on the DX160.
Make sure you have a ground connection between the PIC and
the DX160.

Also, what PIC are you using ? What compiler version ?
axmanjr



Joined: 07 Aug 2007
Posts: 25
Location: Las Vegas, NV

View user's profile Send private message

PostPosted: Tue Aug 07, 2007 3:01 pm     Reply with quote

Hi, thanks for the response. Yes, PIN_B2 is connected directly to the DX160's TTL pin. Also, I'm using the PIC18F4680 and I think my compiler version is 3.23 (haven't checked in a while).

Is it possible to setup the fputc statement in a loop, to send multiple ASCII characters to the DX160, like this:

//***********
char buffer[10];
int m;
buffer[0] = 186;
buffer[1] = 194;

for(m=0; m<2; m++)
fputc(buffer[m], LCD);
//***********

I'll mess with this more when I get home tonight. I noticed the datasheet saying something about being cautious with your delay settings. I think I have mine way to low.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 07, 2007 3:13 pm     Reply with quote

Yes, you can do a loop that way.

Note that the DX160 data sheet says the baud rate is 57600, not 9600.
Quote:

The baud rate is set at 57600,n,8,1 when the display is received from the factory.


It says you can change the baud rate by sending a command, but
presumably that command must be sent at 57600 baud. Then later
commands may use the lower baud rate.

You're using a software UART, because you've specified pins B2 and B3,
instead of C6 and C7. To use 9600 baud, you would have to specify
two #use rs232() statements. One would be defined for 57600 baud,
and the other for 9600. Name them as LCD57600 and LCD9600.
Start out with the high-speed stream, issue the command for the lower
baud rate, and then do all further communication by using the low speed
stream.

Alternatively, use the hardware UART, define one stream, initialize it for
57600 baud, then use the setup_uart() function (see the manual) to
change the baudrate to 9600.
axmanjr



Joined: 07 Aug 2007
Posts: 25
Location: Las Vegas, NV

View user's profile Send private message

PostPosted: Tue Aug 07, 2007 3:44 pm     Reply with quote

Thanks, I'll give that a try and update later!
axmanjr



Joined: 07 Aug 2007
Posts: 25
Location: Las Vegas, NV

View user's profile Send private message

PostPosted: Wed Aug 08, 2007 1:08 pm     Reply with quote

Success! Thanks again for your help! It worked, after much debugging and "trial and error" routines... I ended up sticking with the default 57600 BAUD rate. I realized that I had to use PIN_C6 for TX (hardware UART) because the software UART apparently had a limited BAUD rate range. It couldn't reach 57600. And switching the BAUD rate to something else was a pain. The program would freak out... So I stuck with 57600.

After solving other issues, I got the screen to display random boxes and simple text.

Again thanks!
axmanjr



Joined: 07 Aug 2007
Posts: 25
Location: Las Vegas, NV

View user's profile Send private message

PostPosted: Tue Aug 14, 2007 1:50 pm     Reply with quote

Question: If I want to use a 57600 BAUD rate to communicate to the LCD screen, would I need to use a specific crystal frequency to accomodate that?

Currently I am using a 4MHz crystal. But I am noticing a big lag when writing to the LCD screen, a big delay everytime something is being written to the screen.
Ttelmah
Guest







PostPosted: Tue Aug 14, 2007 3:18 pm     Reply with quote

If it is working, then you are sending close enough to 57600bps. At 4MHz, you will actually be sending at 58823bps, which is the closest that the hardware can do from this clock. Just over 2% 'fast'. Normally anything up to about 3 to 4%, is considered 'acceptable' (RS232 has some margin here...).
It depends how much data is being sent, and how you are sending it. If (for instance), you are performing significant arithmetic, this will take time, and would be quicker on a faster chip.
However you may find the display itself 'buffers' the data, and only performs an update some time latter (not uncommon). Things lke a clear screen, can take quite a long time.
Simple output of ASCII characters as shown, will be as fast as 'possible, on just about any clock rate!. However it can be suprising what slows things down. For instance, a simple array access, may easily take 20 or more instructions. At 4Mhz, there is time for 173 instructions between each character. If you are doing something else (timer interrupt for example), time might well become short.
What is the chip?. The maximum clock rate depends on this.

Best Wishes
Guest








PostPosted: Tue Aug 14, 2007 3:32 pm     Reply with quote

Thanks for the input. I'm not sure what the chip on the LCD is at the moment, but I am interfacing it with a PIC18F4680
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group