Chapter 9 Alphanumeric Displays

Slides:



Advertisements
Similar presentations
Chapter 3 Message in a Bottle Programming Loops in C.
Advertisements

Chapter 2 Walking in Circles Programming Loops in C.
Keeping the Sheep Corralled An engineer, a physicist, and a mathematician are shown a pasture with a herd of sheep, and told to put them inside the smallest.
Chapter 4 NUMB3RS.
Lab 12 : Liquid Crystal Displays: Slide 2 Slide 3 Slide 4 Slide 5 Slide 6 Slide 7 DMD Basics : Slide 8 Slide 9 Slide 10 Slide 11 Slide 12 Data Write the.
Lab7: Introduction to Arduino
Slides created by: Professor Ian G. Harris PIC Development Environment MPLAB IDE integrates all of the tools that we will use 1.Project Manager -Groups.
Chapter 6 Under the Hood. Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition) Checklist The following tools will be used in this lesson:
Outline  Examine some of the H/W supplied with a typical PC and consider the software required to control it.  Introduce Commkit, a software tool that.
MP3 player on PC using PIC controller via USB. Supervisor: Dmitry Sokolik Performed by: Yoav Gershoni Shachar Faigenblat.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
Chapter 8 Communication Introduction to serial communication interfaces. Examples of use of the SPI module.
16x2 LCD Module on DE2-115 數位電路實驗 TA: 吳柏辰 Author: Trumen.
Chapter 1 The First Flight Creating the first project and saying “Hello to the World”
Digital Outputs LCD Display
Chapter 5 Interrupts.
Chapter 3 More Loops. Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition) Checklist The following tools will be used in this lesson:
Chapter 2 A Loop in the Pattern Designing the Main Loop and Timing.
LCD Interfacing.
UniMAP 1 Interfacing Peripherals. UniMAP 2 Interfacing devices on Embedded Linux In general, to interface to a device connected to an embedded Linux platform.
8279 KEYBOARD AND DISPLAY INTERFACING
EEE527 Embedded Systems Lecture 2: Chapter 2: C and Using more MPLAB (X) + XC32 Ian McCrumRoom 5B18, Tel: voice mail on 6 th ring
Computer Architecture 2 nd year (computer and Information Sc.)
Chapter 10 Glass Bliss Using the Parallel Master Port to communicate with Alphanumeric LCD displays.
8279 KEYBOARD AND DISPLAY INTERFACING
Chapter 5 - Interrupts.
Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC.
Microcontrollers, Microcomputers, and Microprocessors
Microcontrollers JULES CALELLA. Microcontrollers vs Microprocessors  Microprocessors – do not contain RAM, ROM, I/O  Microcontrollers – The whole package.
Vishwakarma government engineering college Prepare by. Hardik Jolapara( ) LCD Interfacing with ATmega16.
CEng3361/18 CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT Spring 2007 Recitation 01.
Sitarambhai Naranjibhai Patel Institute of Technology and Research Centre, Umrakh, Bardoli. A Presentation On “ 16x2 LCD Interfacing with AVR atmega32.
LCD AND LCD INTERFACING. INDEX:-  INTRODUCTION  PIN DISCRIPTION  INITIALIZATION OF LCD  LCD INTERFACING  LCD INTERFACING WITH ATMEGA 32  INTERFACING.
CEng3361 CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT Spring 2011 Recitation 06.
ENERGY METER TO INDICATE BILLING IN RUPEES FOR LOAD WISE OR DAY WISE
INT. TO EMBEDDED SYSTEMS DEVELOPMENT
Peripherals – Keypad The Keypad provides a simple means of numerical data or control input. The keys can be attributed whatever data or control values.
LCD Interfacing using Atmega 32
Basic Computer Organization and Design
Chapter 8 Asynchronous Serial
Topics Introduction Hardware and Software How Computers Store Data
LCD and Keyboard Interfacing
Microcontroller Applications
UNIVERSAL COLLEGE OF ENGINEERING & TECHNOLOGY
GANDHINAGAR INSTITUTE OF TECHNOLOGY
Microprocessor and Assembly Language
8259 Chip The Intel 8259 is a family of Programmable Interrupt Controllers (PIC) designed and developed for use with the Intel 8085 and Intel 8086 microprocessors.
EET 2261 Unit 11 Controlling LCD and Keypad
Introduction to Microprocessors and Microcontrollers
Interfacing Memory Interfacing.
LCD and Keyboard Interfacing
EET 2261 Unit 11 Controlling LCD and Keypad
LCD and Keyboard Interfacing
Chapter 2 – Introduction to the Visual Studio .NET IDE
Chapter 10 It’s an Analog World
Basic Editing Lesson 2.
MARIE: An Introduction to a Simple Computer
Topics Introduction Hardware and Software How Computers Store Data
Introducing the PIC Mid-Range Family and the 16F84A
LCD and Keyboard Interfacing
LCD and Keyboard Sepehr Naimi
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
8279 – Programmable Keyboard/Display Interface
8051 Micro Controller.
LCD and Keyboard Interfacing
INTERRUPTS.
The Programmable Peripheral Interface (8255A)
Presentation transcript:

