View previous topic :: View next topic |
Author |
Message |
grogue
Joined: 05 Dec 2015 Posts: 5
|
Problem with printf using terminal |
Posted: Tue Dec 08, 2015 12:23 pm |
|
|
Hey guys, I'm new here and I'm having some problems with the serial com.
I'm using a RS232 to USB converter and Tera Term to emulate a terminal in my computer. The thing is \f isn't working in this terminal and the information keeps coming over and over without erasing the old information. When I test the code in the virtual terminal on ISIS, it works.
I'm really going crazy here.
The program:
Code: | #include <Serial.h>
int x=0;
int y=0;
float value=0;
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_vref(FALSE);
setup_comparator(NC_NC_NC_NC);
//TODO: User Code
while(true){
value=3.4+(3.4*x);
if(input(pin_a0) && y==0){
x++;
delay_ms(20);
printf("\fNumber Value");
delay_ms(20);
printf("\n %u ",x);
printf("$%f",value);
y=1;
}
if(!input(pin_a0)){
y=0;
}
}
} |
Ps: Sorry 'bout my bad english |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Tue Dec 08, 2015 1:59 pm |
|
|
The command sequence for a VT terminal to clear the screen, is <ESC>[2J, not the 'form feed'. So "\x1B[2J" in printf.
You can set Tera term to automatically clear the screen on a page scroll, with the setting "ScrollWindowClearScreen=on", in the configuration file/ |
|
|
grogue
Joined: 05 Dec 2015 Posts: 5
|
|
Posted: Tue Dec 08, 2015 3:06 pm |
|
|
Thanks for the answer, Ttelmah!
I did everything you said but still not working.
The ScrollWindowClearScreen was on. I changed it to off just to test it but it changed nothing.
With the changes, the program is this:
Code: | #include <Serial.h>
int x=0;
int y=0;
float value=0;
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_vref(FALSE);
setup_comparator(NC_NC_NC_NC);
//TODO: User Code
while(true){
value=3.4+(3.4*x);
if(input(pin_a0) && y==0){
x++;
delay_ms(20);
printf("\x1B[2J Number Value");
delay_ms(20);
printf("\n %u ",x);
printf("$%f",value);
y=1;
}
if(!input(pin_a0)){
y=0;
}
}
}
|
Is this alright? |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Tue Dec 08, 2015 3:32 pm |
|
|
Change this:
Code: | printf("\x1B[2J Number Value");
|
to this:
Code: | printf("%x[2J Number Value", 0x1b); |
I know that there is probably a shortcut to getting printf to insert the escape via some sort of escape sequence (i.e. "\something"), but I have no idea what that is. |
|
|
grogue
Joined: 05 Dec 2015 Posts: 5
|
|
Posted: Tue Dec 08, 2015 4:01 pm |
|
|
Hey newguy, thanks for the answer!
Still not working. I'm receiving informations such as: "30.601[b2J Number Value" , "$27.201b[2J Number Value", etc.
The terminal is not erasing the old information and I don't know why, but the float number is coming before "Number". |
|
|
grogue
Joined: 05 Dec 2015 Posts: 5
|
|
Posted: Tue Dec 08, 2015 4:03 pm |
|
|
In fact, the first time I use it the information is "1b[2J Number". The float number just appear after this first information. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Tue Dec 08, 2015 6:03 pm |
|
|
I'm at a loss. I thought that the compiler might not recognize the "\x" escape sequence, so that's why I suggested what I did.
Where your // TODO: User code line is, try inserting
printf("\n\n\n\n\n");
I don't know if that will help but my line of thought is that the PC or the serial-USB dongle is having issues synchronizing the data stream from your PIC.
You could also alter your program to simply printf() a dummy sentence - simply to help you diagnose the proper screen wipe/refresh character sequence, then put your desired code back in.
Try printing
Hello 1
(delay 1 second)
(screen erases)
Hello 2
(delay 1 second)
(screen erases)
etc. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 08, 2015 10:59 pm |
|
|
TeraTerm has a 10000 line buffer. If I go into the Setup / Window menu
in TeraTerm, and untick the tickbox for "Scroll Buffer", then the
following program works.
It displays blocks of lines of x, y, and z. It clears the screen and
homes the cursor after displaying each block:
Code: |
#include <18F4620.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)
//=====================================
void main()
{
int8 i;
for(i=0; i<10; i++)
{
printf("Line %u xxxxxxxxxxxxxxxxxxxxxxxxx \n\r", i);
}
delay_ms(2000);
printf("\x1b[2J"); // Clear screen
printf("\x1b[H"); // set cursor to 0,0
for(i=0; i<10; i++)
{
printf("Line %u yyyyyyyyyyyyyyyyyyyyyyyyy \n\r", i);
}
delay_ms(2000);
printf("\x1b[2J"); // Clear screen
printf("\x1b[H"); // set cursor to 0,0
for(i=0; i<10; i++)
{
printf("Line %u zzzzzzzzzzzzzzzzzzzzzzzzz \n\r", i);
}
delay_ms(2000);
printf("\x1b[2J"); // Clear screen
printf("\x1b[H"); // set cursor to 0,0
while(TRUE);
}
|
|
|
|
grogue
Joined: 05 Dec 2015 Posts: 5
|
|
Posted: Thu Dec 10, 2015 10:46 pm |
|
|
PCM programmer, thank you very much!
The problem was really the scroll buffer option! Now it works like a charm!
Thanks everybody! You guys helped me a lot! |
|
|
|