E15 Laboratory 4

More C

← Back to E15 Lab page ←

Please contact me if you find any errors or other problems (e.g., something is unclearly stated) in this web page


Useful references for E15 labs


This lab will be somewhat more "real-world" than previous labs in that that you will be required to read and use some actual manufacturer's data sheets.  The information below is purposefully incomplete - you'll have to look up a lot of it in the resources referenced.  If you absolutely can't find (or understand) something after about 20-30 minutes, you should feel free to come talk to me.

Task 1  (Basic): The LCD

Read the spec sheet for the LCD and write code that initializes the LCD and writes to it (note: there is some code in the datasheet (page 10) you can use as a guide for your own program).  For this task use the code in the file E15Lab4AD.c as a template:

Task 1a: Write a function "LCDputc(char c)" (LCD put char) that has as input a character (8 bits) and writes it one bit at a time to the serial clock (SCL: pin P1.1) and Serial Data (SI: P1.0).  In the function, the CSB line should be made low before the write, and set high afterwards.  Don't worry about changing the RS and RST lines, that will come later.  It will be helpful to examine page 10 of the LCD data sheet.

As an example, to write the hexadecimal 0xB9 you would need to create waveforms like the one below.   (Note: in this example RST=1, signifying no reset condition, and RS=1, signifying a data byte being written; to write a command set RS=0.  The value of RS and RST will be set outside the "LCDputc()" function.)

You will need to look at the I/O board schematic to see how these pins are connected to the MSP430.  You can't actually test  the "LCDputc()" function until you complete Task 1b. 

Task 1b: Write a function "LCDinit()" that initializes the LCD (refer to datasheet, page 10, for details). The function should set the appropriate pins on P1 to outputs.   You'll also have to manipulate the RST (Reset) and CS (Chip Select) lines and use your "LCDputc()" function; don't use separate "writecom" and "writedata" functions as is shown in data sheet.  For any of the required delays in the code, you can simply call the function below:

To test your initialization, try writing a letter "A" to the display.  The ASCII equivalent of "A" is the decimal number 65 (or 0x41) – so after initialization, set the display to write data and call "LCDputc(0x41)" or "LCDputc('A')" or "LCDputc(65)."  This is done in E15Lab4AD.c (before the "while(1)" loop - you just need to add a line to put RS high before the "LCDputc()."

Task 1c: Write a function "LCDputs(char s[])" (LCD put string).  The input is a character string (i.e., an array of char).  Test by modifying E15Lab4AD.c (i.e., removing the two labeled comments in the "while(1)" loop). 

Notes:

 

Task 2 (Basic) : The A/D

Download and run the code below (E15Lab4AD.c):

Note that the code reads from two channels - the potentiometer on the E15 I/O board is attached to pin P1.7 (Analog channel 7), a temperature sensor on the MSP430F2012 is connected to channel 10.  You can ignore the reading from channel 10.

Turn the potentiometer on the E15 I/O board all the way to the left, and pause the code ().  Look at the value of adval_7(From the debug window go to View→Local.)

Start the code again () and turn the potentiometer to the right.  Pause and examine adval_7.

Start the code, put the potentiometer to the middle.  Pause and examine adval_7.

Fill in a table like the one below by measuring the actual potentiometer voltage using a voltmeter between the pin on the I/O board marked "JGND" and the one labeled "JPOT" for several voltages between 0 and 2.5 V.

Voltage Actual
A/D Reading
(adval_7)
Expected
A/D Reading
     
     
     
     
     
     
     
     
     
     
     

 

Task 3 (Basic): LCD and A/D together

Task 3a: Write a program that reads from the A/D and writes the value to the LCD (either hexadecimal or decimal).  Use your "LCDputs()" function.

It will be helpful to know that the ASCII equivalents for the digits 0 through 9 are 0x30 through 0x39.

Task 3b: Write a program that reads from the A/D and displays the approximate angle of the potentiometer (in degrees) on the LCD.  Use the LCD character for degrees (shown) as part of your output.  Don't use any floating point numbers (i.e., only ints and chars).  

The top line of the display should read "Angle = xxx°."  (with period, without quotations), and should change as you move the potentiometer.  Assume 0° is when the potentiometer is in the middle of its mechanical range, and positive degrees correspond to clockwise rotation.

 

Task 4 (Advanced): More things

Task 4a: Look at the User's Manual for the MSP430 (Chapter 20, Section 20.2.8) and figure out how the A/D converter measures temperature.  Write code that displays the angle (in degrees) of the potentiometer on the top line and the temperature (in degrees Fahrenheit) on the bottom line. 

Task 4b: Unfortunately the LCD uses most of the pins of the MSP430 (I/O board schematic), but we can still manipulate the upper-left, middle, and lower right LED's.  Write a program that cycles through the LED's (about one per second) while displaying on the LCD which LED is on.

Task 4c: Something cool using the LCD and/or A/D (e.g., have a circle bounce back and forth across the LCD display, going faster if the temperature increases; or, make a thermometer with the top line showing the temperature in degrees, and the bottom line showing a horizontal bar graph of temperature; or ...).


To Turn in:

The grading of each subtask is as follows.


← Back to E15 Lab page ←

Please contact me if you find any errors or other problems (e.g., something is unclearly stated) in this web page