Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 10 Glass Bliss Using the Parallel Master Port to communicate with Alphanumeric LCD displays.

Similar presentations


Presentation on theme: "Chapter 10 Glass Bliss Using the Parallel Master Port to communicate with Alphanumeric LCD displays."— Presentation transcript:

1 Chapter 10 Glass Bliss Using the Parallel Master Port to communicate with Alphanumeric LCD displays

2 Di Jasio - Programming 32-bit Microcontrollers in C Alphanumeric LCD Modules

3 Di Jasio - Programming 32-bit Microcontrollers in C InstructionCodeDescription/ Execution time RSR/WDB7DB6DB5DB4DB3DB2DB1DB0 Clear display0000000001Clears display and returns cursor to the home position (address 0). 1.64mS Cursor home000000001*Returns cursor to home position (address 0). Also returns display being shifted to the original position. DDRAM contents remains unchanged. 1.64mS Entry mode set00000001I/DSSets cursor move direction (I/D), specifies to shift the display (S). These operations are performed during data read/write.40uS Display On/Off 0000001DCBSets On/Off of all display (D), cursor On/Off (C) and blink of cursor position character (B). 40uS Cursor/display shift000001S/CR/L**Sets cursor-move or display-shift (S/C), shift direction (R/L). DDRAM contents remains unchanged. 40uS Function set00001DLNF**Sets interface data length (DL), number of display line (N) and character font(F).40uS Set CGRAM addr0001CGRAM addressSets the CGRAM address. CGRAM data is sent and received after this setting.40uS Set DDRAM addr001DDRAM addressSets the DDRAM address. DDRAM data is sent and received after this setting. 40uS Read busy-flag and address ctr01BFCGRAM / DDRAM addressReads 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 10write dataWrites data to CGRAM or DDRAM.40uS (or DDRAM) Read CGRAM 11read dataReads data from CGRAM or DDRAM.40uS (or DDRAM) HD44780 Instruction Set

4 Di Jasio - Programming 32-bit Microcontrollers in C HD44780 Instruction Set (cont.) Bit nameSetting / Status I/D0 = Decrement cursor position1 = Increment cursor position S0 = No display shift1 = Display shift D0 = Display off1 = Display on C0 = Cursor off1 = Cursor on B0 = Cursor blink off1 = Cursor blink on S/C0 = Move cursor1 = Shift display R/L0 = Shift left1 = Shift right DL0 = 4-bit interface1 = 8-bit interface N0 = 1/8 or 1/11 Duty (1 line)1 = 1/16 Duty (2 lines) F0 = 5x7 dots1 = 5x10 dots BF0 = Can accept instruction1 = Internal operation in progress

5 Di Jasio - Programming 32-bit Microcontrollers in C Character Generator Table

6 Di Jasio - Programming 32-bit Microcontrollers in C Parallel Master Port

7 Di Jasio - Programming 32-bit Microcontrollers in C PMCON PMCON Register 20-1 (DS61143)

8 Di Jasio - Programming 32-bit Microcontrollers in C LCD Initialization #define LCDDATA 1 // RS = 1 ; access data register #define LCDCMD 0 // RS = 0 ; access command register #define PMDATA PMDIN1 // PMP data buffer void LCDinit( void) { // PMP initialization PMCON = 0x83BF; // Enable the PMP, long waits PMMODE = 0x3FF; // Master Mode 1 PMPEN = 0x0001; // PMA0 enabled PMADDR = LCDCMD; // command register (ADDR = 0) PMDATA = 0x38; // set: 8-bit interface, 2 lines, 5x7 TMR1 = 0; while( TMR1<8); // 8 x 6us = 48us PMDATA = 0x0c; // ON, no cursor, no blink TMR1 = 0; while( TMR1<8); // 8 x 6us = 48us PMDATA = 0x01; // clear display TMR1 = 0; while( TMR1<300);// 300 x 6us = 1.8ms PMDATA = 0x06; // increment cursor, no shift TMR1 = 0; while( TMR1<300); // 300 x 6us = 1.8ms } // LCDinit

