B+[M+1]+E) * TPB ] represents the minimum time to complete an LCD read or write operation, this minimum time must be greater than the LCD enable cycle time, tC, which is specified as 450 ns. For the configuration described above, [(B+[M+1]+E) * TPB] = [(5) * 100 ns] = 500 ns, thereby satisfying the LCD timing specifications. If the cycle time is too short, wait periods can be added to any segment within the allowable ranges. Since the PMP is clocked from the peripheral bus clock, it is likely that the PMP cycle is slower than the core CPU, which means that the PMP also has a busy flag that must be polled before writing or reading the next byte. With the PMP interrupt disabled, the only way to determine if the PMP is ready for the next read or write cycle is to poll the PMP flag. The PMPMasterWrite function provided in the PIC32 Peripheral Library polls the PMP flag to ensure it has been cleared prior to writing. The code for writing to the LCD using the PMP is shown in Listing 7.3. —- ==== Listing 7.3. LCD Write Function Using the PMP ====

void writeLCD( int addr, char c)
{
while( busyLCD());	// Wait for LCD to be ready
PMPMasterWrite( c);    // initiate write sequence
} // End of writeLCD

—- Reading the PMP requires two successive read operations, as shown in Listing 7.4. Figure 7.17 shows that the PIC32 reads the Busy Flag 14 times before the Busy Flag resets. Since the readLCD function calls mPMPMasterReadByte(); twice in a row before returning the value, the readLCD function is only called seven times before the Busy Flag is returned as zero. Regardless of how many times the Busy Flag is read, the LCD doesn’t return a Busy Flag value of zero until 33.6 μs after the LCD write operation. A capture of the timing for the PMP is shown in Appendix B. —- ==== Listing 7.4. LCD Read Function Using the PMP ====

char readLCD( int addr )
{
} // End of readLCD