Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Similar documents
ELCT 912: Advanced Embedded Systems

Chapter 10 Sections 1,2,9,10 Dr. Iyad Jafar

Embedded Systems Programming and Architectures

EET203 MICROCONTROLLER SYSTEMS DESIGN Serial Port Interfacing

Experiment 7:The USART

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Example of Asyncronous Serial Comms on a PIC16F877

Section 21. Addressable USART

Serial Communication with PIC16F877A

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

PIC Architecture & Assembly Language Programming. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Parallel IO. Serial IO. Parallel vs. Serial IO. simplex vs half-duplex vs full-duplex. Wires: Full Duplex. Wires: Simplex, Half-duplex.

APPLICATION NOTE 2361 Interfacing an SPI-Interface RTC with a PIC Microcontroller

Asynchronous Transmission. Asynchronous Serial Communications & UARTS

Arithmetic and Logic Instructions. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

ECE 354 Introduction to Lab 1. February 5 th, 2003

ELE492 Embedded System Design

Serial Communication

The University of Texas at Arlington Lecture 21_Review

Flow Charts and Assembler Programs

Outlines. PIC Programming in C and Assembly. Krerk Piromsopa, Ph.D. Department of Computer Engineering Chulalongkorn University

ECE 354 Computer Systems Lab II. Interrupts, Strings, and Busses

ECE 354 Introduction to Lab 2. February 23 rd, 2003

/* PROGRAM FOR BLINKING LEDs CONEECTED TO PORT-D */

Interrupts. ELEC 330 Digital Systems Engineering Dr. Ron Hayne. Images Courtesy of Ramesh Gaonkar and Delmar Learning

Kit Contents. Getting Started Kits. Board. Board

UNIVERSITY OF NAIROBI FACULTY OF ENGINEERING DEPARTMENT OF ELECTRICAL AND INFORMATION ENGINEERING

8051SERIAL PORT PROGRAMMING

Using the 8-Bit Parallel Slave Port

LPTCOM. Bruce Misner Lakehead University h d3 RD2 pin 21. RD3 pin h d4. RD4 pin 27 RD5 pin h d5. RD6 pin 29 RD7 pin H d6

ELCT706 MicroLab Session #4 UART Usage for Bluetooth connection PC - PIC

Binary Outputs and Timing

MCS-51 Serial Port A T 8 9 C 5 2 1

ECE Homework #3

University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory

ELCT706 MicroLab Session #4 UART Usage for Bluetooth connection PC - PIC

Embedded Systems. PIC16F84A Sample Programs. Eng. Anis Nazer First Semester

Embedded System Design

FULL DUPLEX BIDIRECTIONAL UART COMMUNICATION BETWEEN PIC MICROCONTROLLERS

The MICROPROCESSOR PRINCIPLES AND APPLICATIONS Lab 7

Super Awesome Multitasking Microcontroller Interface for Electromechanical Systems (S.A.M.M.I.E.S.) Pinball Table

When JP1 is cut, baud rate is Otherwise, baud rate is Factory default is that JP1 is shorted. (JP1 is jumper type in some model)

These 3 registers contain enable, priority,

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

EXPERIMENT 4: Parallel Input/Output. Objectives Introduction to the Parallel Input/Output (I/O) Familiarization to Interfacing

TKT-3500 Microcontroller systems

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

Introduction. Embedded system functionality aspects. Processing. Storage. Communication. Transformation of data Implemented using processors

Weekly Report: Interactive Wheel of Fortune Week 4 02/014/07-02/22/07 Written by: Yadverinder Singh

Basics of UART Communication

Input/Output Ports and Interfacing

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE Microcontroller Based System Design

Chapter 13. PIC Family Microcontroller

Arithmetic,logic Instruction and Programs

PIC16F /40-Pin 8-Bit CMOS FLASH Microcontrollers. Devices Included in this Data Sheet: Pin Diagram PDIP. Microcontroller Core Features:

AN587. Interfacing to an LCD Module. Interfacing to an LCD Module INTRODUCTION OPERATION CONTROL SIGNAL FUNCTIONS TABLE 2: CONDITIONAL ASSEMBLY FLAGS

