21.07.2013 Views

Introduction to Microcontrollers Lab Manual - Microchip

Introduction to Microcontrollers Lab Manual - Microchip

Introduction to Microcontrollers Lab Manual - Microchip

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

8.3 THE LAB<br />

8.3.1 Objective<br />

Write a program <strong>to</strong> look for a string at a particular address in the external EEPROM.<br />

Then, using the UART and a terminal emula<strong>to</strong>r like in <strong>Lab</strong> 3, display the string or an<br />

error message. Finally, provide a simple prompt that allows the user <strong>to</strong> enter a new<br />

string. This string, if entered, would be s<strong>to</strong>red in<strong>to</strong> the same location in external<br />

memory.<br />

Record how much program and data memory your program takes. This is reported by<br />

MPLAB IDE in the menu View>Memory Usage.<br />

8.3.2 Pertinent Information<br />

In order <strong>to</strong> write in<strong>to</strong> EEPROM, it must first be erased. Then, and only then, can it be<br />

successfully programmed. An EEPROM that has been erased will read 0xff as the<br />

value of each byte. This is how the program will know if a string has been entered since<br />

0xff is not a valid ASCII character.<br />

The string could either be of fixed length or could be NULL terminated (like C uses).<br />

You will have <strong>to</strong> add the logic for the NULL termination <strong>to</strong> both the writing and reading<br />

of the data, i.e. you will have <strong>to</strong> write an extra 0x00 value after the string entered by the<br />

user.<br />

When enabling the SPI for the external 25LC256 EEPROM memory, you will have <strong>to</strong><br />

drive the SPI_CS_ROM (pin 42) and SPI_CS_ID (pin 92) directly and run the SPI in 3pin<br />

mode. It is important <strong>to</strong> ensure that other devices on the SPI bus are inactive.<br />

SPI chip select lines:<br />

SPI_CS_ROM (pin 42), PORTB (pin 13)<br />

You will have <strong>to</strong> configure the PPS for the SPI for the following pins:<br />

SPI_SCK (pin 10), configure PPS output RP21 <strong>to</strong> SCKxOUT<br />

SPI_MOSI (pin 12), configure PPS output RP19 <strong>to</strong> SDOx<br />

SPI_MISO (pin 11), configure PPS input RP26 <strong>to</strong> SPIx<br />

The basic program flow is depicted in Figure 8-4.<br />

2011 <strong>Microchip</strong> Technology Inc. DS51963A-page 61

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!