Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 19th October 2008, 08:52 AM   #1
Default PIC 16F877 UART receive

Hi,

I'm doing a project where Serial comms is used for communication between a gsm modem to the PIC. Since I'm new to UART programming, I'm now working without the modem, just to test if I've got the UART part right first. Hyperterminal is used for the testing.

I've got the transmitting part (PIC to hyperterminal) working, but I can't get the receving part (hyperterminal to PIC) to work. Below is the relevant parts of my code:

The main gist of my main function is to send some commands if RC0==1. The function sendSMS (which has been checked to be working fine) transmits some commands to hyperterminal (which will be eventually replaced with a gsm modem). Else, if a key is pressed in hyperterminal, the char (key pressed) will be sent to the PIC and store in the memory location defined as "RECEIVE". To check if this process has been carried out correctly, transmitNum function (which has been checked to be working fine) is used to transmit the data stored in "RECEIVE".

The few commented out lines that transmits H, E, L, P or N was actually used for debugging. Without those lines, my program just hangs. Even the sendSMS function could not be carried out. But when transmit E, L or P is placed in the sub functions, the main programs runs and transmits H and N at the end. What am I doing wrong? I've attached my full code in the attachments.

Thanks in advance to all kind souls who reply to this!


#define RECEIVE 50

unsigned char receive_char()
{
while(!RCIF);
{ if (OERR==1)
{ CREN=0;
CREN=1; }
}
//transmit('E');

return RCREG;
}

void store_num(char add)
{
int i=0;
unsigned char temp;

while (i < 16)
{ temp = receive_char();
//transmit('L');
write2EE(add+i, temp);
//transmit('P');
if (temp == SPACE) break;
i++;
}
}

void main ()
{ initports();
initUSART();
initMem();

while(1)
{ if(RC0==1) sendSMS(HelpSMS);
store_num(RECEIVE);
transmit('H');
transmitNum(RECEIVE);
transmit(LF);
transmit('N');
}
};
Attached Files
File Type: c sms.c (5.8 KB, 67 views)

Last edited by yueying_53; 20th October 2008 at 08:14 AM.
yueying_53 is offline  
Reply

Tags
pic, receive, uart

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
How can I Transmit/ Receive BCD noman_dk Electronic Projects Design/Ideas/Reviews 3 23rd February 2008 05:59 PM
RF receive using PIC USART col_implant Electronic Projects Design/Ideas/Reviews 11 15th November 2007 05:06 PM
Receive data? Possible? ice-egoz Micro Controllers 0 5th August 2004 03:24 AM
receive data from other pic janetsmith2000@yahoo.com Micro Controllers 1 24th March 2004 07:28 PM
receive 0 data from UART..... wingbar General Electronics Chat 5 15th March 2004 07:11 PM



All times are GMT. The time now is 06:55 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker