HOME

CONTENTS

Search

MY SMART HOME PROJECT

Embedded Projects HOME

PIC Serial Communication Tutorial (UART) 9:06 PM

Vishal Kottarathil

4 comments +2 Recommend this on Google

First, a quick history of RS232. What is RS232? It's just a name for a standard that has propagated from generation to generation of computers. The first computers had serial ports that used RS232, and even current computers have serial ports (or at least USB ports that act like RS232 ports). Back in the day, serial information needed to be passed from devices like printers, joysticks, scanners, etc to the computer. The simplest way to do this was to pass a series of 1s and 0s to the computer. Both the computer and the device agreed on a speed of information - 'bits per second'. A computer would pass image data to a printer at 9600 bits per second and the printer would listen for this stream of 1s and 0s expecting a new bit every 1/9600 = 104us (104 micro-seconds, 0.000104 seconds). As long as the computer output bits at the pre-determined speed, the printer could listen. Zoom forward to today. Electronics have changed a bit. Before they were relatively high power, high voltage devices. The standard that is 'RS232' dictates that a bit ranges from -12V to +12V. Modern electronics do not operate at such high positive and negative voltages. In fact, our PIC runs 0V to 5V. So how do we get our 5V micro to talk the RS232 +/-12V voltages? This problem has been solved by the IC manufacturers of the world. They have made an IC that is generically known as the MAX232 (very close to RS232, no?). The MAX232 is an IC originally designed by a company called Maxim IC that converts the +/-12V signals of RS232 down to the 0/5V signals that our PIC can understand. It also boosts the voltage of our PIC to the needed +/-12V of the RS232 protocol so that a computer can understand our PIC and vice versa. To get our PIC IC sending serial characters to a computer, we have to send these serial signals through a MAX232 circuit so that the computer receives +/12V RS232 signals. Don't worry if you're working with a chip labeled 'ICL232' or 'ST232' - these are just generics of the MAX232. Everyone says 'MAX232'. The ICs all function the same and nearly all have the same pinout.

Discussion Group

TOTAL PAGEVIEWS

278128 RECENT POSTS

My Smart Home Project ABSTRACT Smart home technology h collective term for information and com

STM32F4 Discovery Tutorial 1 Using NETMF - S Normal 0 false false false EN-IN

STM32F4 DISCOVERY BOARD The STM32F4DISCOVERY helps you easily. It includes everything required

FIND US Find us on Facebook

Embedded Projects Like

Embedded Projects Pointers are...

Circuit

converted by Web2PDFConvert.com

4,671 people like Embedded Projects.

F acebook social plugin

FOLLOW BY EMAIL Submit

Email address...

POPULAR POSTS PIC Serial Communication Tutorial (UART) First, a quick history of RS232. What is RS232? It's just a name for a standard that has propagated from generation to generation o... PIC Microcontroller Based Electronic Lock Circuit Diagram Security is a prime concern in our day-today life. Everyone wants to be as much secure as possible. An ac...

UART Library The UART hardware module is available with a number of PIC compliant MCUs. The mikroC PRO for PIC UART Library provides comfortable work with the Asynchronous (full duplex) mode. You can easily communicate with other devices via RS-232 protocol (for example with PC, see the figure at the end of the topic – RS-232 HW connection). You need a PIC MCU with hardware integrated UART, for example 16F887. Then, simply use the functions listed below. Important :

STM32F4 Discovery Tutorial 1 Using NETMF - Setting Up the Environment STM32F4 STM32F4 Discovery I received my STM32F4 Discovery board few days ago. During these days I am searchi... PIC Countdown Timer (0-99) This project describes how to program PIC16F628A to function as a 00-99 min programmable timer. User can set any time betwe...

UART library routines require you to specify the module you want to use. To select the desired UART module, simply change the letter x in the routine prototype for a number from 1 to 2. Switching between the UART modules in the UART library is done by the UART_Set_Active function (UART modules have to be previously initialized). Number of UART modules per MCU differs from chip to chip. Please, read the appropriate datasheet before utilizing this library. Library Routines UARTx_Init UARTx_Data_Ready UARTx_Tx_Idle UARTx_Read UARTx_Read_Text UARTx_Write UARTx_Write_Text UART_Set_Active Generic Routines UART_Data_Ready UART_Tx_Idle UART_Read UART_Read_Text UART_Write UART_Write_Text

