Sending Strings to pc by pic16f876A

Status
Not open for further replies.

Rajat Bhardwaj

Newbie level 1
Joined
Jul 2, 2013
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
14
Hi!... I was successful in sending numbers one by one serially to my PC through pic16f876A by using max232 IC by using the following code(using HI-Tech compiler):
#include<stdlib.h>
#include <htc.h>
#include<stdio.h>
#define _XTAL_FREQ 12000000
void putst(unsigned char x);
void putch (unsigned char tx);
void USART_Init(void);
void main()
{
int i;
PORTC = 0xff;
TRISC = 0x00;
USART_Init();
while(1)
{
putst(i+48);
}
}
}
void USART_Init(void)
{
TRISC6=1;
TRISC7=1;
SPBRG=77.125;
BRGH=1;
SYNC=0; //asynchronous
SPEN=1; //enable serial port
//pins
CREN=1; //enable reception
SREN=0; //no effect
TXIE=0; //disable tx interrupts
RCIE=0; //disable rx interrupts
TX9=0; //8-bit transmission
RX9=0; //8-bit reception
TXEN=0; //reset transmitter
TXEN=1; //enable the transmitter
PEIE=1;
RCIE=1;
GIE=1;
}


void putst(unsigned char x)
{
TXEN=0;
TXEN=1;
putch (x);
putch(10);
putch(13);
}

void putch (unsigned char tx)
{
while(!TXIF);
TXREG=tx;
__delay_ms(100);
}


Now I am having trouble in sending strings to my pc in the same way.What changes I will have to make in order to send strings serially instead of numbers?.Please help!!
 

Please post code between code tags to preserve it's formatting.

1. remove the entire putst function, it isn't needed.
2. no idea what SPBRG=77.125; is supposed to do, you can't have fractional parts in register values.
3. Treat each character in your string as a single character and pass it to your putch routine.

For example:

Code:
void SendString(char *Data)
{
	char TxPtr = 0;
	
	while(Data[TxPtr])
	{
		SendByte(Data[TxPtr++]);
	}
}

This assumes you are using standard 'C' strings which have a null terminator.

Brian.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…