Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] PIC UART Routine Yielding Unexpected Results

Status
Not open for further replies.

Kfir Maymon

Member level 1
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
Screenshot 2014-09-27 16.57.05.png
 

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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top