ELCT 912: Advanced Embedded Systems

Similar documents
EET203 MICROCONTROLLER SYSTEMS DESIGN Serial Port Interfacing

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

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

Embedded Systems Programming and Architectures

The University of Texas at Arlington Lecture 21_Review

Serial Communication with PIC16F877A

Asynchronous Transmission. Asynchronous Serial Communications & UARTS

Experiment 7:The USART

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

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

Example of Asyncronous Serial Comms on a PIC16F877

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

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

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

Section 21. Addressable USART

Serial Communication

Chapter 13. PIC Family Microcontroller

Kit Contents. Getting Started Kits. Board. Board

ELE492 Embedded System Design

Interrupts on PIC18F252 Part 2. Interrupts Programming in C Language

Embedded Systems Lab Lab 8 EEPROM

Interrupts and Serial Communication on the PIC18F8520

Department of Electronics and Instrumentation Engineering Question Bank

FULL DUPLEX BIDIRECTIONAL UART COMMUNICATION BETWEEN PIC MICROCONTROLLERS

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Interrupt Handling Module No: CS/ES/13 Quadrant 1 e-text

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

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

Micro-Controller: PIC16C74 < Part 5: Interrupt >

IE1206 Embedded Electronics

Interrupts on PIC18F252 Part 2

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

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

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text

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

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

These 3 registers contain enable, priority,

PIC Discussion By Eng. Tamar Jomaa

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

Embedded Systems Design (630470) Lecture 4. Memory Organization. Prof. Kasim M. Al-Aubidy Computer Eng. Dept.

Hong Kong Institute of Vocational Education Digital Electronics & Microcontroller. 8. Microcontroller

Lab 6 RS-232 Communication The following routines are provided for devices with a single USART peripheral:

The MICROPROCESSOR PRINCIPLES AND APPLICATIONS Lab 7

8051 Microcontroller

4D Picaso Touchscreen Display board datasheet EB

8051 Timers and Serial Port

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

NH-67, TRICHY MAIN ROAD, PULIYUR, C.F , KARUR DT. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING COURSE MATERIAL

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

DIPLOMA THESIS DETECTION AND PREVENTION OF FAULTY PINS

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

Embedded System Design

EE458 - Embedded Systems Exceptions and Interrupts

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

TKT-3500 Microcontroller systems

Chapter 11: Interrupt On Change

Embedded Systems. PIC16F84A Internal Architecture. Eng. Anis Nazer First Semester

Chapter 09. Programming in Assembly

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

ET-PIC 24 WEB-V1. o Central Processing Unit (CPU) o System. o nanowatt Power Managed Modes. o Analog Features

Microprocessors and Microcontrollers (EE-231)

Chapter 6 PROGRAMMING THE TIMERS

TKT-3500 Microcontroller systems

Unit B - Rotary Encoders B.1

8051 Serial Communication

LABORATORY MANUAL Interfacing LCD 16x2, Keypad 4x4 and 7Segment Display to PIC18F4580

The 8051 microcontroller has two 16-bit timers/counters called T0 and T1.

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

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

Interrupt Programming: Interrupts vs. Polling Method:

DERTS Design Requirements (1): Microcontroller Architecture & Programming

More Fun with Timer Interrupts

Introduction to Microcontroller Apps for Amateur Radio Projects Using the HamStack Platform.

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

Cork Institute of Technology. Autumn 2006 Microcomputer Applications (Time: 2 Hours)

Microcontroller basics

SH69P48A EVB. Application Notes for SH69P48A EVB SH69V48A JP2 J4(ICE_J4) S1 IDD TEST JP1 74HC273 JP4 JP3 74HC273 JP6 STKOVE JP7 SW1 J5(ICE_J5)

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING MSC SYSTEMS ENGINEERING AND ENGINEERING MANAGEMENT SEMESTER 2 EXAMINATION 2016/2017

USART Functions. putsusart puts1usart puts2usart putrsusart putrs1usart putrs2usart. ReadUSART Read1USART Read2USART getcusart getc1usart getc2usart

Chapter 2 Sections 1 8 Dr. Iyad Jafar

USB232 board EB Technical datasheet

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

BHARATHIDASAN ENGINEERING COLLEGE. III Year / V Semester / EEE MICROPROCESSORS AND MICROCONTROLLERS (R-2013)

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

CENG-336 Introduction to Embedded Systems Development. Timers

Laboratory: Introduction to Mechatronics

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

/*Algorithm: This code display a centrifuge with five variable speed RPM by increaseing */

Mod-3: Interrupts,Timer operation,serial communication 1

Interrupts & Interrupt Service Routines (ISRs)

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

\\OHARARP-PC\Users\ohararp\Documents\PICBASIC\18F25K20\GM862\GM862_D.bas

Timer0..Timer3. Interrupt Description Input Conditions Enable Flag

Binary Outputs and Timing

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet Example Application...

PIC-I/O Multifunction I/O Controller