Chapter 9 Alphanumeric Displays “Glass = Bliss”

Checklist The following tools will be used in this lesson: MPLAB X, Integrated Development Environment (v1.8 or later, free) MPLAB XC16, C compiler (v1.11 or later, free) The following pieces of documentation will be used during this lesson: PIC24FJ128GA010 Datasheet –DS39747 (latest rev.) Make sure they are available and/or installed and ready to use on your computer. You can download them from Microchip web site at: http://www.microchip.com/mplabx And http://www.microchip.com/xc16 Additional Hardware Tools: Explorer 16/32 evaluation board or equivalent board with 2x16 alphanumeric display (HD44780 compatible) ICD3 In circuit Programmer Debugger (or ICD4, Real-ICE)

Alphanumeric Displays

Character Set

HD44780 Command Set Instruction Code Description Execution time RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 Clear display 1 Clears display and returns cursor to the home position (address 0). 1.64mS Cursor home * Returns cursor to home position (address 0). Also returns display being shifted to the original position. DDRAM contents remains unchanged. Entry mode set I/D S Sets cursor move direction (I/D), specifies to shift the display (S). These operations are performed during data read/write. 40uS Display On/Off control D C B Sets On/Off of all display (D), cursor On/Off (C) and blink of cursor position character (B). Cursor/display shift S/C R/L Sets cursor-move or display-shift (S/C), shift direction (R/L). DDRAM contents remains unchanged. Function set DL N F Sets interface data length (DL), number of display line (N) and character font(F). Set CGRAM address CGRAM address Sets the CGRAM address. CGRAM data is sent and received after this setting. Set DDRAM address DDRAM address Sets the DDRAM address. DDRAM data is sent and received after this setting. Read busy-flag and address counter BF CGRAM / DDRAM address Reads Busy-flag (BF) indicating internal operation is being performed and reads CGRAM or DDRAM address counter contents (depending on previous instruction). 0uS Write to CGRAM or DDRAM write data Writes data to CGRAM or DDRAM. Read from CGRAM or DDRAM read data Reads data from CGRAM or DDRAM.

HD44780 Command Bits Bit name Setting / Status I/D 0 = Decrement cursor position 1 = Increment cursor position S 0 = No display shift 1 = Display shift D 0 = Display off 1 = Display on C 0 = Cursor off 1 = Cursor on B 0 = Cursor blink off 1 = Cursor blink on S/C 0 = Move cursor 1 = Shift display R/L 0 = Shift left 1 = Shift right DL 0 = 4-bit interface 1 = 8-bit interface N 0 = 1/8 or 1/11 Duty(1 line) 1 = 1/16 Duty (2 lines) F 0 = 5x7 dots 1 = 5x10 dots BF 0 = Can accept instruction 1 = Internal operation in progress

PMPCON Control Register

Initializing the Display #define LCDDATA 1 #define LCDCMD 0 #define PMDATA PMDIN1 void InitLCD( void) { // PMP initialization PMCON = 0x83BF; // Enable the PMP, long waits PMMODE = 0x3FF; // Master Mode 1 PMAEN = 0x0001; // PMA0 enabled // init TMR1 T1CON = 0x8030; // Fosc/2, 1:256, 16us/tick // wait for >30ms TMR1 = 0; while( TMR1<2000);// 2000 x 16us = 32ms PMADDR = LCDCMD; // command register PMDATA = 0b00111000; // 8-bit, 2 lines, 5x7 TMR1 = 0; while( TMR1<3); // 3 x 16us = 48us PMDATA = 0b00001100; // ON, cursor off, blink off PMDATA = 0b00000001; // clear display TMR1 = 0; while( TMR1<100); // 100 x 16us = 1.6ms PMDATA = 0b00000110; // increment cursor, no shift } //InitLCD

