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

Thread Starter

tech_student

Joined Apr 16, 2010
4
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:

Rich (BB code):
#define Delay 50

#define BUFSIZE 10

#define LF 0x0A


unsigned short Buffer[BUFSIZE];

unsigned short input;

unsigned short output;

unsigned int i = 0;



void main() {

USART_Init(9600); 

ADCON1 = 0; 

TRISA = 0xFF; 

PORTB=0;

TRISB=0;

input = ADC_Read(0);

Buffer=input;

do {

output= Buffer;

USART_Write(output);

delay_ms(Delay);

USART_Write(LF);

i++;

if (i==BUFSIZE)

{

i=0;

}

input = ADC_Read(0);

Buffer=input;

delay_ms(Delay);

} while (1); 
}
 
Last edited:

BMorse

Joined Sep 26, 2009
2,675
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....

Rich (BB code):
#define Delay 50

#define BUFSIZE 10

#define LF 0x0A


unsigned short Buffer[BUFSIZE];

unsigned short input;

unsigned short output;

unsigned int i = 0;



void main() {

USART_Init(9600); 

ADCON1 = 0; 

TRISA = 0xFF; 

PORTB=0;

TRISB=0;

input = ADC_Read(0);

Buffer=input;

do {

output= Buffer;

USART_Write(output);

delay_ms(Delay);

USART_Write(LF);

i++;

if (i==BUFSIZE)

{

i=0;

}

input = ADC_Read(0);

Buffer=input;

delay_ms(Delay);

} while (1); 
} 	


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


B. Morse
 

retched

Joined Dec 5, 2009
5,207
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?
 

t06afre

Joined May 11, 2009
5,934
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
 

Thread Starter

tech_student

Joined Apr 16, 2010
4
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
 

Attachments

Last edited:

Thread Starter

tech_student

Joined Apr 16, 2010
4
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.
Rich (BB code):
// TITLE: PIC16F877A code written in MikroC

//TOPIC: - Design and implementation of a wireless ECG

//time delay between samples

#define Delay 50

//buffer size to hold data

#define BUFSIZE 10

#define LF 0x0A

#define USART_Write

#define USART_Init

// Variable Definition

unsigned short Buffer[BUFSIZE];

unsigned short input;

unsigned short output;

unsigned int i = 0;

/****************************************************
* Function: Read Data from Analog input
* convert it into digital and Send it in RS232 Format
* to Transmitter Rx Pin
****************************************************/

void main() {

USART_Init(9600); // Initalize USART (9600 baud rate, 1 stop bit, ...

// Select Vref and analog inputs, in order to use ADC_Read

ADCON1 = 0; // All porta pins as analog, VDD as Vref

TRISA = 0xFF; // PORTA is input

PORTB=0;

TRISB=0;

input = ADC_Read(0);

// Read the first Data element

Buffer=input;

do {

// Read ADC results and send the upper byte via USART in RS232 Format

output= Buffer;

// Send the current Data

USART_Write(output);

delay_ms(Delay);

// Send terminater

USART_Write(LF);

// go to the next data element Read

i++;

// circular buffer

if (i==BUFSIZE)

{

i=0;

}

//Read next input

input = ADC_Read(0);

Buffer=input;

delay_ms(Delay);

} while (1); // endless loop
}


thank you so much!!
 

Attachments

Last edited:

t06afre

Joined May 11, 2009
5,934
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
 
Top