8051 Serial Port. EE4380 Fall02 Class 10. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

Serial Port Utilities

Interrupts and Serial Communication on the PIC18F8520

Jordan University of Science and Technology Electrical Engineering Department Microcontrollers and Embedded Systems Spring 2011

Micro II and Embedded Systems

Embedded Systems and Software. Serial Communication

Embedded Systems and Software

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017

Chapter 5. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code.

Hardware Interfacing. EE25M Introduction to microprocessors. Part V. 15 Interfacing methods. original author: Feisal Mohammed

The University of Texas at Arlington Lecture 5

Design, Development & Implementation of a Temperature Sensor using Zigbee Concepts

ECE Test #1: Name

Assembly Language Instructions

Serial Communication Prof. James L. Frankel Harvard University. Version of 2:30 PM 6-Oct-2015 Copyright 2015 James L. Frankel. All rights reserved.

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

Performance & Applications

PIC16C7X 11.0 SYNCHRONOUS SERIAL PORT (SSP) MODULE SSP Module Overview. Applicable Devices

IE1206 Embedded Electronics

Sender Receiver Sender

Laboratory Exercise 5 - Analog to Digital Conversion

Interfacing PIC Microcontrollers. ADC8BIT2 Schematic. This application demonstrates analogue input sampling

Serial Communications

8051 Timers and Serial Port

PIC16F870/ /40-Pin, 8-Bit CMOS FLASH Microcontrollers. Devices Included in this Data Sheet: Pin Diagram. Microcontroller Core Features:

TKT-3500 Microcontroller systems

Serial Communications

Figure 1: Pushbutton without Pull-up.

EEE111A/B Microprocessors

Week1. EEE305 Microcontroller Key Points

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002 RESIT. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J1. Time allowed: 3 Hours

Chapter 11: Interrupt On Change

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Serial Port Communication Module No: CS/ES/11 Quadrant 1 e-text

Section 11. Timer0. Timer0 HIGHLIGHTS. This section of the manual contains the following major topics:

Section 14. Timer1 HIGHLIGHTS. Timer1. This section of the manual contains the following major topics:

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller

PICDEM-1 USER S GUIDE

D:\PICstuff\PartCounter\PartCounter.asm

Outline GPIO SPI UART. Ref. PIC Family Reference Manual:

Source Codes for DRA818U/DRA818V

Section 16. Basic Sychronous Serial Port (BSSP)

ﻢﯿﺣﺮﻟا ﻦﻤﺣﺮﻟا ﷲا ﻢﺴﺑ

PIC Discussion. By Eng. Tamar Jomaa

Micro-Controller: PIC16C74 < Part 5: Interrupt >

Transcription:

PIC18 Serial Port Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan chanhl@mail.cgu.edu.twcgu

Serial vs. parallel data transfer 2

Simplex, half-, and full-duplex transfers 3

Data framing in asynchronous serial communication Older systems: ASCII characters were 7-bit and number of stop bits were 2 (gives device sufficient time to organize itself before transmission of next byte) Modern systems: 8 ASCII bits and 1 stop bit ASCII A (41H) Parity bit odd: 1 is added for A or even: 0 is added for A 4

Data transfer rate (baud rate) Early IBM PC/XT was 100 ~ 9600 bps (bits per second) Pentium-based PC is as high as 56K bps Generally limited to 100K bps 5

RS232 connectors DB-9 6

RS232 standard RS232 voltage levels 1 : -3 ~ -25 V 0 : 3 ~ 25 V Line driver (voltage converter) Convert RS232 voltage levels to TTL voltage levels MAX232 MAX233 7

PIC18 connection to RS232 8

PIC18 UART (universal asynchronous receiver/transmitter) programming SPBGR (serial port baud rate generator) TXREG (transfer register) RCREG (receiver register) TXSTA (transmit status and control register) RCSTA(receive status and control register) PIR1 (peripheral interrupt request register1) 9

SPBRG register and baud rate Desired baud rate = Fosc/(4x16x(Y+1)) 1)) Fosc/4 instruction cycle The value for SPBGR Y = Fosc/64/BaudRate -1 10