Projects Topic List Projects Topic List With Links Discussion Group Updated on 11/11/2012 From Cornell University ECE 4760 Design...

CATEGORIES .NET (2) 16x2 Character LCD (9) 2 UART (1) 4x3 Keypad (1) 4x4 keypad (1) 8051 (6) 8051 Project (3) 8051 Tutorial (3) 89C51 (4) 89C51 Project (2) 89S51 (1) converted by Web2PDFConvert.com

UARTx_Init Prototype void UARTx_Init(const unsigned long baud_rate); Returns Nothing. Description Initializes desired hardware UART module with the desired baud rate. Refer to the device data sheet for baud rates allowed for specific Fosc. If you specify the unsupported baud rate, compiler will report an error. Requires You need PIC MCU with hardware UART. UARTx_Init needs to be called before using other functions from UART Library. Parameters : baud_rate: requested baud rate

Refer to the device data sheet for baud rates allowed for specific Fosc. Note : Calculation of the UART baud rate value is carried out by the compiler, as it would produce a relatively large code if performed on the library level. Therefore, compiler needs to know the value of the parameter in the compile time. That is why this parameter needs to be a constant, and not a variable. Example // Initialize hardware UART1 and establish communication at 9600 bps UART1_Init(9600);

UARTx_Data_Ready Prototype char UARTx_Data_Ready(); Returns 1 if data is ready for reading 0 if there is no data in the receive register Description Use the function to test if data in receive buffer is ready for reading. Requires UART HW module must be initialized and communication established before using this function. See UARTx_Init. Example // If data is ready, read it: if (UART1_Data_Ready() == 1) { receive = UART1_Read(); }

UARTx_Tx_Idle Prototype char UARTx_Tx_Idle(); Returns 1 if the data has been transmitted 0 otherwise

89S52 (1) Additional UART (1) ARM (1) Atiny (1) Atmega8 (1) AVR (5) Avr Project (1) C# (1) C# Serial Port (2) C# serial Terminal (1) C# Voltmeter (1) Clock (1) Contents Page (1) Digital Voltmeter (3) EEPROM (2) Electronic code lock (1) Embedded (18) Embedded Project (11) Embedded Tutorial (13) Embeded (5) Extra UART (1) Home Security (1) Internet Based Device Control (1) Keypad (1) Keypad Tutorial (1) LCD (6)

Description Use the function to test if the transmit shift register is empty or not. Requires UART HW module must be initialized and communication established before using this function. See UARTx_Init. Example // If the previous data has been shifted out, send next data: if (UART1_Tx_Idle() == 1) { UART1_Write(_data); }

UARTx_Read Prototype char UARTx_Read(); Returns Returns the received byte. Description Function receives a byte via UART. Use the function UARTx_Data_Ready to test if data is ready first. Requires UART HW module must be initialized and communication established before using this function. See UARTx_Init. Example // If data is ready, read it: if (UART1_Data_Ready() == 1) { receive = UART1_Read(); }

UARTx_Read_Text Prototype void UARTx_Read_Text(char *Output, char *Delimiter, char Attempts); Returns Nothing. Description Reads characters received via UART until the delimiter sequence is detected. The read sequence is stored in the parameter output; delimiter sequence is stored in the parameter delimiter. This is a blocking call: the delimiter sequence is expected, otherwise the procedure

LCD Tutorial (4) Lock (1) LPG Sensor (1) MAX232 (3) Microcontroller (15) Microcontroller generates sound (1) Microcontroller Interrupt (1) Microcontroller Project (7) Microcontroller Tutorial (11) Microcontroller Tutorial. 8051 Tutorial (1) Mikoc 4 Bit LCD (3) MikroC (15) MikroC AVR (3) MikroC AVR Tutorial (3) MikroC EEPROM (2) MikroC for 8051 (4) MikroC PIC Tutorial (6) Mikroc tutorial (3) converted by Web2PDFConvert.com

