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

Read characters from uart using RS232
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
lozi_dani



Joined: 22 Jan 2016
Posts: 40

View user's profile Send private message

PostPosted: Mon May 16, 2016 9:04 am     Reply with quote

Ok I have changed putc(1); for putc('J');, but i'm still receiving xxxxxxxxxxx....

I have also changed the #use rs232 like this:
Code:

#use RS232(BAUD=9600, parity=N, stop=1, XMIT=PIN_C6, RCV=PIN_C7, bits=8, ERRORS)

And I've checked in PUTTY the settings of the Serial, and I have now the same parameters in both places.

Maybe could be the UART of my PIC wrong? Its strange because this PIC is new.
temtronic



Joined: 01 Jul 2010
Posts: 9632
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon May 16, 2016 10:23 am     Reply with quote

try a 'loopback test'.

disconnect PIC tx and rx from USB<>TTL module

connect RX and TX of USB module together.

now press keys on PC KBD. They should be seen on the PC screen.
This will confirm that PUTTY works and that the USB module functions.
However... there can be a 'problem'.

There are TWO styles of USB 'modules'

1) USB<>RS232

2) USB<>TTL

You need the 2nd one, USB<>TTL to connect the PIC to PC.

If you post a link of the one you are using ,we can see what you have.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 20061

View user's profile Send private message

PostPosted: Mon May 16, 2016 10:24 am     Reply with quote

99.99999%, no.

Most likely thing is that your PIC is not actually running at 20MHz.

This comes to the basic 'flash an LED' test.

Connect an LED (with a suitable current limiting resistor), to an output pin on the PIC, and run a program like:
Code:

#include <UART.h>
#include <input.c> //contains get_string
#include <string.h> //needed for the string functions.
#include <stdlib.h>
#use delay(clock=20000000)
#use RS232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, ERRORS)

void main(void)
{
   while(true){
      output_high(LED); //where 'LED' is the pin you are using
      delay_ms(1000);
      output_low(LED);
      delay_ms(1000);
   }
}


The LED must stay on for 1 second, then off for one second. I'd guess you are going to see it perhaps being on for a couple of seconds.

The reason for this guess, is that your posted message, is about twice as many characters as the message being transmitted. This almost certainly implies the PIC is actually running at about half the speed you think it is. Check what the crystal is on the board?.
lozi_dani



Joined: 22 Jan 2016
Posts: 40

View user's profile Send private message

PostPosted: Mon May 16, 2016 11:44 am     Reply with quote

Thanks temtronic! I'm going to try that first. About what you are telling Ttelmah about the blink led program, I have already tried that using the blink led example that CCS C Compiler provides and everything seem to work well. What I have not tried is to do the blink led using all the initialize code I'm using for the UART program. I will try that too. The external crystal I'm using is of 20mhz, and I'm using the external crystal in the fuses using HS config. As I said, using the blink led program that CCS provides, works well. But let me try using the uart code and I will put the results now for your help guys!
jeremiah



Joined: 20 Jul 2010
Posts: 1411

View user's profile Send private message

PostPosted: Mon May 16, 2016 1:30 pm     Reply with quote

lozi_dani wrote:
Thanks temtronic! I'm going to try that first. About what you are telling Ttelmah about the blink led program, I have already tried that using the blink led example that CCS C Compiler provides and everything seem to work well. What I have not tried is to do the blink led using all the initialize code I'm using for the UART program. I will try that too. The external crystal I'm using is of 20mhz, and I'm using the external crystal in the fuses using HS config. As I said, using the blink led program that CCS provides, works well. But let me try using the uart code and I will put the results now for your help guys!


When you say it works well, did you measure the time it takes to turn the LED on and off with an oscilloscope or some other measurement device. The whole point of that test is to make sure the timing of the on/off cycle is correct. Eyeballing it is a chance to mis-measure. The difference between 1.0 second and 1.2 seconds can be difficult to eyeball but make a huge difference in the UART output.
Ttelmah



Joined: 11 Mar 2010
Posts: 20061

