View previous topic :: View next topic |
Author |
Message |
filjoa
Joined: 04 May 2008 Posts: 260
|
printf questions |
Posted: Fri Sep 04, 2009 2:35 pm |
|
|
Hi
I try print a string on hyperterminal but type "0" and "1" but only write garbage.
This is my code:
Quote: |
#include <18F252.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,BROWNOUT,STVREN
#use delay(clock=20000000)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
//======================
void main()
{
int8 speed1,speed2,btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8;
while(1)
{
if (input(PIN_B7)==1) speed1=1; else speed1=0;
if (input(PIN_B6)==1) speed2=1; else speed2=0;
if (input(PIN_B5)==1) btn1=1; else btn1=0;
if (input(PIN_B4)==1) btn2=1; else btn2=0;
if (input(PIN_B3)==1) btn3=1; else btn3=0;
if (input(PIN_B2)==1) btn4=1; else btn4=0;
if (input(PIN_B1)==1) btn5=1; else btn5=0;
if (input(PIN_B0)==1) btn6=1; else btn6=0;
if (input(PIN_C5)==1) btn7=1; else btn7=0;
if (input(PIN_C4)==1) btn7=1; else btn8=0;
printf("%d%d%d%d%d%d%d%d%d%d\0",speed1,speed2,btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8);
}
}
|
I have a resistor on PIC RX but if I don't have have the same result.
If I put printf("test\n"); on terminal appear 55ë55ë....
Someone can help me?
Kind regards
Last edited by filjoa on Sat Sep 05, 2009 8:33 pm; edited 1 time in total |
|
|
Ttelmah Guest
|
|
Posted: Fri Sep 04, 2009 2:56 pm |
|
|
Three possibilities:
1) Your crystal attached is not 20MHz (or is not running at 20MHz).
2) Your PC is not set to 115200bps.
3) Your wiring of the level translator/signal inverter in the connection to the PC is not correct.
Best Wishes |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Fri Sep 04, 2009 4:35 pm |
|
|
Hi
I stupid but correct answer is 3) I don't have max232 connected
But for print my original string? What is better I put speed1, speed2, like int1 or int8?
Used %d is correct for I print on terminal "0"and "1"?
On terminal I need some like this "0000000000" if any stry pressed...
kind regards |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Sat Sep 05, 2009 8:39 pm |
|
|
Hi
if I like print and value of ADC port (0-255) how I can save on my printf function 3 spaces?
I like print on terminal, reading from ADC this: "ADC:xx0" at "ADC:255" where xx is 2 spaces.
if "POS" is my ADC variable how I can print it like last example?
kind regards |
|
|
mbradley
Joined: 11 Jul 2009 Posts: 118 Location: California, USA
|
|
Posted: Sat Sep 05, 2009 11:29 pm |
|
|
If I understand you correctly, then you would do something like this:
printf("%03u",var);
the 0 says leading zeros, and the 3 says three places |
|
|
Ttelmah Guest
|
|
Posted: Sun Sep 06, 2009 4:05 am |
|
|
For leading _spaces_, just "%3u" though.
Best Wishes |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Sun Sep 06, 2009 6:55 am |
|
|
Hi
thanks... sorry my English.
is this "%3u" it work like need...
thanks friends |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Thu Sep 10, 2009 7:33 pm |
|
|
Hi
How I can configure on my program ADC for have range 0-1023?
kind regards |
|
|
Ttelmah Guest
|
|
Posted: Fri Sep 11, 2009 2:22 am |
|
|
At the top of the code, line after including the processor file, add the line:
#device adc=10
Then remember that the variables you use to hold the ADC value, must become int16 or larger, and you need to add the letter 'L' to the printf declarations: "%4LU".
Best Wishes |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Fri Sep 11, 2009 9:35 am |
|
|
for not open other post I expose my problem there...
I have many program where I need use hyperterminal, but I have always the same problem... for example...
in this case for see result of ADC on hyperterminal, if I turn on power supply of circuit and after I try connect hyperterminal, give me an erro, say some like "port in use" or somithink like that...
I need ever connect the program and after put the power on circuit...
this is normal? or I have some error on my circuit? some one have the same problem?
PS: I used windows XP or Vista, but the problem is the same.
kind regards |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Sat Sep 12, 2009 5:07 am |
|
|
this don'r happen anyone?
this is my circuit interface:
yours is the same?
kind regards |
|
|
|