bar_
Newbie level 6
Dear All,
I'm trying to create a software UART for my 16f877a controller for interfacing serial bluetooth and gsm modem for a home automation purpose.
But i got stuck in the first step itself. First i tried FORCE_SW function on the CCS C complier but it is not working properly. i mean, the data displayed on the terminal is full of junk. the code is below
please anybody help me solving this problem. thanks in advance.
I'm trying to create a software UART for my 16f877a controller for interfacing serial bluetooth and gsm modem for a home automation purpose.
But i got stuck in the first step itself. First i tried FORCE_SW function on the CCS C complier but it is not working properly. i mean, the data displayed on the terminal is full of junk. the code is below
Code:
#include "16F877a.h"
#use delay(clock = 4000000)
#use rs232(baud = 9600, xmit = pin_c0, rcv = pin_c1, force_sw)
void main()
{
set_tris_c(0b10000010); // UART RX pin direction register
while(1)
{
printf("e\n\r");
delay_ms(100);
}
}
Then i tried to write my own code to just transmit the character "e" at a interval of 100ms continously but it is also not working. i mean not displaying any junk data also. below is the code
#include "16f877a.h"
#use delay(clock=40000000)
#define Baudrate 9600 //bps
#define one_bit_delay (1000000/Baudrate) //one bit delay
#define DataBitCount 8 // no parity, no flow control
#define set_rx_tx_direc set_tris_c(0b10000010) // UART RX pin direction register
#byte port_c = 0x07
#bit UART_RX = port_c.1
#bit UART_TX = port_c.0
void main()
{
set_rx_tx_direc;
UART_TX = 1;
delay_ms(3);
while(1)
{
UART_TX = 0; //start bit to transmit "e" whose ascii value = 0d101 or 0b01100101
delay_us(one_bit_delay);
UART_TX = 1; //0th bit
delay_us(one_bit_delay);
UART_TX = 0; //1st bit
delay_us(one_bit_delay);
UART_TX = 1; //2nd bit
delay_us(one_bit_delay);
UART_TX = 0; //3rd
delay_us(one_bit_delay);
UART_TX = 0; //4th
delay_us(one_bit_delay);
UART_TX = 1; //5th
delay_us(one_bit_delay);
UART_TX = 1; //6th
delay_us(one_bit_delay);
UART_TX = 0; //7th
delay_us(one_bit_delay);
UART_TX = 1; //stop bit
delay_us(one_bit_delay);
delay_ms(100); // delay_to_next_character
}
}
please anybody help me solving this problem. thanks in advance.