Mikroc tutorial (3)

exits (if the delimiter is not found). Parameters :

Motor Control (1)

Output: received text Delimiter: sequence of characters that identifies the end of a received

NETMF (1) Password Lock (1)

string Attempts: defines number of received characters in which Delimiter sequence is expected. If Attempts is set to 255, this routine will continuously try to detect the Delimiter sequence.

PC Based Voltmeter (1) PIC (8) PIC Based Electronic Lock (1)

Requires UART HW module must be initialized and communication established before using this function. See UARTx_Init. Example Read text until the sequence “OK” is received, and send back what’s been received: UART1_Init(4800);

//

pic ADC (3) pic interrupt (1)

initialize UART1 module

PIC Music (1)

Delay_ms(100);

pic project (4)

while (1) { if (UART1_Data_Ready() == 1) {

PIC sound melody (1)

// if PIC Tutorial (3)

data is received UART1_Read_Text(output, "OK", 10);

// reads

PIC UART (1)

// sends

PIC Voltmeter (3)

text until 'OK' is found UART1_Write_Text(output);

back text

Project (10)

} }

Projects Topic (1)

UARTx_Write Prototype void UARTx_Write(char data_); Returns Nothing. Description The function transmits a byte via the UART module. Parameters :

Real Time Monitoring (2) RS 232 (1) Security System (1) Serial Communication (3)

_data: data to be sent

Smart home (1)

Requires UART HW module must be initialized and communication established before using this function. See UARTx_Init. Example unsigned char _data = 0x1E; ... UART1_Write(_data);

STM32 (3) STM32F4 (3) STM32F4 Discovery (3)

UARTx_Write_Text Prototype void UARTx_Write_Text(char * UART_text); Returns Nothing. Description Sends text via UART. Text should be zero terminated. Parameters :

STM32F4 Project (1) STM32F4 Tutorials (3) STMicroelectronics (1) Temperature Sensor (2)

UART_text: text to be sent

Requires UART HW module must be initialized and communication established before using this function. See UARTx_Init. Example Read text until the sequence “OK” is received, and send back what’s been received: UART1_Init(4800);

Smart Home Project (1)

//

initialize UART1 module

Timer (1) Tutorial (8) Uart (6) USB (1)

Delay_ms(100); USB to RS 232 (1)

while (1) { if (UART1_Data_Ready() == 1) {

// if

data is received UART1_Read_Text(output, "OK", 10);

VISUAL STUDIO (1)

// reads Water Level Control (1)

text until 'OK' is found UART1_Write_Text(output);

USB to UART (1)

// sends

back text }

BLOG ARCHIVE

}

UART_Set_Active Prototype void UART_Set_Active(char (*read_ptr)(), void (*write_ptr)(unsigned char data_), char (*ready_ptr)(), char (*tx_idle_ptr)()) Returns Nothing. Description Sets active UART module which will be used by the UART library routines. Parameters :

► 2013 (4) ▼ 2012 (25) ► November (2) ► October (2) ► August (1) converted by Web2PDFConvert.com

Parameters : ► June (3)

read_ptr: UARTx_Read handler write_ptr: UARTx_Write handler ready_ptr: UARTx_Data_Ready handler tx_idle_ptr: UARTx_Tx_Idle handler

► April (3) ▼ March (13) Projects Topic List

Requires Routine is available only for MCUs with two UART modules. Used UART module must be initialized before using this routine. See UARTx_Init routine // initialize Example UART1_Init(9600); UART1 module UART2_Init(9600); // initialize UART2 module RS485Master_Init();

AVR Serial Communication Tutorial (UART) PIC Serial Communication Tutorial (UART) Electronic Voting Machine Using 8051 Microcontroll... 89C51 Based Digital Thermometer Using DS1820

// initialize

MCU as Master

PIC 4 Bit LCD Interfacing Tutorial

