|
|
View previous topic :: View next topic |
Author |
Message |
Herry Guest
|
How to get the ASCII by RS-232 |
Posted: Mon Nov 01, 2004 5:02 am |
|
|
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()
}
} |
|
|
Trampas
Joined: 04 Sep 2004 Posts: 89 Location: NC
|
|
Posted: Mon Nov 01, 2004 6:32 am |
|
|
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
|
|
Posted: Tue Nov 02, 2004 3:47 am |
|
|
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.. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Tue Nov 02, 2004 5:35 am |
|
|
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
|
|
Posted: Tue Nov 02, 2004 5:43 am |
|
|
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.. |
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 |
|
|
|
|
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
|