9 Di Jasio - Programming 32-bit Microcontrollers in C Reading the LCD char readLCD( int addr) { int dummy; while( PMMODEbits.BUSY); // wait for PMP to be available PMADDR = addr; // select the command address dummy = PMDATA; // init read cycle, dummy read while( PMMODEbits.BUSY); // wait for PMP to be available return( PMDATA); // read the status register } // readLCD #define busyLCD() readLCD( LCDCMD) & 0x80 #define addrLCD() readLCD( LCDCMD) & 0x7F #define getLCD() readLCD( LCDDATA)

10 Di Jasio - Programming 32-bit Microcontrollers in C Writing to the LCD void writeLCD( int addr, char c) { while( busyLCD()); while( PMMODEbits.BUSY); // wait for PMP to be available PMADDR = addr; PMDATA = c; } // writeLCD #define busyLCD() readLCD( LCDCMD) & 0x80 #define addrLCD() readLCD( LCDCMD) & 0x7F #define getLCD() readLCD( LCDDATA)

11 Di Jasio - Programming 32-bit Microcontrollers in C Extending the “Include Search Path”

12 Di Jasio - Programming 32-bit Microcontrollers in C LCD Control Using the peripheral library void initLCD( void) { // PMP initialization mPMPOpen( PMP_ON | PMP_READ_WRITE_EN | 3, PMP_DATA_BUS_8 | PMP_MODE_MASTER1 | PMP_WAIT_BEG_4 | PMP_WAIT_MID_15 | PMP_WAIT_END_4, 0x0001, // only PMA0 enabled PMP_INT_OFF); // no interrupts used // wait for >30ms Delayms( 30); //initiate the HD44780 display 8-bit init sequence PMPSetAddress( LCDCMD); // select command register PMPMasterWrite( 0x38); // 8-bit int, 2 lines, 5x7 Delayms( 1); // > 48 us PMPMasterWrite( 0x0c); // ON, no cursor, no blink Delayms( 1); // > 48 us PMPMasterWrite( 0x01); // clear display Delayms( 2); // > 1.6ms PMPMasterWrite( 0x06); // increment cursor, no shift Delayms( 2); // > 1.6ms } // initLCD

13 Di Jasio - Programming 32-bit Microcontrollers in C LCD Control Using the peripheral library char readLCD( int addr) { PMPSetAddress( addr); // select register mPMPMasterReadByte(); // initiate read sequence return mPMPMasterReadByte();// read actual data } // readLCD void writeLCD( int addr, char c) { while( busyLCD()); PMPSetAddress( addr); // select register PMPMasterWrite( c); // initiate write sequence } // writeLCD

14 Di Jasio - Programming 32-bit Microcontrollers in C putsLCD() void putsLCD( char *s) { char c; while( *s) { switch (*s) { case '\n': // point to second line setLCDC( 0x40); break; case '\r': // home, point to first line setLCDC( 0); break; case '\t': // advance next tab (8) positions c = addrLCD(); while( c & 7) { putLCD( ' '); c++; } if ( c > 15) // if necessary move to second line setLCDC( 0x40); break; default: // print character putLCD( *s); break; } //switch s++; } //while } //putsLCD

15 Di Jasio - Programming 32-bit Microcontrollers in C Advanced LCD Control #define setLCDG( a) writeLCD( LCDCMD, (a & 0x3F) | 0x40)

16 Di Jasio - Programming 32-bit Microcontrollers in C Progress Bar void newBarTip( int i, int width) { char bar; int pos; // save cursor position while( busyLCD()); pos = addrLCD(); // generate a new character at position i // set the data pointer to the LCD CGRAM buffer setLCDG( i*8); // as a horizontal bar (0-4)x thick moving left to right // 7 pixel tall if ( width > 4) width = 0; else width = 4 - width; for( bar=0xff; width > 0; width--) bar >= 1; if right to left // fill each row (8) with the same pattern putLCD( bar); // restore cursor position setLCDC( pos); } // newBarTip

17 Di Jasio - Programming 32-bit Microcontrollers in C Progress Bar (cont.) void drawProgressBar( int index, int imax, int size) { // index is the current progress value // imax is the maximum value // size is the number of character positions available int i; // scale the input values in the available space int width = index * (size*5) / imax; // generate a character to represent the tip newBarTip( TIP, width % 5); // user defined character 0 // draw a bar of solid blocks for ( i=width/5; i>0; i--) putLCD( BRICK); // filled block character // draw the tip of the bar putLCD( TIP); // use character 0 } // drawProgressBar


Download ppt "Chapter 10 Glass Bliss Using the Parallel Master Port to communicate with Alphanumeric LCD displays."

Similar presentations


Ads by Google