UART_Set_Active(&UART1_Read, &UART1_Write, &UART1_Data_Ready, &UART1_Tx_Idle); // set UART1

PIC 16F887 Based Digital Thermometer

active RS485Master_Send(dat,1,160);

// send message

through UART1

AVR 4 Bit LCD Interfacing Tutorial Character LCD Basics AVR EEPROM Tutorial

UART_Set_Active(&UART2_Read, &UART2_Write, &UART2_Data_Ready, &UART2_Tx_Idle); // set UART2

PIC Countdown Timer (0-99)

active

PIC Microcontroller Based Electronic Lock

RS485Master_Send(dat,1,160);

// send through

UART2 UART_Data_Ready Prototype char UART_Data_Ready(); Returns 1 if data is ready for reading 0 if there is no data in the receive register Description Use the function to test if data in receive buffer is ready for reading. This is a generic routine which uses the active UART module previously activated by the UART_Set_Active routine. Requires UART HW module must be initialized and communication established before using this function. See UARTx_Init. Example // If data is ready, read it: if (UART_Data_Ready() == 1) { receive = UART_Read(); }

LCD based digital alarm clock using 89S51 microcon... ► February (1)

ABOUT ME V I S H A L K O T T A R A T H I L V I E W

M Y

C O M P L

Embedded Projects. Powered by Blogger.

SIGN IN

UART_Tx_Idle Prototype char UART_Tx_Idle(); Returns 1 if the data has been transmitted 0 otherwise Description Use the function to test if the transmit shift register is empty or not. This is a generic routine which uses the active UART module previously activated by the UART_Set_Active routine. Requires UART HW module must be initialized and communication established before using this function. See UARTx_Init. Example // If the previous data has been shifted out, send next data:

FOLLOWERS

if (UART_Tx_Idle() == 1) { UART_Write(_data); }

UART_Read Prototype char UART_Read(); Returns Returns the received byte. Description Function receives a byte via UART. Use the function UART_Data_Ready to test if data is ready first. This is a generic routine which uses the active UART module previously activated by the UART_Set_Active routine. Requires UART HW module must be initialized and communication established before using this function. See UARTx_Init. converted by Web2PDFConvert.com

Example // If data is ready, read it: if (UART_Data_Ready() == 1) { receive = UART_Read(); }

LABELS Contents Page (1)

UART_Read_Text Prototype void UART_Read_Text(char *Output, char *Delimiter, char Attempts); Returns Nothing. Description Reads characters received via UART until the delimiter sequence is detected. The read sequence is stored in the parameter output; delimiter sequence is stored in the parameter delimiter. This is a blocking call: the delimiter sequence is expected, otherwise the procedure exits (if the delimiter is not found). This is a generic routine which uses the active UART module previously activated by the UART_Set_Active routine. Parameters : Output: received text Delimiter: sequence of characters that identifies the end of a received

string Attempts: defines number of received characters in which Delimiter sequence is expected. If Attempts is set to 255, this routine will continuously try to detect the Delimiter sequence.

Requires UART HW module must be initialized and communication established before using this function. See UARTx_Init. Example Read text until the sequence “OK” is received, and send back what’s been received: UART1_Init(4800);

//

initialize UART1 module Delay_ms(100); while (1) { if (UART_Data_Ready() == 1) {

// if data

is received UART_Read_Text(output, "OK", 10);

// reads

text until 'OK' is found UART_Write_Text(output);

// sends

back text } }

UART_Write Prototype void UART_Write(char data_); Returns Nothing. Description The function transmits a byte via the UART module. This is a generic routine which uses the active UART module previously activated by the UART_Set_Active routine. Parameters : _data: data to be sent

Requires UART HW module must be initialized and communication established before using this function. See UARTx_Init. Example unsigned char _data = 0x1E; ... UART_Write(_data);

UART_Write_Text Prototype void UART_Write_Text(char * UART_text); Returns Nothing. Description Sends text via UART. Text should be zero terminated. This is a generic routine which uses the active UART module previously activated by the UART_Set_Active routine. Parameters : UART_text: text to be sent

