Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

EUSART issues

Status
Not open for further replies.

richb

New Member
Hi Guys, i'm banging my head against a brick wall at the moment, if anyone can take a quick look over the code, it would be most appreciated.

I'm using the PIC18f4580 and trying to simply transmit rs232 to my computer via hyperterminal using the max233. When i compile the code on my 16f877a it works fine (ob altering the SPBRG setting), but on the 18f, i have no luck.

Here is my code:

Code:
#include <pic18f4580.h>

void putch(unsigned char c)
{
	while(!TXIF) continue;	// set when register is empty 
	TXREG = c;
}

void puts(const char *str)
{
	while(*str){
		putch(*str);
		str++;
	}
}

void rs232_init()			// Sets USART to 9600 Baud, 8-bit data

{

	SPBRG =	51;	
	BRGH =	1;
	BRG16	= 0;				//
	SYNC =	0;				// Asynch Operation
	SPEN =	1;				// Enable Serial Port
	CREN =	1;				// Enable Reception
	TXEN =	1; 				// Enable transmission & Set TXIF
	TX9  =	0;				// 8- or 9-bit transmission
	RX9  =	0;				// 8- or 9-bit reception
	RCIE =	1;
}

void main(void)

{
	IRCF2		= 1;
	IRCF1		= 1;
	IRCF0		= 1;

	/*disable comparator module*/

	CM0	= 1;
	CM1	= 1;
        CM2 = 1;

	/*Disable PSP (parallel slave port) */
	PSPMODE = 0;

	PCFG3	= 1;
	PCFG2	= 1;
	PCFG1	= 1;
	PCFG0	= 1;

	LATD	= 0xFF;
	LATE	= 0x00;

	TRISD 	= 0x00;
	TRISA	= 0xFF;
	TRISE	= 0x00;
	TRISC6	= 0;
	TRISC7	= 1;
	
	rs232_init();
	puts("move forward!!");
}

I am running the pic at 8mhz using the internal osc (i hope) although don't have any available scope to check this.

Any help would be greatly appreciated
Cheers
Richb
 
hi

had a look at the datasheet again,

TRISC<6> must be cleared (= 0) for
Asynchronous and Synchronous Master modes,
or set (= 1) for Synchronous Slave mode

from memory i believe i want to set the device as a master, although i could be wrong.

I did try setting it to 1, but no luck i'm afriad.
 
Oops.. What I've stated earlier is not applicable for your PIC :)
Try to wait IOFS to be set to make sure that the internal oscillator is stable in order to get UART to work properly. See whether it helps or not.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top