TX_test program in PIC C

Status
Not open for further replies.

flemmard

New Member
hi all,
The code below is not working...Can anyone advice on this.I'm using PIC16f877.

Code:
#include <pic1687x.h>
#include <pic.h>

// Transmitter test program


void main() {
    TRISC = 0x00 ; //portC as output
	SPBRG = 129;	// Set the baud rate to 9.6k
	BRGH = 1;		// Set high baud rate 
	SYNC = 0;		// Set asynchronous 
	SPEN = 1;		// Enable serial port pins 
	SREN=0;	         
	TX9 = 0;		// Disable 9 bit transmission 
	TXIE = 0;		// Disable tx interrupts 
	RCIE = 0;		// Disable rx interrupts 
	TXEN  = 0;      //reset the transmitter
	TXEN = 1;		// Enable the transmitter

	while(1) {
	    TXEN  = 1;
		while(!TXIF) {	// Checks if the transmit flag is down 
			continue;
		}
		TXREG = 0b01010101;
	}
}

Thanks
 
TX and RX have to be set to input for the UART to work. You should also write to TXREG and then wait for TXIF to be set.

Mike.
 
Pommie said:
TX and RX have to be set to input for the UART to work. You should also write to TXREG and then wait for TXIF to be set.

Mike.

Hi, thanks for your reply ! Can you please send me your code if you have some sample?
 
I only use asm on 16F pics but I would guess it would be something like,

Code:
#include <pic1687x.h>
#include <pic.h>

// Transmitter test program


void main() {
	TRISC = 0xc0 ; //portC as output
	SPBRG = 129;	// Set the baud rate to 9.6k
	BRGH = 1;		// Set high baud rate 
	SYNC = 0;		// Set asynchronous 
	SPEN = 1;		// Enable serial port pins 
	SREN=0;	         
	TX9 = 0;		// Disable 9 bit transmission 
	TXIE = 0;		// Disable tx interrupts 
	RCIE = 0;		// Disable rx interrupts 
	TXEN  = 0;      //reset the transmitter
	TXEN = 1;		// Enable the transmitter

	while(1) {
		TXEN  = 1;
		TXREG = 0b01010101;
		while(!TXIF); 	// Checks if the transmit flag is down 
	}
}

Mike.
 
I am compiling a Problem-Issue Verses Effort-Issue report.

I will incorportate this example as an Effort-Issue.
 


Hi , can you send me your asm code to to test my tx ?
I understand that i can add that asm code directly to my C for compilation
Thanks in advance
 
flemmard said:
Hi , can you send me your asm code to to test my tx ?
I understand that i can add that asm code directly to my C for compilation
Thanks in advance

You can check my RS232 PIC tutorial for assembler code.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…