CoE3DJ4 Digital Systems Design. Chapter 5: Serial Port Operation

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

Microcontroller Overview

MTRX3700 Mechatronics

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

Transcription:

ELCT 912: Advanced Embedded Systems Lecture 10: Applications for Programming PIC18 in C Dr. Mohamed Abd El Ghany, Department of Electronics and Electrical Engineering

Programming the PIC18 to transfer data serially 1. The TXSTA register is loaded with the value 20H, indicating asynchronous mode with 8-bit data frame, low baud rate, and transmit enabled. 2. Make TX pin of PORTC (RC6) an output for data to come out of the PIC 3. The SPBRG is loaded with value to set the baud rate for serial data transfer 4. SPEN bit in the RCSTA register is set HIGH to enable the serial port of PIC18 5. The character byte to be transmitted serially is written into the TXREG register. 6. Monitor the TXIF bit of the PIR1 register to make sure UART is ready for next byte 7. To transfer the next character, go to step 5 2

Programming the PIC18 to transfer data serially Write a C program for the PIC18 to transfer the letter G serially at 9600 baud, continuously. Use 8-bit data and 1 stop bit. Assume XTAL = 10 MHz. 3

Programming the PIC18 to transfer data serially Write a PIC18 C program to transfer the message YES serially at 9600 baud, 8-bit data, and 1 stop bit. Do this continuously. 4

Programming the PIC18 to receive data serially 1. The RCSTA register is loaded with the value 90H, to enable the continuous receive in addition to the 8-bit data size option 2. The TXSTA register is loaded with the value 00H to choose the low baud rate option. 3. SPBRG is loaded with a value to set the baud rate 4. Make the RX pin of PORTC (RC7) an input for data to come into the PIC18. 5. The RCIF flag bit of the PIR1 register is monitored for a HIGH to see if an entire character has been received yet. 6. When RCIF is raised, the RCREG register has the byte. Its contents are moved into a safe place 7. To receive the next character, go to Step5 5

Programming the PIC18 to receive data serially Program the PIC18 in C to receive bytes of data serially and put them on PORTB. Set the baud rate at 9600, 8-bit data, and 1 stop bit. 6

Example Write an C18 program to send two different strings to the serial port. Assuming that SW is connected to pin PORTB.5, monitor its status and make a decision as follows: SW = 0; send your first name SW = 1; send your last name Assuming XTAL =10 MHz, baud rate of 9600, and 8-bit data Part 1 7

Example Part 2 8

Baud rates for BRGH =1 Note : for F osc = 10 MHz, we have SPBRG = (625000/ Baud Rate) 1 9

SPBRG Values for Various Baud Rates (XTAL = 10 MHz) 10

Baud rates error calculation For example, with the XTAL = 10 MHz and BRGH =0, we have the following for the 9600 baud rate: SPBRG value = (156250/9600)-1= 16.27 1= 15.27 =15 Error = (15.27 15)/16 = 1.7% 11

Example Write a PIC18 C program to send the two messages Normal speed and High Speed to the serial port. Assuming that SW is connected to pin PORTB.0, monitor its status and set the baud rate as follows: SW =0 9600 baud rate SW =1 38400 baud rate Assuming XTAL =10 MHz for both cases. Part 1 12

Example Part 2 13

Programming Timer Interrupts Timer Interrupt Flag Bits and Associated Registers INTCON Register with Timer0 Interrupt Enable and Interrupt Flag 14

Programming Timer Interrupts The Role of Timer Interrupt Enable Flag (TMRxIE) 15

The Difference Between the RETURN and RETFIE Instructions Explain why we cannot use RETURN instead of RETFIE as the last instruction of ISR Both perform the same actions of popping off the top bytes of the stack into the program counter and making the PIC18 return to where it left off. However, RETFIE also performs the additional task of clearing the GIE flag, indicating that the servicing of the interrupt is over and the PIC18 now can accept a new interrupt. If you use RETURN instead of RETFIE as the last instruction of interrupt service routine, you simply block any new interrupt after the first interrupt, because the GIE would indicate that the interrupt is still being serviced. 16

Example Write a program to use Timer0 and Timer1 interrupts to generate square waves on pins RB1 and RB7 respectively, while data is being transferred from PORTC to PORTD Part 1 17

Example Part 2 18

Example Part 3 19

Example Part 4 20

PIC18 interrupt Programming in C Notes: The C18 compiler uses #pragma code to place code at a specific ROM address. Because the C18 does not pace an ISR at the interrupt vector table automatically, we must use assembly language instruction GOTO at the interrupt vector to transfer control to the ISR. 21

PIC18 interrupt Programming in C Now we redirect it from address location 00008 to another program to find the source of the interrupt and finally to the ISR. This is done with the help of the keyword interrupt as follows: 22

Example Write a program to use Timer0 and Timer1 interrupts to generate square waves on pins RB1 and RB7 respectively, while data is being transferred from PORTC to PORTD ( C version) Part 1 23

Example Part 2 24

Example Part 3 25

Example Part 4 26