Pic16f877A uart string comapare reg

Discussion in 'Embedded Systems and Microcontrollers' started by selvamurugan_t, Aug 8, 2016.

  1. selvamurugan_t

    Thread Starter New Member

    Aug 8, 2016
    17
    0
    Hi ,
    I have define array1[](predefined) and another array2[] received from hyperterminal to pic.

    Just I want to compare those arrays and if its succeeded I am sending string to lcd ok else error.
    But I am getting result as error.

    Code (C):
    1.  
    2. #include <pic.h>
    3. #include<string.h>
    4. #include "lcd_driver.c"
    5. #define _XTAL_FREQ 8000000
    6.  
    7. char UART_Init(const long int baudrate)
    8. {
    9. unsigned int x;
    10. x = (_XTAL_FREQ - baudrate*64)/(baudrate*64);
    11. if(x>255)
    12. {
    13. x = (_XTAL_FREQ - baudrate*16)/(baudrate*16);
    14. BRGH = 1;
    15. }
    16. if(x<256)
    17. {
    18. SPBRG = x;
    19. SYNC = 0;
    20. SPEN = 1;
    21. TRISC7 = 1;
    22. TRISC6 = 1;
    23. CREN = 1;
    24. TXEN = 1;
    25. return 1;
    26. }
    27. return 0;
    28. }
    29. char UART_TX_Empty()
    30. {
    31. return TRMT;
    32. }
    33. char UART_Data_Ready()
    34. {
    35. return RCIF;
    36. }
    37. char UART_Read()
    38. {
    39.  
    40. while(!RCIF);
    41. return RCREG;
    42. }
    43. void UART_Read_Text(char *Output, unsigned int length)
    44. {
    45. int i;
    46. for(int i=0;i<length;i++)
    47. Output[I] = UART_Read();
    48. }
    49. void UART_Write(char data)
    50. {
    51. while(!TRMT);
    52. TXREG = data;
    53. }
    54. void UART_Write_Text(char *text)
    55. {
    56. int i;
    57. for(i=0;text[I]!='\0';i++)
    58. UART_Write(text[I]);
    59. }
    60. //----------------------------------------main function------------------------------------------
    61. void main()
    62. {
    63. char i,array1[13] = {'1','2','3','4','5','6','7','8','9','1','2','1'},array2[13];
    64. //char i,array1[6] = "hello",array2[6];
    65. TRISB = 0x00;
    66.  
    67. setuplcd_port();
    68. lcd_init();
    69. lcd_send_string("welcome"); // Write text in first row
    70. UART_Init(9600);
    71. array1[12] = '\0';
    72. array2[12] = '\0';
    73. while(1)
    74. {
    75. if(UART_Data_Ready())
    76. {
    77. for(i=0;i<12;)
    78. {
    79. if(UART_Data_Ready())
    80. {
    81. array2[I] = UART_Read();
    82. i++;
    83. // lcd_command(0x01);
    84. // lcd_command(0x80);
    85. // lcd_send_string(array2);
    86. }
    87. }
    88.  
    89. for(i=0;i<12;i++)
    90. {
    91. if((array1[I]!=array2[I])&&(array1[I]!='\0'||array2[I]!='\0')&&(array1[I]!='\n'||array2[I]!='\n'))
    92. {
    93. lcd_command(0x01);
    94. lcd_command(0x80);
    95. lcd_send_string("error");
    96. }
    97. else
    98. {
    99. lcd_command(0x01);
    100. lcd_command(0x80);
    101. lcd_send_string("ok");
    102. }
    103. }
    104. }
    105. }
    106. }
    107.  
    Used code tags
     
    Last edited by a moderator: Aug 8, 2016
  2. dannyf

    Well-Known Member

    Sep 13, 2015
    1,769
    357
    That's an easy error.
     
  3. MrChips

    Moderator

    Oct 2, 2009
    12,418
    3,355
    You have to use the strcmp( ) function.
     
  4. selvamurugan_t

    Thread Starter New Member

    Aug 8, 2016
    17
    0
    The page loading on long time and May know where I did the mistake.
     
  5. selvamurugan_t

    Thread Starter New Member

    Aug 8, 2016
    17
    0


    if(strcmp(array1,array2)==0)
    {
    return 1;
    }
    else
    return 0;
    }


    /*
    for(i=0;i<=11;i++)
    {
    if(array1==array[2])
    flag=0;
    }
    if(flag=0)
    return 1;
    else
    return 0;

    */

    This time also I am getting error
     
    Last edited: Aug 8, 2016
  6. dannyf

    Well-Known Member

    Sep 13, 2015
    1,769
    357
    Don't worry about it. I have solved the error.
     
  7. selvamurugan_t

    Thread Starter New Member

    Aug 8, 2016
    17
    0
    In that above I cant find the solution for my problem ..could you resolve it and send the correct link to me
     
Loading...