View user's profile Send private message

PostPosted: Mon May 16, 2016 1:38 pm     Reply with quote

lozi_dani wrote:
Ok after look for some information about how to connect the rs232 to the PC, I've seen the solution I think I am going to implement:
I am going to try to connect the rs232 port to the MAX232 driver. the MAX232 driver to a RS232 to TTL adapter like this:

http://img.dxcdn.com/productimages/sku_148963_1.jpg

and this Rs232 adapter to a Serial /TTL to Usb adapter like this:

https://wiki.openwrt.org/_media/doc/hardware/usbtors232.ttl.jpeg

I've not found other simplest solution... =(

I will go tomorrow to buy everything, because as I saw, I need this component and some capacitors that I have not now to try it.

Anyway, if someone has another solution please tell me, because if my solution doesn't works I need to try something different..


I'm worried by this.

You are talking about using a MAX232, but also about using a TTL adapter.

These are 'either or', not 'both'.

The PIC talks async TTL serial. Not RS232.
To convert TTL serial to RS232 you use a MAX232 or similar adapter. The module you point to, is such an adapter.
PC serial is normally RS232. However there has also been a link posted to a USB to async TTL adapter. If using this, no MAX232 is needed.
lozi_dani



Joined: 22 Jan 2016
Posts: 40

View user's profile Send private message

PostPosted: Tue May 17, 2016 11:00 am     Reply with quote

Ok! I have tried what you both said to me. I have connected the TTL<>USB to my PC connecting RX and TX pins between them, I've used the program Coolterm to see what is happening when I write something and at the moment I write, Tx and RXgreen leds of the program turns on, so I guess that something is going between them when I send something through TX.

After I've tried to do the same program using a led to check if the speed is correct, and it isn't. With this code:

Code:

#include <UART.h>
#include <input.c> //contains get_string
#include <string.h> //needed for the string functions.
#include <stdlib.h>
#use delay(clock=20000000)
#use RS232(BAUD=9600, parity=N, stop=1, XMIT=PIN_C6, RCV=PIN_C7, bits=8, ERRORS)

#define CLEAR_UART() while(kbhit()) dummy=getc()
#define LED PIN_D1

void main()
{
   output_low(LED);
   
   while(true){
      output_high(LED);
      putc('J');
      delay_ms(500);
      output_low(LED);
      putc('J');
      delay_ms(500);

   }

}


I can see how the led is blinking, but not each 500ms, it delays much more, between 1000 and 1500ms.

I've tried just now to use the UART program using the configuration bits of the Blink Led example, and I am able to see the 'J' character and the led blinking each 500ms, so I suppose the problem must be the configuration bits of the UART program.
This is the code:

Code:

#include <Blink_Led.h>
//#include <input.c> //contains get_string
#include <string.h> //needed for the string functions.
#include <stdlib.h>
#use RS232(BAUD=9600, parity=N, stop=1, XMIT=PIN_C6, RCV=PIN_C7, bits=8, ERRORS)

int8 dummy;

#define CLEAR_UART() while(kbhit()) dummy=getc()

void main()
{


    //Example blinking LED program
    while(true){
      output_low(LED);
      putc('J');
      delay_ms(DELAY);
      output_high(LED);
      putc('J');
      delay_ms(DELAY);
    }

}


As you can see I had to comment the <input.c> library. I don't know why but using this code CCS gives me an error saying that putc is not declared inside of <input.c> library. I don't know why is telling me this because when I compile my UART program, it doesn't gives me any errors.

Maybe you could know why could be giving me this error? The main problem is that in that library I have the get_string function, whici I need to take the string I want to send to the pic via wifi to see which motor I want to turn on... =(

At least I have my UART working hehe!



edit: I think I've seen the problem but I'm not able to see how to fix it.
When I see my UART.h file, I can see this line:
Code:
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)

If I comment this line (because I already have it in my UART.c file), the pogram gives me that error related with <input.c> library, but I can see the ¡J' character each 500ms as I want in the Hyperterminal. The problem is that I have to comment the <input.c> line to run the program, and with this, I can't use the get_string() function.