Start bit detection in asynchronous Receiver Example: 8-bit, parity enabled 1 stop 8 cycles 16 cycles Tim Wilmshurst, An Introduction to the Design of Small-Scale Embedded Systems, Palgrave, 2001. 11

TXSTA: Transmit status and control register 12

TXSTA: Receive status and control register 13

PIR1 (interrupt control register 1) 14

Transmit the message YES serial at 9600 baud, 8- bit data, and 1 stop bit. Do this forever. MOVLW B 00100000 ; enable transmit and choose low baud MOVWF TXSTA MOVLW D 15 ; 9600 bps MOVWF SPBRG BCF TRISC, TX ; make TX pin an output BSF RCSTA, SPEN ; enable serial port OVER MOVLW A Y CALL TRANS MOVLW A E CALL TRANS MOVLW A S CALL TRANS MOVLW 0x0 ; null to purge the buffer CALL TRANS 15

Transmit the message YES (cont.) TRANS S1 BTFSS PIR1, TXIF ; wait until the last bit is gone BRA S1 MOVWF TXREG RETURN 16

Receive bytes of data serially and put them on PORTB. Set the baud rate 9600, 8-bit data, and 1 stop bit. MOVLW B 10010000 ; enable receive and serial port MOVWF RCSTA MOVLW D 15 ; 9600 bps MOVWF BSF CLRF SPBRG TRISC, RX ; make RX pin an input TRISB R1 BTFSS PIR1, RCIF ; check for ready BRA R1 MOVFF RCREG, PORTB BRA R1 17

Quadrupling the baud rate Baud rate for BRGH = 0 = Fosc/(4x16x(Y+1)) Baud rate for BRGH = 1 = Fosc/(4x4x(Y+1)) 18

Simplified USART transmit block diagram 19

Programming g serial communication interrupts 20

Read data from PORTD and transmit serially ORG 0000H GOTO MAIN ORG 0008H BTFSC PIR1, TXIF ; Is interrupt due to transmit? BRA TX_ISR RETFIE TX_ ISR ORG 0040H MOVFF PORTD, TXREG ; load new value, clear TXIF RETFIE 21

Read data from PORTD and transmit serially y( (cont.) ORG 00100H MAIN SETF TRISD ; make PORTD input MOVLW 0x20 ; enable transmit and choose low baud MOVWF TXSTA MOVLW D 15 ; 9600 bps MOVWF SPBRG BCF TRISC, TX ; make TX pin an output BSF RCSTA, SPEN ; enable serial port BSF PIE1, TXIE ; enable TX interrupt BSF INTCON, PEIE ; enable peripheral interrupts BSF INTCON, GIE ; enable interrupts globally OVER BRA OVER 22

Read data from PORTD and transmit serially while incoming data from serial port is sent to PORTB ORG 0000H GOTO MAIN ORG 0008H HI_ISRISR BTFSC PIR1, TXIF ;IsitTXinterrupt? interrupt? BRA TX_ISR BTFSC PIR1, RCIF ; Is it RC interrupt? TX_ ISR RC_ISR BRA RETFIE RC_ISR MOVFF PORTD, TXREG ; load new value, clear TXIF GOTO HI_ISR MOVFF RCREG, PORTB ; copy received data to PORTB GOTO HI_ISR 23

Read data from PORTD and transmit serially while incoming data from serial port to PORTB (cont.) ORG 00100H MAIN CLRF TRISB ; make PORTB output SETF TRISD ; make PORTD input MOVLW 0x20 ; enable transmit and choose low baud MOVWF TXSTA MOVLW D 15 ; 9600 bps MOVWF SPBRG BCF TRISC, TX ; make TX pin an output BSF TRISC, RX ; make RC pin an input MOVLW 0x90 ; enable receive and serial port MOVWF RCSTA BSF PIE1, TXIE ; enable TX interrupt BSF PIE1, RCIE ; enable receive interrupt BSF INTCON, PEIE ; enable peripheral interrupts BSF INTCON, GIE ; enable interrupts globally OVER BRA OVER 24

Reference M.A. Mazidi, R.D. Mckinlay, D Causey, PIC Microcontroller and Embedded Systems Using Assembly and C for PIC18, Pearson Education Inc., 2008. 25