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.

UART problem

Status
Not open for further replies.

ddonn

New Member
I am using a PIC18f4520 and i am trying to use the uart tool on the pickit2 to receive from PIC and print 'Hey' to screen. I am using 9600baud and need to know what delay i need to use in my code and how to use it. This is the code i am using and i am getting nothing on the screen.


#include "p18f4520.h"
#include <usart.h>
#include <delays.h>

#pragma config OSC = INTIO67 // Sets the oscillator mode to HS
#pragma config WDT = OFF // Turns the watchdog timer off
#pragma config MCLRE = OFF // Turns low voltage programming off

void main()
{
long i;
// clock frequency = 8MHz
OSCCONbits.IRCF2 = 1;
OSCCONbits.IRCF1 = 1;
OSCCONbits.IRCF0 = 1;

TRISC = 0x00;

OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 209);

while(1)
{

TRISD=0x00;
LATDbits.LATD1=1;
for (i=0;i<10000;i++);
//Delay1KTCYx(250);
putrsUSART( "Hey" );
LATDbits.LATD1=0;
for (i=0;i<10000;i++);
//Delay1KTCYx(250);
LATDbits.LATD1=1;
//Delay10KTCYx(2000);
}
Any help would be much appreciated.
 
there is a PDF which states all the info you need:

Hardware USART: (Page 70)
"C:\MCC18\doc\MPLAB-C18-Libraries_51297f.pdf"

Sodtware USART:
"C:\MCC18\doc\hlpC18Lib"

For software USART goto Software Peripheral Library then Software UART Functions then click the top arrow pointing to the right 1 time. And you will have delay info...


DelayTXBitUART Delay for:
((((2*Fosc) / (4*baud)) + 1) / 2) - 12 cycles

DelayRXHalfBitUART Delay for:
((((2*Fosc) / (8*baud)) + 1) / 2) - 9 cycles

DelayRXBitUART Delay for:
((((2*Fosc) / (4*baud)) + 1) / 2) - 14 cycles
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top