![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Bill Legge
Joined: 07 Sep 2010 Posts: 24 Location: West Australia
|
get and put |
Posted: Sat Dec 18, 2010 11:47 pm |
|
|
I've been learning/testing the get/gets and put/puts functions with the following code:
Code: |
#include <main.h>
#use rs232(UART1,BAUD=2400) // default, 8_bits, no parity
#define HEARTBEAT PIN_H0
void main()
{
unsigned int8 caktr;
// strings are character arrays with null terminator
unsigned int8 string[30];
// set ups
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2|ADC_TAD_MUL_0);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_4(T4_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);
While(1){
printf("Type single character, it will be echoed\r\n");
// program works OK if the next two lines are deleter ????????????
caktr = getc(); // get one character
putc(caktr); // put one character
// ???????????????????????????????????????????????????????????????
printf("Type string terminated with CR(13),it will be echoed\r\n");
gets(string); // get string null added
puts(string); // put string until null
output_toggle(HEARTBEAT);
delay_ms(1000);
}
}
|
It works OK if the lines between the ???? are deleted. What am I doing wrong?
Regards Bill Legge _________________ Denmark in West Australia
'Where the forest meets the sea' |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Sun Dec 19, 2010 4:52 am |
|
|
First critical thing, add 'ERRORS' to your UART definition.
This should (must!) always be present when using the UART, _unless_ you have written alternative ERROR handling code. Without this, if any significant number of characters (two or more) are typed in the long delay, or while the printing is occurring, the UART _will_ become permanently 'hung'. Might be your problem.
Then, what terminal program are you using?.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Bill Legge
Joined: 07 Sep 2010 Posts: 24 Location: West Australia
|
put and get |
Posted: Sun Dec 19, 2010 5:01 pm |
|
|
Thanks for your reply.
I will try the 'ERRORS' but think that it's my code at fault and not the RS232 link/comms. I've used RS232 for a few years now (but not with a C compiler) and not come across this type of difficulty.
Terminal emulators used:
1. The tool included in the CCS compiler.
2. The tool included in the ME Labs PicBasicPro compiler, and
3. Downloaded from: https://sites.google.com/site/terminalbpp/
After three days of hair pulling with trying to parse a simple, formatted incoming RS232 stream - and extract the data. I think I will download the code on this site from 'Dave' - although I'm starting to feel dumb that I can not write my own code.
Regards Bill Legge _________________ Denmark in West Australia
'Where the forest meets the sea' |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|