[SOLVED] PIC UART Routine Yielding Unexpected Results

Status
Not open for further replies.

Kfir Maymon

Member level 1
Joined
Sep 20, 2013
Messages
40
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Location
Israel
Visit site
Activity points
315
hi,
sorry for the stupid question but what i am doing wrong?

Code:
long temp=0;
char txtt[11];

void init(){
CM1CON0=0x07;
ANSEL=0x0f;
TRISC=0x00;
TRISB=0xf0;
}


void main() {
init();
UART1_Init(19200);
while(1){

   temp = (1023 * 254);
   IntToStrWithZeros(temp, txtt);
   UART1_Write_Text("TEMP ");
   UART1_Write_Text(txtt);
   UART1_Write_Text("\r\n");

delay_ms(1000);
}
}

i get temp = -02302
 

I think variable "temp" should be an unsigned type. Try before with a smaller value, like just "1024".
 

same problem with unsigned,
i start to think i`m crazy.

update: i found the problem,
i needed to change,
this:
IntToStrWithZeros(temp, txtt);
to this:
LongWordToStrWithZeros(temp, txtt);
 
Last edited:

So you should see how the function "IntToStrWithZeros(temp, txtt);" works. What data type does it receive? Maybe even if you pass an unsigned value, inside the function it is treated as signed. Did you try using a small positive value as I suggested before?
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…