Problem with PIC16f877A coding!!! please help~ (URGENT)

Discussion in 'Embedded Systems and Microcontrollers' started by tech_student, Apr 16, 2010.

  1. tech_student

    Thread Starter New Member

    Apr 16, 2010
    4
    0
    hey everyone...

    i am currently working on a wireless pcg device. my problem now is that my PIC C language codes are not working when transmitting signal from my RF module...im very new in doing hardware project..please could anyone help me? its urgent! i appreciate any help...thank you!!!

    here are my codes:

    Code ( (Unknown Language)):
    1. #define Delay 50
    2.  
    3. #define BUFSIZE 10
    4.  
    5. #define LF 0x0A
    6.  
    7.  
    8. unsigned short Buffer[BUFSIZE];
    9.  
    10. unsigned short input;
    11.  
    12. unsigned short output;
    13.  
    14. unsigned int i = 0;
    15.  
    16.  
    17.  
    18. void main() {
    19.  
    20. USART_Init(9600);
    21.  
    22. ADCON1 = 0;
    23.  
    24. TRISA = 0xFF;
    25.  
    26. PORTB=0;
    27.  
    28. TRISB=0;
    29.  
    30. input = ADC_Read(0);
    31.  
    32. Buffer[i]=input;
    33.  
    34. do {
    35.  
    36. output= Buffer[i];
    37.  
    38. USART_Write(output);
    39.  
    40. delay_ms(Delay);
    41.  
    42. USART_Write(LF);
    43.  
    44. i++;
    45.  
    46. if (i==BUFSIZE)
    47.  
    48. {
    49.  
    50. i=0;
    51.  
    52. }
    53.  
    54. input = ADC_Read(0);
    55.  
    56. Buffer[i]=input;
    57.  
    58. delay_ms(Delay);
    59.  
    60. } while (1);
    61. }[/i][/i][/i]
     
    Last edited: Apr 16, 2010
  2. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    Now where is the rest of it??? If this is all you have then no wonder it doesn't work. And please use the code tags to post code to make it easier to read and follow, use the "GO ADVANCED" button when posting and select the # symbol in the toolbar....

    Code ( (Unknown Language)):
    1. #define Delay 50
    2.  
    3. #define BUFSIZE 10
    4.  
    5. #define LF 0x0A
    6.  
    7.  
    8. unsigned short Buffer[BUFSIZE];
    9.  
    10. unsigned short input;
    11.  
    12. unsigned short output;
    13.  
    14. unsigned int i = 0;
    15.  
    16.  
    17.  
    18. void main() {
    19.  
    20. USART_Init(9600);
    21.  
    22. ADCON1 = 0;
    23.  
    24. TRISA = 0xFF;
    25.  
    26. PORTB=0;
    27.  
    28. TRISB=0;
    29.  
    30. input = ADC_Read(0);
    31.  
    32. Buffer[i]=input;
    33.  
    34. do {
    35.  
    36. output= Buffer[i];
    37.  
    38. USART_Write(output);
    39.  
    40. delay_ms(Delay);
    41.  
    42. USART_Write(LF);
    43.  
    44. i++;
    45.  
    46. if (i==BUFSIZE)
    47.  
    48. {
    49.  
    50. i=0;
    51.  
    52. }
    53.  
    54. input = ADC_Read(0);
    55.  
    56. Buffer[i]=input;
    57.  
    58. delay_ms(Delay);
    59.  
    60. } while (1);
    61. }   [/i][/i][/i]


    and post the whole code including configuration bits and any other header or include file declarations...


    B. Morse
     
    tech_student likes this.
  3. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    OUCH, how soon do you need this done?

    Have you had any programming successes? Just to prove your compiler setup and PIC operation? Have you tried the "Light an LED" hello, world, to see if the compiler is talking to the programmer and the PIC?
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    As BMorse said. You must include much more in your coding like.
    1) I see no config bits setting!
    2) You must tell the C compiler which clock speed your PIC use
    A schematics is also always helpful
     
    tech_student likes this.
  5. tech_student

    Thread Starter New Member

    Apr 16, 2010
    4
    0
    hi guys...
    thanks for the reply, the problem im not that good in programming as well as PIC. im doing hardware and i have never done programming in my life. i tried reading about C coding but thats the best i came out with.

    simply i want to send my heart sound analog signal to rf transmitter. rf can only read serial signal. so i used USART in the coding as well as conversion of ADC.

    i uploaded the schematics already.
    please help me becoz im out of ideas :)

    im defining the task in the coding below
     
    • tx.jpg
      tx.jpg
      File size:
      236 KB
      Views:
      38
    • rx.jpg
      rx.jpg
      File size:
      195.9 KB
      Views:
      34
    Last edited: Apr 18, 2010
  6. tech_student

    Thread Starter New Member

    Apr 16, 2010
    4
    0
    the analog input is fed to pin 2 or pin 3......
    i uploaded the code in a text file. please help me. i've been working on it for a long time.
    Code ( (Unknown Language)):
    1. // TITLE: PIC16F877A code written in MikroC
    2.  
    3. //TOPIC: - Design and implementation of a wireless ECG
    4.  
    5. //time delay between samples
    6.  
    7. #define Delay 50
    8.  
    9. //buffer size to hold data
    10.  
    11. #define BUFSIZE 10
    12.  
    13. #define LF 0x0A
    14.  
    15. #define USART_Write
    16.  
    17. #define USART_Init
    18.  
    19. // Variable Definition
    20.  
    21. unsigned short Buffer[BUFSIZE];
    22.  
    23. unsigned short input;
    24.  
    25. unsigned short output;
    26.  
    27. unsigned int i = 0;
    28.  
    29. /****************************************************
    30. * Function: Read Data from Analog input
    31. * convert it into digital and Send it in RS232 Format
    32. * to Transmitter Rx Pin
    33. ****************************************************/
    34.  
    35. void main() {
    36.  
    37. USART_Init(9600); // Initalize USART (9600 baud rate, 1 stop bit, ...
    38.  
    39. // Select Vref and analog inputs, in order to use ADC_Read
    40.  
    41. ADCON1 = 0; // All porta pins as analog, VDD as Vref
    42.  
    43. TRISA = 0xFF; // PORTA is input
    44.  
    45. PORTB=0;
    46.  
    47. TRISB=0;
    48.  
    49. input = ADC_Read(0);
    50.  
    51. // Read the first Data element
    52.  
    53. Buffer[i]=input;
    54.  
    55. do {
    56.  
    57. // Read ADC results and send the upper byte via USART in RS232 Format
    58.  
    59. output= Buffer[i];
    60.  
    61. // Send the current Data
    62.  
    63. USART_Write(output);
    64.  
    65. delay_ms(Delay);
    66.  
    67. // Send terminater
    68.  
    69. USART_Write(LF);
    70.  
    71. // go to the next data element Read
    72.  
    73. i++;
    74.  
    75. // circular buffer
    76.  
    77. if (i==BUFSIZE)
    78.  
    79. {
    80.  
    81. i=0;
    82.  
    83. }
    84.  
    85. //Read next input
    86.  
    87. input = ADC_Read(0);
    88.  
    89. Buffer[i]=input;
    90.  
    91. delay_ms(Delay);
    92.  
    93. } while (1); // endless loop
    94. }[/i][/i][/i]


    thank you so much!!
     
    Last edited: Apr 18, 2010
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Then you program on a PC you do not need to know much about the inner workings in most cases. But then programming a micro controller it is imperative, to have some knowledge about the inner working. So once more you must set the configuration bits described in section 14.0 SPECIAL FEATURES OF THE CPU in the data sheet. Which I really hope you have downloaded. Your C compiler also need to know which speed your PIC is working on. In order to set things like delays and RS232 bitrate correctly. Please correct this before asking for more help.
    It will also help to break down your problem into smaller segments. As an example set up a simple test function to test the serial communication link. First then you are sure this work, and hence you have understood how it is function. You can move on to the AD converter. You will find a lot of valuable information in the data sheet. Even if you program in C the internal registers must have the correct configuration
     
  8. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
  9. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    One of them is probably the others professor, making sure they do there own work :)
     
  10. tech_student

    Thread Starter New Member

    Apr 16, 2010
    4
    0
    the codes worked perfectly. thanks guys. the problem was with the connection
     
  11. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    I can not see that we did so much. But I am glad you solved your problems:)
     
Loading...