Pointer-Array Problems

Discussion in 'Embedded Systems and Microcontrollers' started by varden, Aug 2, 2016.

  1. varden

    Thread Starter New Member

    Jul 11, 2016
    Hi. I posted same problem a few days ago but still couldn't do it.I hope you can help. My problem is, I get data from bluetooth and can print it on 16x2 lcd. But I need to know lenght of coming data in order to complate my other project. Also if you know how I can write this data to SD card without knowing number of digits, it would be even better.(I use mikro C) This time I am posting whole code. I tried different things and this is final form.
    Code (Text):
    1. char gelen;
    2. char txt;
    3. unsigned short k=0;
    5. sbit LCD_RS at RB2_bit;
    6. sbit LCD_EN at RB3_bit;
    7. sbit LCD_D4 at RB4_bit;
    8. sbit LCD_D5 at RB5_bit;
    9. sbit LCD_D6 at RB0_bit;
    10. sbit LCD_D7 at RB1_bit;
    12. sbit LCD_RS_Direction at TRISB2_bit;
    13. sbit LCD_EN_Direction at TRISB3_bit;
    14. sbit LCD_D4_Direction at TRISB4_bit;
    15. sbit LCD_D5_Direction at TRISB5_bit;
    16. sbit LCD_D6_Direction at TRISB0_bit;
    17. sbit LCD_D7_Direction at TRISB1_bit;
    19. void main() {
    20. ADCON1 |= 0X0F;
    21. CMCON  |= 7;
    23. Lcd_Init();
    24. Lcd_Cmd(_LCD_CURSOR_OFF);
    25. Lcd_Cmd(_LCD_CLEAR);
    26. Lcd_Out(1, 1, "Bluetooth-hc05");
    27. delay_ms(2000);
    28. Lcd_Cmd(_LCD_CLEAR);
    29. UART1_Init(2400);
    30. Delay_ms(100);
    31. for( ; ;)
    32. {
    33. if (UART1_Data_Ready()) {
    34. gelen = UART1_Read();
    36.     while(gelen[k] != '\0'){
    37.      k++;
    39. }
    41. ShortToStr(k, txt);
    42. Lcd_Chr_Cp(txt);
    46. }
    47. }
    48. }
    It says at while line, "pointer required."
  2. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    You have gelen defined as a character, not a character array. You will have the same problem with txt, I believe.
  3. varden

    Thread Starter New Member

    Jul 11, 2016
    What it should be like? I tried as txt[16] and gelen[16] but outcome becomes meanless characters.
  4. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    For one thing, I think your for loop is not correct. As far as I can tell, your index k is never reset back to the beginning of the array.

    Aside from that, since I use neither your compiler or libraries, I cannot help you further. Someone else will likely pop in here shortly.
    varden likes this.
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    You are not reading the data properly. Assuming reading the data is all you need do...

    You need two loops: outer loop loops until a zero is received to indicate the entire string is received, assuming the BT sends a traditional zero terminated string. Once you get that zero you can process the character array as you wish. Within this loop you need a single line loop to wait for the next character to be received.

    Variable k gets reset at the top of the loop such when you exit the loop k now holds the character count.

    How long the arrays need be depends on what the BT sends, you need look that up.

    I don't use that compiler so see if they have an SD card library. Trust me, you do not want to write that code, you want a library.
    varden likes this.
  6. varden

    Thread Starter New Member

    Jul 11, 2016
    Oh thanks, you are right I forget about k doesn't reset. I will try to fix it.
    And I am still beginner I couldn't even dare to use SD card without library :D But library needs you to enter how many character you want to write. If I say something bigger it loops until fill it. So this is my main problem.

    Also my teacher told us mikro C is very populer compiler and that is why we chose it. But know I started to doubt about it :D