If I comment the #use rs232... line of the UART.c code and uncomment the #use rs232... line of the UART.h code, the <input.c> line doesn't gives me any error, but I can not see the 'J' character each 500ms. The led turns on around each 2 seconds, and when it turns on, the Hyperterminal starts to print the 'J' character a lot of times until the led turn off.

Line #use rs232 in UART.h:
Code:
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)


Line #use rs232 in UART.c:
Code:
#use RS232(BAUD=9600, parity=N, stop=1, XMIT=PIN_C6, RCV=PIN_C7, bits=8, ERRORS)



The main problem of all of this is that I can not use the get_string() function if the code gives me that error with <input.c> library.

Why could be this happening? It is normal? Maybe I am doing something wrong that I am not able to see?

thanks a lot!
Ttelmah



Joined: 11 Mar 2010
Posts: 20061

View user's profile Send private message

PostPosted: Tue May 17, 2016 12:10 pm     Reply with quote

If you think your fuses are the problem. _Post them_. Throughout, you are making things complex by leaving things out.

The reason for your error is covered dozens of times here.

The order of files in CCS must be:

1) Processor file
2) Fuses
3) Clock configuration
4) 'Select' statements if applicable for the chip
5) Peripheral configuration (#use RS232, I2C, etc. etc..)
6) Only then include library files.
7) Your code.

You have moved input.c above the RS232 declaration, so it can't work, since there is no port defined.
Same applies to anything like LCD, using delays. This must be after the clock definitions.
lozi_dani



Joined: 22 Jan 2016
Posts: 40

View user's profile Send private message

PostPosted: Tue May 17, 2016 12:38 pm     Reply with quote

You're right Ttelmah! I've put the <input.c> line under the fuses declaration and works perfectly. I didn't know that <input.c> also depens of the fuses..Good lesson for me, I have to print in my mind that order of declarations you give me. Thanks!!

About the fuses, I have the next (Blink_Led works fine and UART works but with wrong delays).

Blink_Led.c:
Code:

#include <Blink_Led.h>
#include <string.h> //needed for the string functions.
#include <stdlib.h>
#use RS232(BAUD=9600, parity=N, stop=1, XMIT=PIN_C6, RCV=PIN_C7, bits=8, ERRORS)
#include <input.c> //contains get_string

int8 dummy;

#define CLEAR_UART() while(kbhit()) dummy=getc()

void main()
{


    //Example blinking LED program
    while(true){
      output_low(LED);
      putc('J');
      delay_ms(DELAY);
      output_high(LED);
      putc('J');
      delay_ms(DELAY);
    }

}

Blink_Led.h:
Code:

#include <18F4550.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES PLL12                    //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV4                  //System Clock by 4
#FUSES USBDIV                   //USB clock source comes from PLL divide by 2
#FUSES XT                       //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES VREGEN                   //USB voltage regulator enabled
#FUSES PBADEN                   //PORTB pins are configured as analog input channels on RESET
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES ICPRT                    //ICPRT enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads

#use delay(crystal=20000000,  clock=5000000)
#define LED PIN_D1
#define DELAY 500


Now the UART code:

UART.c:
Code:

#include <UART.h>
#include <string.h> //needed for the string functions.
#include <stdlib.h>
#use delay(clock=20000000)
#use RS232(BAUD=9600, parity=N, stop=1, XMIT=PIN_C6, RCV=PIN_C7, bits=8, ERRORS)
#include <input.c> //contains get_string

int8 dummy;
#define CLEAR_UART() while(kbhit()) dummy=getc()
#define LED PIN_D1

void main()
{
   output_low(LED);
   
   while(true){
      output_high(LED);
      putc('J');
      delay_ms(500);
      output_low(LED);
      putc('J');
      delay_ms(500);

   }

}


UART.h:
Code:

