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 CCS Technical Support

How to get the ASCII by RS-232

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







How to get the ASCII by RS-232
PostPosted: Mon Nov 01, 2004 5:02 am     Reply with quote

G'day everybody


HMR3300Compass---------.18F458

TX---------(ASCII)------------->RX

RX--------------------------------TX


now I have a simple project that use 18F458 to receive ASCII format data from Honeywell digital compass HMR3300

and want to save it's data to RAM

The compass will send data 8 times per second

format is ASCII

like this

Honeywell HMR3300 (0.6)
#A
251.2,6.2,0.9
251.5,7.5,0.1
251.8,8.9,-0.6
251.8,9.0,-0.6
251.9,9.2,-0.5
251.9,9.2,-0.6
251.9,9.3,-0.7
251.8,9.1,-0.6
251.8,9.1,-0.5
251.9,9.2,-0.6
251.8,9.2,-0.7
251.9,9.3,-0.7
251.8,9.1,-0.7

but I don't know how to do it..

below is my code....
Please help me

Regards
---------------------------------------------------------------
#include <18f458.h>
#fuses HS,NOLVP,NOWDT,PUT
#device ICD=TRUE
#device ADC=10
#include <math.h>
#use delay(clock=16000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)

#include <stdio.h>
#include <stdlib.h>

main()
{
char* data[];
while(1)
{
*data=getch()
}
}
Code:
[list][/list]
Trampas



Joined: 04 Sep 2004
Posts: 89
Location: NC

View user's profile Send private message MSN Messenger

PostPosted: Mon Nov 01, 2004 6:32 am     Reply with quote

You are off to a good start....

First off in your design do you have a serial port for connecting PIC to PC?

Code:
main()
{
    char data[20];
    int i;
   
    i=0;
    while(i<20)
    {
        data[i]=getch();
        i++;
     }
     //now first 20 ascii chars are in data[].
     // next look at the string functions like strtok
     // then you can start parsing the data
     // if you have serial port to PC I would recommend echoing data to PC

}


Now I would also recommend you look at writting your code on the PC first. That is store your sample data in a file then use the fgetc() function to get the data and write your processing program on the PC. It would be much easier to debug.

Trampas
Guest








PostPosted: Tue Nov 02, 2004 3:47 am     Reply with quote

I use getch() to receive one character from keyboard...but no responce..

also use simple program to check ...likes...

main()
{
while(kbhit())
{
output_d(255);
}
}

can't entry while loop..

why.. Sad
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Nov 02, 2004 5:35 am     Reply with quote

Quote:
I use getch() to receive one character from keyboard...but no responce..


You have not provided enough information to explain your problem.

Quote:
also use simple program to check ...likes...

main()
{
while(kbhit())
{
output_d(255);
}
}


Two problems. If there is no character present the very first time the expression kbhit() is evaluated the while condition is false and therefore the code within the while loop will never be executed. However if there is a character present before the expression is evaluated the code within the while loop will be executed continuously as no attempt is made within the while loop to read the character.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Ttelmah
Guest







PostPosted: Tue Nov 02, 2004 5:43 am     Reply with quote

Anonymous wrote:
I use getch() to receive one character from keyboard...but no responce..

also use simple program to check ...likes...

main()
{
while(kbhit())
{
output_d(255);
}
}

can't entry while loop..


why.. Sad


The code as written, won't work. It will start by detecting that there is not a character, and therefore drop 'off the end' of the code, and hit the hidden 'sleep' instruction, that CCS places there. Try:
Code:

main()
{
   while(true) {
      while (kbhit()) {
          //You must get the character, or kbhit will remain asserted
          getc();
          output_d(255);
          delay_us(100);
      }
      output_d(0);
}


This will assert the whole of portd high for 100uSec, when a character is seen.

Best Wishes
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