How to use USART in PIC16877A (using C: initializing, sample program)

Status
Not open for further replies.

andromeda30

Newbie level 5
Joined
Dec 9, 2010
Messages
8
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,339
How to start program for USART in PIC16877A (using C: initializing *sample program)

Hi friends..i really need help.

we are working with our thesis project and deals with ADC, pic16877a, and a sim900D gsm module

please give me ideas or sample program for this:

pic16877a will do ADC (accept analog voltage) and then the data will be transmitted to the computer (the computer is connected with a mobile phone, we are using the hyperterminal) through pic16's usart port then the usart port is connected to a gsm module sim900D.

how to program for example if we send 5 ( read in ADC as 5 volts) from the pic to the computer..

please..we badly need it.

anyways. we are using MPLab IDE in programming for C language.
 
Last edited:

It all depends on the C compiler you use. There are mcc18, hitech c and also ccs c and all the functions in the precompiled library is different
 

Code:
/*****************************************************************************/
/*                                                                     					*/
/*  FILE        :tr.c                              		       						*/
/*  DESCRIPTION : Uart transmit		                              		*/
/*  CPU GROUP   :16F877A                                                    		*/
/*****************************************************************************/

unsigned int sec,msec;
void send_message(unsigned char const *msg);
void main()
{
			ADCON1=0X06;
			TRISA=0X3F;
			TRISB=0XFF;
			TRISC=0XFF;
			TRISD=0xFF;
			TRISE=0X07;
		
			TXSTA=0x24;
			RCSTA=0x90;
			SPBRG=25;
			
			GIE=PEIE=TMR2IE=1;
			T2CON=0x07;
			TMR2=193;
			
			send_message("Hai kct");
			send_message("\r\n");
			
			while(1)
			{
				if(sec>10)
				{
				sec=0;	
				send_message("serial port checking");
				send_message("\r\n");
				}
			}
}
void send_message(unsigned char const *msg)
	{
		while(*msg!='\0')
		{
			TXREG=*msg;
			while(!TRMT);
			msg++;
		}
	}
void interrupt isr()
{
	if(TMR2IF)
	{	
		TMR2IF=0;
		TMR2=193;
		msec++;	
	}
	if(msec>999)
	{
		msec=0;
		sec++;
	}
	
}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…