Requires UART HW module must be initialized and communication established before using this function. See UARTx_Init. Example Read text until the sequence “OK” is received, and send back what’s been received: UART1_Init(4800);

// converted by Web2PDFConvert.com

initialize UART1 module Delay_ms(100); while (1) { if (UART_Data_Ready() == 1) {

// if data

is received UART_Read_Text(output, "OK", 10);

// reads

text until 'OK' is found UART_Write_Text(output);

// sends

back text } }

This program demonstrates a simple data exchange via UART. When PIC MCU receives data, it immediately sends it back. If PIC is connected to the PC (see the figure below), you can test the example from the mikroC PRO for PIC terminal for RS-232 communication, menu choice Tools › Terminal. Serial Terminal- Download

Code char uart_rd; void main() { ANSEL = 0;

// Configure AN pins as

digital ANSELH = 0; UART1_Init(9600);

// Initialize UART module

at 9600 bps Delay_ms(100);

// Wait for UART module to

stabilize UART1_Write_Text("Start"); UART1_Write(10); UART1_Write(13); while (1) { if (UART1_Data_Ready()) { uart_rd = UART1_Read(); UART1_Write(uart_rd); } }

// // // //

Endless loop If data is received, read the received data, and send data via UART

}

Serial Terminal- Download

converted by Web2PDFConvert.com

See Also

An Extra UART For Your PIC PC Based Digital Voltmeter Using PIC 16F877A

Posted in: C# Serial Port,C# serial Terminal,Embedded,Embedded Tutorial,Microcontroller,Microcontroller Tutorial,MikroC,MikroC PIC Tutorial,PIC,PIC Tutorial,Tutorial,Uart

Newer Post

Home

Older Post

4 comments: pcbpinoy said... Serial communication has been using the RS232 for the UART examples/tutorials. How ever, computers at this present age no longer use/include RS232 ports. USB is used instead and it can be used for serial communication thru the COM port. W hat are the changes on the examples above to effectively do serial communication w ith PIC and your pc? March 29, 2012 at 7:34 AM

Vishal K M said... For USB to 232 converters no need of any modification March 30, 2012 at 3:37 AM

Pistia Stratiotes said...

converted by Web2PDFConvert.com

W hat if I am using transceiver, is the code is still the same? September 10, 2012 at 11:46 PM

Vishal Kottarathil said... W hat type of transceiver you mean? If you mean RF transceiver you can use same code at a low baud rate. September 11, 2012 at 5:17 AM

Post a Comment Enter your comment...

Comment as: Publish

Select profile... Preview

Copyright © 2011 Embedded Projects | Powered by Blogger Embedded Projects Blog Tutorials | Projects - |

converted by Web2PDFConvert.com