#include <18F4550.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES PLL12                    //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV4                  //System Clock by 4
#FUSES USBDIV                   //USB clock source comes from PLL divide by 2
#FUSES XT                       //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES VREGEN                   //USB voltage regulator enabled
#FUSES PBADEN                   //PORTB pins are configured as analog input channels on RESET
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES ICPRT                    //ICPRT enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads

#use delay(crystal=20000000,  clock=5000000)



Now i will continue working with the Blink_Led code adapted. Anyway, I cannot see what is wrong with mt UART code =(

I am going to try now to read something from the PC and send an answer from the PIC depending of what I am typing. I think that if I achieve that I will be able to configure my WiFi module using RS232.
Ttelmah



Joined: 11 Mar 2010
Posts: 20061

View user's profile Send private message

PostPosted: Tue May 17, 2016 1:07 pm     Reply with quote

Both are wrong:
Code:

#FUSES NOWDT               //No Watch Dog Timer
#FUSES WDT128              //Watch Dog Timer uses 1:128 Postscale
#FUSES PLL5                   //Divide By 5(20MHz crystal input)
#FUSES CPUDIV1            //System Clock by.
#FUSES USBDIV              //USB clock source comes from PLL divide by 2
#FUSES HS                      //Crystal is 20MHz - requires HS
#FUSES FCMEN                //Fail-safe clock monitor enabled
#FUSES IESO                  //Internal External Switch Over mode enabled
#FUSES PUT                    //Crystal requires Power Up Timer
#FUSES NOBROWNOUT    //No brownout reset
#FUSES BORV20              //Brownout reset at 2.0V
#FUSES VREGEN              //USB voltage regulator enabled
#FUSES PBADEN              //PORTB pins are configured as analog input channels on RESET
#FUSES LPT1OSC             //Timer1 configured for low-power operation
#FUSES MCLR                  //Master Clear pin enabled
#FUSES STVREN               //Stack full/underflow will cause reset
#FUSES NOLVP                 //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES ICPRT                  //ICPRT enabled
#FUSES NOXINST              //Extended set extension and Indexed Addressing mode disable (Legacy mode)
#FUSES NODEBUG            //No Debug mode for ICD
#FUSES NOPROTECT         //Code not protected from reading
#FUSES NOCPB                //No Boot Block code protection
#FUSES NOCPD                //No EE protection
#FUSES NOWRT                //Program memory not write protected
#FUSES NOWRTC              //configuration not registers write protected
#FUSES NOWRTB              //Boot block not write protected
#FUSES NOWRTD              //Data EEPROM not write protected
#FUSES NOEBTR               //Memory not protected from table reads
#FUSES NOEBTRB             //Boot block not protected from table reads

#use delay(clock=20MHz)


I'm assuming you do want to run USB (since you are enabling the USB clock, and the USB vreg). The USB PLL requires 4MHz input. Also USB requires a minimum of about 8MHz for the CPU clock.

You have a 20MHz crystal, but are selecting the oscillator to drive crystals to 10MHz max.

You are dividing the crystal by 4 to run at 5MHz. In the version that works you are telling it this, but like this it won't handle USB properly. The fuses posted above run at 20MHz. If you want to run at 10MHz, change to CPUDIV2, and clock=10MHz.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue May 17, 2016 3:21 pm     Reply with quote

Hi,

It really amazes me how many users of the CCS compiler neglect the simplest of tests to verify that their PIC is running, and running at the correct speed!! The classic 'blinking LED' test should be job #1 for every single CCS 'C' project you create! This is especially true for PIC's with the more complex clock architectures. Sometimes the smallest error will put you right in the weeds, and you won't necessarily know it right off.....

BTW, Ttelmah did recommend that you do a blinking LED test at the top of page #2 of this thread, and if you'd taken his advise, you would have saved yourself a lot of aggravation. Hint: when Ttelmah or PCM programmer (and a whole host of other folks!) make a suggestion like this, it's best that you heed it!
_________________
John

If it's worth doing, it's worth doing in real hardware!
lozi_dani



Joined: 22 Jan 2016
Posts: 40

View user's profile Send private message

PostPosted: Tue May 17, 2016 3:39 pm     Reply with quote

The truth is that I don't want to use USB, I am using external oscillator but I don't know how to tell to CCS C Compiler that I don't want that, I didn't see an External Oscillator option.. So I used the default config of the crystal in that option and simply I don't use it. I know this isn't professional, but I don't see that option anywhere..

About the code, what I am trying now is to send something to the PIC, and the PIC should give me a response depending on what I am sending. I have used this code and works perfectly:
Code:

#include <Blink_Led.h>
#include <string.h> //needed for the string functions.
#include <stdlib.h>
#use RS232(BAUD=9600, parity=N, stop=1, XMIT=PIN_C6, RCV=PIN_C7, bits=8, ERRORS)
#include <input.c> //contains get_string

int8 dummy;
int compare;

#define CLEAR_UART() while(kbhit()) dummy=getc()

#define BUFFER_MAX_SIZE 4
char datos[BUFFER_MAX_SIZE];
char datos2[]= "hola";

void main()
{

   output_low(LED);
   
    //Example blinking LED program
    while(true){
      output_high(LED);
      get_string(datos, BUFFER_MAX_SIZE);
      puts(datos);
    }

}


Here, if I type "hola", the PIC sends me another "hola". Until here everything ok.

But now I want to receive an answer depending on what I am sending. I am using this code.
Code:

#include <Blink_Led.h>
#include <string.h> //needed for the string functions.
#include <stdlib.h>
#use RS232(BAUD=9600, parity=N, stop=1, XMIT=PIN_C6, RCV=PIN_C7, bits=8, ERRORS)
#include <input.c> //contains get_string

int8 dummy;
int compare=0;

#define CLEAR_UART() while(kbhit()) dummy=getc()

#define BUFFER_MAX_SIZE 22
char datos[BUFFER_MAX_SIZE];
//char datos2[]= "hola";
char auto_man[] = "http://192.168.1.6/P11";
char derecha[] = "http://192.168.1.6/P12";
char izquierda[] = "http://192.168.1.6/P13";

void main()
{
   delay_ms(500);
   //configuracion del wifi
   /*puts("AT+CWMODE=3\r\n");
   delay_ms(1000);
   CLEAR_UART(); //throw reply away
   puts("AT+CIPMUX=1\r\n");
   delay_ms(1000);
   CLEAR_UART(); //throw reply away
   puts("AT+CIPSERVER=1,80\r\n");*/
   

    while(true){
      output_high(LED);
      get_string(datos, BUFFER_MAX_SIZE);
      puts("\n");
      puts(datos);
     
      //compare auto_man
      compare = strcmp(datos, auto_man);
      puts("compare de auto_man = ");
      puts(compare);
         if(strcmp(datos, auto_man)){
                  output_high(PIN_D5);
                  delay_ms(500);}
                               

      //compare derecha
      compare = strcmp(datos, derecha);
      puts("compare de derecha = ");
      puts(compare);
         if(strcmp(datos, derecha)){
                output_high(PIN_D6);
                delay_ms(500);}
           

      //compare izquierda
      compare = strcmp(datos, izquierda);
      puts("compare de izquierda = ");
      puts(compare);
         if(strcmp(datos, izquierda)){
               output_high(PIN_D7);
               delay_ms(500);}
                     
      output_low(LED);
      output_low(PIN_D5);
      output_low(PIN_D6);
      output_low(PIN_D7);
      delay_ms(500);
      compare = 0;
 }
}


Here I send an IP (which will be the IP address of the WiFi module, and a command like: http://192.168.1.6 (ip) and /P11 or /P12 or /P13 depending if the command I want to send.

I am controlling some leds also depending of what I am sending to the PIC.

I am seeing that the results are not the expected, so I decide to see in the Hyperterminal which is the value that the "compare" variable is receiving from the srtcmp() function.

I thought that this function will returns a 0 or 1, if the result of the comparison is false or true, but the puts(compare) function returns to me this:
Code:

http://192.168.1.6/P11  <--this is what I am typing
compare de auto_man =    <--this next lines are the result

compare de derecha =
œ¨]õZë é$'.#£©1×È..¶.
compare de izquierda =
œ¨]õZë é$'.#£©1×È..¶.     <--


In the way the program is built, it should only returns to me with this example:

compare de auto_man = 1

and nothing more, but for some reason that I am not able to see, is going through all the ifs I wrote.

I suppose that the code goes through all the ifs, because I am not receiving the expected 0 or 1.

How can I receive 0 or 1 with strcmp() function? I thought it should returns only that two values.. And I am sure that the problem is not the crystal or the baud rate, because everything is displayed right, only the result of the strcmp() function gives me something different of what I am expecting..

Maybe I should use another function to do this?

Thanks a lot! At least I have the UART working, I have advanced a lot from the beginning..
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 17, 2016 7:50 pm     Reply with quote

You need to read the CCS manual instead of dumping code on us.

Here is an example of where you did not read the manual:
Quote:
int compare=0;

compare = strcmp(datos, auto_man);
puts("compare de auto_man = ");
puts(compare);

You are using puts to send an 'int'. But that's not what the CCS manual
says you need to do. The manual says:
Quote:

puts( ) fputs( )

Syntax: puts(string).
fputs (string, stream)
Parameters: string is a constant string or a character array (null-terminated).

An 'int' is not a string. It won't work.

What else does the manual say in the puts() section ? It gives you a clue:
Quote:
In general printf() is more useful than puts().

If you want to display the value of an 'int', look at printf().

