CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

printf() problem with int8 using rs232

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








printf() problem with int8 using rs232
PostPosted: Tue Feb 08, 2005 7:43 am     Reply with quote

Greetings,
I'm usingThe PCH C Compiler, Version 3.216 with the IDE version 3.215. I'm setting up a few basic tests to get familiar with the tools and hardware. The 18F458 micro is bread-boarded w/ a crystal, rs232 interface chip, and header for ICP. I cannot seem to get the printf() to correctly work with integers. Inside the test code, I try using several specification formats in the printf(). The only one that appears to work at all is the hex display (%x). My test code and results are listed below. Any help would be most appreciated.

Results: (captured data from each type of printf specification)
%d -> 26662666
%u -> 26266662
%x -> 0a0a0a0a



Code:
#include <18F458.h>
#device ICD=TRUE
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7, PARITY=N, BITS=8, STREAM=DEBUG)

#define RED_LED pin_B4


void main() {

   int value = 10;

   do {

      output_high(RED_LED);

      //printf("%d", value);

      //printf("%U", value);

      //printf("%c", value);
     
      //printf("%x", value);

      delay_ms(2000);

      output_low(RED_LED);
      delay_ms(2000);

   } while (TRUE);

}


Code:
CS PCH C Compiler, Version 3.216, 27010               07-Feb-05 16:50

               Filename: C:\PICTest\RS232Test.LST

               ROM used: 358 bytes (1%)
                         Largest free fragment is 31578
               RAM used: 7 (0%) at main() level
                         11 (1%) worst case
               Stack:    2 locations

*
0000:  GOTO   010A
....................   
.................... #include <18F458.h>
....................  //////// Standard Header file for the PIC18F458 device //////////////// 
.................... #device PIC18F458 
.................... #list 
.................... 
.................... #device ICD=TRUE 
.................... #fuses HS,NOWDT,NOPROTECT,NOLVP 
.................... #use delay(clock=10000000) 
00E0:  CLRF   FEA
00E2:  MOVLW  08
00E4:  MOVWF  FE9
00E6:  MOVF   FEF,W
00E8:  BZ    0108
00EA:  MOVLW  03
00EC:  MOVWF  01
00EE:  CLRF   00
00F0:  DECFSZ 00,F
00F2:  BRA    00F0
00F4:  DECFSZ 01,F
00F6:  BRA    00EE
00F8:  MOVLW  3C
00FA:  MOVWF  00
00FC:  DECFSZ 00,F
00FE:  BRA    00FC
0100:  NOP   
0102:  NOP   
0104:  DECFSZ FEF,F
0106:  BRA    00EA
0108:  RETLW  00
.................... #use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7, PARITY=N, BITS=8, STREAM=DEBUG) 
....................   
.................... #define RED_LED pin_B4 
....................   
....................   
.................... void main() { 
....................   
010A:  CLRF   FF8
010C:  BCF    FD0.7
010E:  CLRF   FEA
0110:  CLRF   FE9
0112:  BSF    FC1.0
0114:  BSF    FC1.1
0116:  BSF    FC1.2
0118:  BCF    FC1.3
011A:  MOVLW  07
011C:  MOVWF  FB4
011E:  MOVF   F96,W
0120:  MOVF   FB4,W
0122:  BCF    FA1.6
0124:  MOVLW  81
0126:  MOVWF  FAF
0128:  MOVLW  22
012A:  MOVWF  FAC
012C:  MOVLW  90
012E:  MOVWF  FAB
....................    int value = 10; 
0130:  MOVLW  0A
0132:  MOVWF  06
....................   
....................    do { 
....................   
....................       output_high(RED_LED); 
0134:  BCF    F93.4
0136:  BSF    F8A.4
....................   
....................       printf("%d", value); 
0138:  MOVFF  06,07
013C:  MOVLW  18
013E:  MOVWF  08
0140:  BRA    002C
....................   
....................       //printf("%U", value); 
....................   
....................       //printf("%c", value); 
....................   
....................       //printf("%x", value); 
....................   
....................       delay_ms(2000); 
0142:  MOVLW  08
0144:  MOVWF  07
0146:  MOVLW  FA
0148:  MOVWF  08
014A:  RCALL  00E0
014C:  DECFSZ 07,F
014E:  BRA    0146
....................   
....................       output_low(RED_LED); 
0150:  BCF    F93.4
0152:  BCF    F8A.4
....................       delay_ms(2000); 
0154:  MOVLW  08
0156:  MOVWF  07
0158:  MOVLW  FA
015A:  MOVWF  08
015C:  RCALL  00E0
015E:  DECFSZ 07,F
0160:  BRA    0158
....................   
....................    } while (TRUE); 
....................   
.................... } 
0162:  BRA    0134
.................... 
0164:  BRA    0164

Configuration Fuses:
   Word  1: 2200   HS NOOSCSEN
   Word  2: 0E0F   BROWNOUT WDT128 NOWDT BORV20 NOPUT
   Word  3: 0000 
   Word  4: 0001   STVREN DEBUG NOLVP
   Word  5: C00F   NOPROTECT NOCPD NOCPB
   Word  6: E00F   NOWRT NOWRTD NOWRTB NOWRTC
   Word  7: 400F   NOEBTR NOEBTRB
valemike
Guest







PostPosted: Tue Feb 08, 2005 8:33 am     Reply with quote

Cut and paste the following code and try it on your hardware and Hyperterminal. It works fine using the PICDEM-2 Plus.
Also, make sure the clock=xxxxxx is correct.

Make sure you have Hyperterminal set at:
bits per second: 9600
data bits: 8
parity: none
stop bits: 1
Flow Control: Hardware


Code:

#include <18F458.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <stdlib.h>

void main(void)
{
    unsigned long number;
    int i;
   
    printf ("\r\n\r\n\r\n");
    srand(16);
    for (i=0; i<20; i++)
    {
        number = rand();
        number = number%16;
        printf ("%ld\r\n", number);
    }
}
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Tue Feb 08, 2005 9:00 am     Reply with quote

So from your test code, are you expected to view the results on your RS232 port or with your ICSP debugging pod?

If you are expecting to stream data through the debugging pod, forget it. I just doesn't seem to work all that well.

Otherwise your code seems OK for writing to a serial port at 1200bps assuming you have a 10MHz crystal.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
jma_1



Joined: 08 Feb 2005
Posts: 147
Location: Wisconsin

View user's profile Send private message

problem solved
PostPosted: Tue Feb 08, 2005 2:26 pm     Reply with quote

Greetings,

I changed my bread-board setup to use a 5MHz crystal, re-connected everything and printf() with int8 works works fine now (PC RX using rs232). Perhaps a 10MHz crystal isn't the best idea for bread-boarding Wink Thanks for the replies
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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