PIC Serial Communication Tutorial (UART ... -

Mar 29, 2012 - PIC Countdown Timer (0-99) ... a 00-99 min programmable timer. ... would produce a relatively large code if performed on the library level.

504KB Sizes 8 Downloads 221 Views

Recommend Documents

PIC Serial Communication Tutorial (UART ... -
Mar 29, 2012 - Find us on Facebook. Embedded Projects. Like ... Facebook social plugin. Email address. .... Projects Topic (1). Real Time Monitoring (2).

uart serial communication pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. uart serial ...

Communication : App Inventor UART
Control arduino LED 13 with an android application+ display an ... 1: Develop an Android application with App Inventor 2. 2: Develop an Arduino ... Page 10 ...

pic microcontroller 16f877a tutorial pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. pic microcontroller 16f877a tutorial pdf. pic microcontroller 16f877a tutorial pdf. Open. Extract. Open with

pic microcontroller 16f877a tutorial pdf
pic microcontroller 16f877a tutorial pdf. pic microcontroller 16f877a tutorial pdf. Open. Extract. Open with. Sign In. Main menu. Displaying pic microcontroller ...

serial communication protocols pdf
Page 1 of 1. File: Serial communication protocols pdf. Download now. Click here if your download doesn't start automatically. Page 1 of 1. serial communication protocols pdf. serial communication protocols pdf. Open. Extract. Open with. Sign In. Main

PrimeCell UART (PL011) - ARM Infocenter
Where the term ARM is used it means “ARM or any of its subsidiaries as appropriate”. Confidentiality ... Change to signal names in Fig 2-1, changes to bits in Figs 4-1, 4-3. 9 February 2001. C ..... 2-21. Table 3-1. UART register summary . ......

PrimeCell UART (PL011) - ARM Infocenter
Where the term ARM is used it means “ARM or any of its subsidiaries as ...... Compliance to the AMBA Specification (Rev 2.0) onwards for easy integration.

UNIT-6-2016-SERIAL COMMUNICATION-2016.pdf
Try one of the apps below to open or edit this item. UNIT-6-2016-SERIAL COMMUNICATION-2016.pdf. UNIT-6-2016-SERIAL COMMUNICATION-2016.pdf.

pxa255-13(UART)[1].pdf
UART 訊框包括起始位元、資料位元、同位檢查位元、停止位元。UART 晶片的. 演進下: 1. 8250/8250A/8250B:應用於 PC/XT. 2. 16450:應用於 PC/AT。傳輸速度 38.4 ...

Cheap Usb Serial Drivers Cable Ftdi Usb Rs232 Rj45 Serial ...
Cheap Usb Serial Drivers Cable Ftdi Usb Rs232 Rj45 S ... co Router Switch Free Shipping & Wholesale Price.pdf. Cheap Usb Serial Drivers Cable Ftdi Usb ...

PIC book
Files created as a result of program translation. Macros. CHAPTER .... becomes very popular, so it was installed into computers such as: KIM-1, Apple I, Apple II,.

PIC book
PIC microcontrollers; low-cost computers-in-a-chip; allows ..... PIC16F84 perfectly fits many uses, from automotive industries and controlling home appliances to ...... MikroElektronika Internet presentation using options copy and paste.

PIC code .pdf
please support Adafruit and open-source hardware by purchasing. products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. MIT license, all ...

PIC code .pdf
system 1 second interval tick. int sys_time_seconds;. volatile float x, y, z;. //define. //init INT flags and ISR's. volatile int FF = 0;. volatile int FS = 0;. volatile int t=0;. void __ISR(_EXTERNAL_1_VECTOR, ipl2) C1Handler(void){. FS = 1;. INTCle

SERIAL 1_5_X.pdf
Page 1 of 20. 1781-1981. BETHEL. MAINE. SPECIAL. EDITION m. In Commemoration of the 200th Anniversary. of the Indian Raid on Sudbury Canada.

Twig-Serial Camera - GitHub
many times until reds FF D9 which indicates the end of the JPEG file. Command. Return. 0x56 0x00 0x32 0x0C 0x00 0x0A. 0x00 0x00 0xAH 0xAL. 0x00 0x00 ...

data communication and networking tutorial pdf
data communication and networking tutorial pdf. data communication and networking tutorial pdf. Open. Extract. Open with. Sign In. Main menu. Displaying data ...

Nice Pic Email.pdf
From: Russ Racop fmailto:russracopfaatt.net1. Sent: Tuesday, August 05, 2014 10:08 PM. To: Dan McDonald. Cc: [email protected]. Subject: Flyers. Flyers to be distributed this week. Russ Racop. 301 Alamo Drive. Little Rock, AR 72211. 501-3

report_DESIGN OF HD6402 UART IC FOR APPLICATION IN ...
report_DESIGN OF HD6402 UART IC FOR APPLICATION IN SERIAL COMMUNICATION.pdf. report_DESIGN OF HD6402 UART IC FOR APPLICATION IN SERIAL COMMUNICATION.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying report_DESIGN OF HD6402 UART IC FOR APP

Abigaile johnson pic
The greatst trinians train robbery. ... migrant workers unrealisticambitions but he does showhowconditions during the Great Depression ... Warfare history pdf.

SERIAL 1_2_2.pdf
in height and made a most imposing api>earance. After a season of merriment in which the past. and present seemed strangely mixed up, a bounti.