Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help in programming a PIC micro to transfer data thru UART

Status
Not open for further replies.

kali1613

Newbie level 1
Joined
Jul 21, 2009
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
laguna
Activity points
1,287
pic uart

can any1 help me to program my PIC24 to transfer a designated value through uart... im quite a beginner on this so any help is appreciated.. thanks:D
 

transfer int with 8 bit uart

Like other microcontrollers you have to set all registers related to UART peripheral like baud, number of bits, stop bit, parity etc.
Sending data is simply loading data register and setting transmit bit. Datasheet can help a lot.
 

transfer data to pic

You don't say if you are using the PIC24F or PIC24H series or what language you are using, but here's some 'C' code to get you started. This code is for the PIC24F24FJ64GA002. You'll have to change the header file to match your processor.

Code:
#include <p24FJ64GA002.h>						// This is the header file for the uP you are using
		
#define OSC_FREQ 32000000 						// Frequency of the CPU Oscillator
#define Fcy  (OSC_FREQ/2)						// Peripheral Clock Frequency

// Initialize UART 1 to the baud_rate passed
void USARTInit(unsigned long baud_rate)
{		
	unsigned long temp, temp1;

	U1MODE = 0x0800;			// No Flow Control, Use TX & RX, 8 data bits, no parity, one stop bit, BRGH=0 - start with Uart Disabled
   temp = (unsigned long)Fcy >> 4L;
   temp1 = (temp / baud_rate); 
   U1BRG = (unsigned int)(temp1);		// Set BRG Register based on Baud Rate passed
	RPINR18bits.U1RXR=8;		// Assign RX input to RPR8 (pin 17)
	RPOR4bits.RP9R=3;			// Assign TX output to RPR9 (pin 18)
	U1MODEbits.UARTEN=1;		// Enable Uart
	U1STAbits.UTXEN = 1;		// Enable Transmitter
}

// Send 1 character to UART 1
void USARTPut(unsigned char c)
{
    while(U1STAbits.UTXBF == 1); // Wait for room in the transmitter FIFO..
    U1TXREG = c;				 // then send the character	
}

// Send an array of characters to UART 1
void USARTPutArray(unsigned char *array, unsigned int number_bytes)
{
	while (number_bytes--)
		USARTPut(*(array++));
}

// Send a zero-terminated string to UART 1
void USARTPutString(char *string)
{
    unsigned char c;
    while( (c = *(string++)) )
        USARTPut(c);
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top