I have written a test program for serial communication (PIC16F877A) Everytime a button is pressed the data 'ABCDEFG' is to be sent to the computer.
But, I am recieving only 'ACEG'
Here is the Hi-Tech C code
So after fiddling through the datasheet, I felt, 'Maybe "while(!TXMT)" should work' , and it did.
So, whats the matter going here?
Code that works.
But, I am recieving only 'ACEG'
Here is the Hi-Tech C code
Code:
#include<htc.h>
__CONFIG(HS & LVPDIS & BORDIS & PWRTEN & WDTDIS);
#define _XTAL_FREQ 20000000
void main()
{
// Serial_dir=Out;
TRISC6=0;
TRISC7=1;
SYNC=0; // no synch
SPBRG=129; // 9600 baud at 20Mhz
BRGH=1; // high baud rate
SPEN=1; //enable the serial port
TX9=0; // no pairity bit
TXEN=1; // Start Transmission
CREN=1; //recieve data too
TXIE=0; // no intrpt
TRISB5=0;
RB5=1; // indicator LED. If it glows, PIC is working :)
TRISD1=1; // button is input
while(1)
{
if(RD1==1){
for(char i=0;i<=20;i++)__delay_ms(10);
while(!TXIF); //wait until previous transmit ends
TXREG = 'A';
while(!TXIF); //wait until previous tansmit ends
TXREG='B';
while(!TXIF); //wait until previous tansmit ends
TXREG='C';
while(!TXIF); //wait until previous tansmit ends
TXREG='D';
while(!TXIF); //wait until previous tansmit ends
TXREG='E';
while(!TXIF); //wait until previous tansmit ends
TXREG='F';
while(!TXIF); //wait until previous tansmit ends
TXREG='G';
}
}
}
So after fiddling through the datasheet, I felt, 'Maybe "while(!TXMT)" should work' , and it did.
So, whats the matter going here?
Code that works.
Code:
#include<htc.h>
__CONFIG(HS & LVPDIS & BORDIS & PWRTEN & WDTDIS);
#define _XTAL_FREQ 20000000
void main()
{
// Serial_dir=Out;
TRISC6=0;
TRISC7=1;
SYNC=0; // no synch
SPBRG=129; // 9600 baud at 20Mhz
BRGH=1; // high baud rate
SPEN=1; //enable the serial port
TX9=0; // no pairity bit
TXEN=1; // Start Transmission
CREN=1; //recieve data too
TXIE=0; // no intrpt
TRISB5=0;
RB5=1; // indicator LED. If it glows, PIC is working :)
TRISD1=1; // button is input
while(1)
{
if(RD1==1){
for(char i=0;i<=20;i++)__delay_ms(10);
while(!TRMT); //wait until previous transmit ends
TXREG = 'A';
while(!TRMT); //wait until previous tansmit ends
TXREG='B';
while(!TRMT); //wait until previous tansmit ends
TXREG='C';
while(!TRMT); //wait until previous tansmit ends
TXREG='D';
while(!TRMT); //wait until previous tansmit ends
TXREG='E';
while(!TRMT); //wait until previous tansmit ends
TXREG='F';
while(!TRMT); //wait until previous tansmit ends
TXREG='G';
}
}
}