Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 9 Alphanumeric Displays

Similar presentations


Presentation on theme: "Chapter 9 Alphanumeric Displays"— Presentation transcript:

1 Chapter 9 Alphanumeric Displays
“Glass = Bliss”

2 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: And 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)

3 Alphanumeric Displays

4 Character Set

5 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.

6 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

7 PMPCON Control Register

8 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 = 0b ; // 8-bit, 2 lines, 5x7 TMR1 = 0; while( TMR1<3); // 3 x 16us = 48us PMDATA = 0b ; // ON, cursor off, blink off PMDATA = 0b ; // clear display TMR1 = 0; while( TMR1<100); // 100 x 16us = 1.6ms PMDATA = 0b ; // increment cursor, no shift } //InitLCD

9 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

10 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

11 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);

12 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

13 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).

14 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);

15 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.

16 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’

17 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.

18 Online Resources This is the design center dedicated to graphic displays interfaces 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. 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.


Download ppt "Chapter 9 Alphanumeric Displays"

Similar presentations


Ads by Google