PIC 16F877 UART receive

Status
Not open for further replies.

yueying_53

New Member
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');
}
};
 

Attachments

  • sms.c
    5.8 KB · Views: 383
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…