filtering received messages via rs232

Discussion in 'Embedded Systems and Microcontrollers' started by turku_as, May 6, 2012.

  1. turku_as

    Thread Starter New Member

    May 6, 2012
    3
    0
    hi,

    i am working on a mcu circuit that can communicate another device, and it receives so many message lines. My mcu doesnt have enough ram to store all message lines. So, i tried the code below with my pic18f4550 and 48 mhz clock to filter the message lines and pick the required values from the streaming message.

    Code ( (Unknown Language)):
    1.  
    2. static char message[25];
    3. static char value_required[25]
    4. staric char *ptr;
    5. static int1 value_get = FALSE;
    6.  
    7. char filter[] = "filter_value";
    8.  
    9. void main (void)
    10. {
    11.  
    12. puts("some_command");
    13.  
    14. while(value_get == FALSE)
    15. {
    16. gets(message);
    17. ptr = strstr(message,filter);
    18. if(ptr != NULL)
    19. {
    20. strcpy(value_required,message);
    21. value_get = TRUE;
    22. lcd_putc(value_required);
    23. }
    24. }
    25. }
    26.  
    when i try to run this code , nothing happens. i know it gets values but never filters and sends to lcd.

    i am a little concerned about the clock rate, 48 mhz is enough to run string functions while getting characters at 9600 baud ? or i am using the wrong function?
    Code ( (Unknown Language)):
    1. [CODE=rich][CODE=rich][CODE=rich][CODE=rich][/CODE][/CODE][/CODE][/CODE]
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,361
    You have to post your real code. There are two many things that get altered in the translation.
     
  3. turku_as

    Thread Starter New Member

    May 6, 2012
    3
    0
    here is my code, and i am using 20mhz xtal.

    Code ( (Unknown Language)):
    1.  
    2. #include <18f2550.h>
    3. #include <string.h>
    4.  
    5.  
    6. #fuses HSPLL, NOWDT, PLL5, CPUDIV1, USBDIV, NOXINST
    7. #use delay (clock=48000000)
    8. #use rs232(baud=300,parity=E,xmit=PIN_C6,rcv=PIN_C7,bits=7,STOP=1)
    9.  
    10. #include "lcd.c"
    11.  
    12. #ifndef FASTER_BUT_MORE_ROM
    13. #define FASTER_BUT_MORE_ROM
    14.  
    15. #ifndef INTERNAL_EEPROM_UTILITIES
    16. #define INTERNAL_EEPROM_UTILITIES
    17.  
    18. #ifndef INT_EEPROM_ADDRESS
    19. #define INT_EEPROM_ADDRESS  int8
    20. #endif
    21.  
    22. static char message[25];
    23. static char value_required[25]
    24. staric char *ptr;
    25. static int1 value_get = FALSE;
    26.  
    27. char filter[] = "filter_value";
    28.  
    29. void main (void)
    30. {
    31.  
    32. puts("some_command");
    33.  
    34. while(value_get == FALSE)
    35. {
    36. gets(message);
    37. ptr = strstr(message,filter);
    38. if(ptr != NULL)
    39. {
    40. strcpy(value_required,message);
    41. value_get = TRUE;
    42. lcd_putc(value_required);
    43. }
    44. }
    45. }
    46.  
    47.  
     
  4. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,361
    Did you attempt to run this code? There are spelling errors.
     
  5. turku_as

    Thread Starter New Member

    May 6, 2012
    3
    0
    no, i didnt run this code, i didnt write my original code because it contains a lot of variables and other functions which are not related to my problem.

    also it is too large to read, and those functions dont effect my pic to work correctly. my problem is to read lines and pick the line containing the value i want to store to eeprom;

    so, do you know how i can read the lines correctly and pick the specific one?

    and also my original code can be compiled properly and no problem occours, so you can ignore the syntax errors.
     
  6. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,361
    Ok, the best way to debug code is to compile and run it.
    It is not the same to analyze a hypothetical situation.
    If you are attempting to debug a single feature of a much larger system, create an abridged project that focuses on the single issue. It would be futile to help you otherwise.
     
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    It would also help if you gave us some information on the protocol used. If you keep secrets about your project. It will be very hard to help you
     
Loading...