Reading and Writing char ReadLCD( int addr) { int dummy; while( PMMODEbits.BUSY); // wait for PMP to be available PMADDR = addr; // select the command address dummy = PMDATA; // initiate a read cycle, dummy return( PMDATA); // read the status register } // ReadLCD #define BusyLCD() ReadLCD( LCDCMD) & 0x80 #define AddrLCD() ReadLCD( LCDCMD) & 0x7F #define getLCD() ReadLCD( LCDDATA) void WriteLCD( int addr, char c) while( BusyLCD()); PMADDR = addr; PMDATA = c; } // WriteLCD

Testing the Display #define putLCD( d) WriteLCD( LCDDATA, (d)) #define CmdLCD( c) WriteLCD( LCDCMD, (c)) #define HomeLCD() WriteLCD( LCDCMD, 2) #define ClrLCD() WriteLCD( LCDCMD, 1) void putsLCD( char *s) { while( *s) putLCD( *s++); } // putsLCD main( void) // initializations InitLCD(); // put a title on the first line putsLCD( "Flying the PIC24"); // main loop, empty for now while ( 1) } } // main

Defining Custom Characters // useful macros #define SetLCDG( a) writeLCD( LCDCMD, (a & 0x3F) | 0x40) // position cursor in CGRAM #define setLCDC( a) writeLCD( LCDCMD, (a & 0x7F) | 0x80) // position cursor in DDRAM // generate two new characters SetLCDG(0); putLCD( 0b00010); putLCD( 0b00110); putLCD( 0b11111); putLCD( 0); // alignment putLCD( 0b00000); putLCD( 0b00100); putLCD( 0b01100); putLCD( 0b11100);

Flying the PIC24 // fly airplane, fly! while( 1) { // the entire plane appears at the right margin setLCDC(0x40+14); putLCD( 0); putLCD( 1); DELAY(); // fly fly fly (from right to left) for( i=13; i>=0; i--) setLCDC(0x40+i); // cursor to next position putLCD(0); putLCD(1); // new airplane putLCD(' '); // erase the previous tail } // the tip disappears off the left margin, // only the tail is visible setLCDC(0x40); putLCD( 1); putLCD(' '); // erase the tail setLCDC(0x40); // point to left margin 2nd line putLCD(' '); // and draw just the tip appearing from the right setLCDC(0x40+15); // point to right margin 2nd line putLCD( 0); } // repeat the main loop

Notes for User Interface Experts The PIC24 family of microcontrollers has expanded considerably in the last few years and includes now a number of models (PIC24F DA2) that offer two important new features: The Charge Time Measurement Unit (CTMU), which allows very precise control of capacitive inputs as required in touch screen applications An integrated Graphic Controller, including 3 hardware acceleration units that allow for very effective interface to C-STN and TFT (color) graphic displays For all PIC24 microcontrollers that offer the basic PMP port there is also the possibility to interface directly to Mobile Displays that integrate both the graphic controller and all the RAM required (several hundred Kbytes) to maintain a 16-bit color QVGA or larger image. The complexity of developing any advanced graphical user interface is greatly reduced by the availability of a complete (object oriented) graphic library (GOL) as part of the Microchip Libraries for Application (MLA).

Notes for C Experts it is possible to replace the low level I/O routines defined in the stdio.h library, and in particular write.c, to re-direct the output to the LCD display as in the example code below: #include <p24fxxxx.h> #include <stdio.h> #include <LCD.h> int write(int handle, void *buffer, unsigned int len) { int i, *p; const char *pf; switch (handle) case 0: case 1: case 2: for (i = len; i; --i) putLCD( *(char*)buffer++); break; default: } return(len);

Tips and Tricks Since the LCD display is a slow peripheral, waiting for its commands to be completed in tight (locking) loops constitute a waste of MCU cycles. A better scheme allows for LCD commands to be cached in a FIFO buffer and an interrupt mechanism to periodically schedule their execution in the background of the main application execution. Hint: An example of such a mechanism is provided in the LCD.c example code provided with the Explorer16 demonstration board.

Suggested Excercises Enhance the putLCD() function to interpret correctly the following characters: ‘\n’: advance to the next line ‘\r’: re-position cursor to the beginning of current line ‘\t’: advance to a fixed tabulation position Enhance the putLCD() function to interpret the following ANSI escape codes: ‘\x1b[2J’: clear entire screen ‘\x1b[1;1H’: home cursor ‘\x1b[n;mH’: position the cursor at row ‘n’, column ‘m’

Recommended Readings Di Jasio, L. (2013), “Graphics, Touch, Sound and USB”, Lulu.com This book contains an introduction to use and configuration/customization of the Primitives and the Graphic Object Library (GOL) contained in the Microhip Libraries for Applications (MLA). Wilbert O. Galitz, “The essential guide to User Interface Design”, Wiley Designing user interfaces (graphical or not) is a science, a little planning can goes a long way in making your application more usable and effective.

Online Resources http://www.microchip.com/graphics This is the design center dedicated to graphic displays interfaces http://www.microchip.com/mla This is the Microchip Libraries for Applications page. It contains the Graphic Library that offers an object oriented library for the creation of graphical user interfaces using 16-bit color diplays and touch sensing inputs. http://www.microchip.com/PICTailPlus This is the catalog of expansion boards available for the Explorer16/32. Among them the Graphics PICTail Plus (AC164127) will allow you to quickly evaluate color graphic applications.