Rajat Bhardwaj
Newbie level 1
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!!
#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!!