You have a few other bugs. It looks like your array sizes are too small.
They're too small for get_string(). Other arrays are set at 22 but that
doesn't include room for the final 0x00 byte that is part of every string.

Basically, you need to read the manual and read about what a string is.
Ttelmah



Joined: 11 Mar 2010
Posts: 20061

View user's profile Send private message

PostPosted: Wed May 18, 2016 1:19 am     Reply with quote

As a comment, do you _need_ the external oscillator.

The 25/4550, has an internal oscillator that is good enough for most things. The thing it is not good enough for, is the USB. This is why you can (for instance) use an external oscillator to drive the USB, and the internal oscillator for the code.

I assumed you wanted USB, since you were enabling the USB Vreg (pointless, and wastes power, unless you are using USB), and (of course) had selected a USB chip (wastes pins unless you want USB...).
lozi_dani



Joined: 22 Jan 2016
Posts: 40

View user's profile Send private message

PostPosted: Wed May 18, 2016 1:27 am     Reply with quote

Ok you're right with that, I didn't take care about what exactly puts() can print. I will be more careful the next time sorry.

But what about the value that strcmp() function returns? I've read in some threads that people use strcmp() to compare two strings. I am looking in the manual what says about this function and I read this:
Code:

cresult=strcmp (s1, s2) Compare s1 to s2


and also this:
Code:

strcmp(s1,s2) will give the same result as strcoll(s1,s2)

iresult=strcoll(s1,s2) Compares s1 to s2, both interpreted as appropriate to the current locale


What I am not able to see is what type of value returns this functions because i don't know what type are cresult and iresult variables.

I suppose that these functions don't return a int value, because I am not getting the expected result.

I am reading in some threads that strcmp returns 0 when both strings are equal, and a different value when they are different, so I understand with this that strcmp() returns an integer.

If it is true, why in my if statements, when I put if(strcmp == 1), the code goes in? I mean, I am sending through the Hyperterminal the string http://192.168.1.6/P11, and I am comparing that string that the PIC is receiving with the string auto_man, which have the same string.

It is because what you are telling about the length of the array?

I remember that in one of my attempts I gave to the array a length of 6, when I wanted to compare two arrays of 5 characters because of that last byte, and the result was not as expected, and when I changed that length of the array to 5, everything worked fine. Maybe there are other problems in the code which could be the reason I had that result.

Now I am at work but when I arrive at home I will try again and I will post the results.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
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