Professional Documents
Culture Documents
Pic32mx LCD Init
Pic32mx LCD Init
h> #define LCDDATA 1 cess data register #define LCDCMD 0 cess command register #define PMDATA PMDIN buffer #define busyLCD() readLCD (LCDCMD) & 0x80 #define addrLCD() readLCD (LCDCMD) & 0x7F #define getLCD() readLCD(LCDDATA) #define #define #define #define putLCD(d) writeLCD(LCDDATA,(d)) cmdLCD(c) writeLCD( LCDCMD,(c)) homeLCD() writeLCD(LCDCMD,2) clrLCD() writeLCD(LCDCMD,1) // // // RS=1 ;ac RS=0 ;ac PMP data
void LCDinit(void) { // PMP initialization PMCON = 0x83BF; he PMP, long waits PMMODE = 0x3FF; ode 1 PMAEN = 0x0001; bled // init TMR1 // // enable, // // // enable t Master M PMA0 ena
T1CON = 0x8030; 1:256 Fpb, 1 tick ~6uS TMR1=0; while (TMR1<6000); s PMADDR =LCDCMD; register (ADDR=0) PMDATA = 0x38; t interface, 2 lines , 5x7 TMR1=0 ; while(TMR1<8); = 48uS PMDATA = 0x0f; ursor, no blink TMR1=0 ; while(TMR1<8); = 48uS PMDATA = 0x01; splay
TMR1=0 ; while(TMR1<300); S PMDATA = 0x06; t mode on, entire shift on TMR1=0 ; while(TMR1<300); } // read LCD char readLCD (int addr) { int dummy; while(PMMODEbits.BUSY); be available PMADDR = addr; nd addr dummy = PMDATA; dummy read while( PMMODEbits.BUSY); be available return(PMDATA); status register } void writeLCD(int addr, char c) { while (busyLCD()); while(PMMODEbits.BUSY); ilable PMADDR = addr; PMDATA = c; } // write LCD
//
//
8 x 6uS = 1.8mS
// // // //
wait for PMP to select the comma init read cycle, wait for PMP to // read the
//
main( void) { //initialize LCDinit(); putsLCD("Welcome to cmdLCD(0x80 |0x40); putsLCD(" cmdLCD(0x80 |0x14); putsLCD("Hope you'll enjoy"); cmdLCD(0x80 |0x54); "); PIC32"); // Third Line // Fourth line // First line // Second line