|
|
View previous topic :: View next topic |
Author |
Message |
azand1
Joined: 04 Feb 2014 Posts: 9
|
Trouble in RS232 stream. v.5.021 |
Posted: Sat Mar 29, 2014 11:27 pm |
|
|
Trouble in RS232 stream.
In version 4.124 works. OK!!
In version 5.0 - 021, does not work.
I ask for help.
Obs: translated into English.
Code: |
#include <18LF24J11.h>
#FUSES NOWDT
#FUSES INTRC_IO
#FUSES NOPROTECT
#FUSES RTCOSC_T1
#use delay(clock=8000000) // funcionou com 4Mhz
#use rs232(uart1,baud=4800,parity=N,bits=8,stream=buffer)
//char buffer[160];
rtc_time_t tWriteTime;
rtc_time_t tAlarmTime;
#int_RTC
void RTC_isr(void)
{
rtc_alarm_read(&tAlarmTime);
//sprintf(buffer,"%02u:%02u:%02u",tAlarmTime.tm_hour,tAlarmTime.tm_min,tAlarmTime.tm_sec); // not working
sprintf(buffer,"\n\r%02u/%02u/20%02u %02u:%02u:%02u",tAlarmTime.tm_mon,tAlarmTime.tm_mday,tAlarmTime.tm_year,tAlarmTime.tm_hour,tAlarmTime.tm_min,tAlarmTime.tm_sec); // not working
printf("%s\n\r",buffer);
}
void main()
{
delay_ms(1000);
tWriteTime.tm_year = 9;
tWriteTime.tm_mon = 11;
tWriteTime.tm_mday = 24;
tWriteTime.tm_wday = 2;
tWriteTime.tm_hour = 16;
tWriteTime.tm_min = 1;
tWriteTime.tm_sec = 0;
tAlarmTime.tm_year = 9;
tAlarmTime.tm_mon = 11;
tAlarmTime.tm_mday = 24;
tAlarmTime.tm_wday = 2;
tAlarmTime.tm_hour = 16;
tAlarmTime.tm_min = 1;
tAlarmTime.tm_sec = 5;
setup_rtc(RTC_ENABLE | RTC_OUTPUT_SECONDS, 0x00);
setup_rtc_alarm(RTC_ALARM_ENABLE, RTC_ALARM_HOUR|RTC_ALARM_MINUTE|RTC_ALARM_SECOND, 10);
rtc_write(&tWriteTime);
rtc_alarm_write(&tAlarmTime);
enable_interrupts(GLOBAL);
enable_interrupts(int_rtc);
//
rtc_read(&tWriteTime);
sprintf(buffer,"\n\r%02u/%02u/20%02u %02u:%02u:%02u",tWriteTime.tm_mon,tWriteTime.tm_mday,tWriteTime.tm_year,tWriteTime.tm_hour,tWriteTime.tm_min,tWriteTime.tm_sec);
printf("%s\n\r",buffer);
while(1)
{
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 30, 2014 12:32 am |
|
|
Is your basic complaint that sprintf doesn't work with the 18LF24J11 with
vs. 5.021 ?
It worked for me. I cleaned up your program. I did not name the
stream as "buffer" and then try to send sprintf output to the stream.
That's not supported. It's not in the CCS manual.
I compiled the following test program with vs. 5.021, then I ran it in
MPLAB simulator with the RS232 output sent to the Output Window.
It displays this:
Quote: | 11/24/2009 16:01:00 |
It's working.
Here is the test program:
Code: |
#include <18LF24J11.h>
#FUSES NOWDT
#FUSES INTRC_IO
#FUSES NOPROTECT
#FUSES RTCOSC_T1
#use delay(clock=8000000)
#use rs232(uart1,baud=4800,parity=N,bits=8)
char buffer[160];
rtc_time_t tWriteTime;
rtc_time_t tAlarmTime;
void main()
{
tWriteTime.tm_year = 9;
tWriteTime.tm_mon = 11;
tWriteTime.tm_mday = 24;
tWriteTime.tm_wday = 2;
tWriteTime.tm_hour = 16;
tWriteTime.tm_min = 1;
tWriteTime.tm_sec = 0;
tAlarmTime.tm_year = 9;
tAlarmTime.tm_mon = 11;
tAlarmTime.tm_mday = 24;
tAlarmTime.tm_wday = 2;
tAlarmTime.tm_hour = 16;
tAlarmTime.tm_min = 1;
tAlarmTime.tm_sec = 5;
sprintf(buffer,"\n\r%02u/%02u/20%02u %02u:%02u:%02u",tWriteTime.tm_mon,tWriteTime.tm_mday,tWriteTime.tm_year,tWriteTime.tm_hour,tWriteTime.tm_min,tWriteTime.tm_sec);
printf("%s\n\r", buffer);
while(1)
{
}
} |
|
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Mon Mar 31, 2014 10:53 am |
|
|
I would agree..
S-printf means "STRING" not stream at last I recall.
you use FPRINTF to print to a stream typically.
I'm not using 5.x yet, but the code you supplied already shows a disconnect between what you think you can do with printf in the f- and s- form.
if I were using both for some reason it would go more like this: (not a compilable example)
Code: |
#use rs232(uart1,baud=4800,parity=N,bits=8,stream=COM1)
char buffer [160];
sprintf(buffer, "some string with stuff in it\r\n");
fprintf(COM1, buffer);
|
I probably wouldn't do exactly as shown above since fprintf can take sprintf syntax. If I were to bother using sprintf and then fprintf like that above, it'd be because I was doing something more complex than that.. but you get the idea.
check the PIC-C manual for more.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
|
|
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
|