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 Display Modes
Old 19th October 2008, 07:52 AM   #1 (permalink)
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, 36 views)

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

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


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



All times are GMT. The time now is 08:53 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker