PA 8001 2013 Practical 0

From CERES
Jump to: navigation, search

Objectives

The objectives of this practical are twofold:

  • To make sure that you have understood the basic concepts of C programming required for the rest of the course
  • To acquire basic familiarity with the AVR-Butterfly microprocessor board and its programming

Instructions

You need to submit a single .zip file on blackboard containing the programs for Part 1 and Part 3. The two parts should be put in two different folders, named Part 1 and Part 3, respectively. Only submissions before the deadline are considered, unless you ask for a deadline extension before the deadline. You do not have to wait for an acknowledgment if you ask for an extension. You can only ask for a deadline extension for one week for at most 2 out of 5 practicals.


Part 1: C Programming

  • Give the implementation for the functions specified in bitops.h (first download: bitops.zip)
  • Implement the main.c to run the specified test-cases for each and every function specified in the previous step.
  • Submit a .zip file on blackboard containing main.c, bitops.h and bitops.c . Using CUnit to specify and run your test-cases will be given a bonus point; you can read more about and obtain CUnit from [1].

Part 2: Introduction to AVR-Butterfly

Start your computer and start the ProgrammersNotepad program you find under the WinAvr program. Download pa8001_lab0.zip to a new directory in the H: drive (call the directory Lab0). Unzip the file. You will find a C program, butterflyTest.c and a makefile that is needed for WinAvr when compiling and loading the program to the Butterfly. You can browse and modify the program by opening it in the ProgrammersNotepad. The butterfly board is already connected to a programmer that can be connected to the desktop via the USB interface. Do this! If you are using the school's desktops you will have to use the lower USB port! The board is now ready to receive a program and is getting power via the programmer from your desktop, which means that the program will start running as soon as it is loaded (remember to disconnect the USB from the computer before leaving the lab).

Compile the program using the make all command you find in the tools menu.

Compile and load the program using the make program command you find in the tools menu.

If you inspect the source file you will notice that we do not use predefined functions for writing things in the LCD display. Let's explain the program

#include<avr/io.h>
int main() {
 
 LCDCRA  = 0x80;
 LCDCRB  = 0xb7;
 LCDDR0  = 0x11;
 LCDDR5  = 0x88;
 LCDDR15 = 0x33;
 LCDDR1  = 0x11;
 LCDDR6  = 0x88;
 LCDDR16 = 0x33;
 LCDDR2  = 0x11;
 LCDDR7  = 0x88;
 LCDDR17 = 0x33;
}

We first include a library where all the identifiers we use are defined. For example, LCDCRA and LCDCRB are the names given to two registers in the LCD controller: LCD Control Registers A and B. Then we define the main function: what is executed when the program starts.

The two lines assigning to the control registers are initializations of the LCD (more on this in exercise 3!). What we assign is a combination of bits described using hexadecimal notation. Each hexadigit uses 4 bits, so we are assigning 8 bits (1 byte) to each register. LCDCRA gets 10000000 and LCDCRB gets 10110111.

The rest of the lines are assignments of bit combinations to the data registers (there are LCD Data Register 0 to 19).

Modify the program by removing the lines assigning to data registers 1, 6 and 16. Compile and run to see what happens.

Modify the program by assigning

LCDDR1  = 0x01;
LCDDR6  = 0x08;
LCDDR16 = 0x03;

Compile and run to see what happens. Modify the program by assigning

LCDDR1  = 0x10;
LCDDR6  = 0x80;
LCDDR16 = 0x30;

Compile and run to see what happens.


You do not need to submit the result of this part.

Part 2: Introduction to AVR-Butterfly LCD

Create a new directory and copy the makefile from exercise 1 to it. You will now write some small programs to explore how to control the butterfly's LCD. You should have a look at the documents ATmega169Manual.pdf (pages 209-224) and AVR065LCDdriver.pdf (pages 6-9). What follows helps you to read these documents. To begin with, you will have to initialize the device (the LCD). This is done only once in the program. The registers involved are LCD Control and Status Register A and B (LCDCRA and LCDCRB), the LCD Frame Rate Register (LCDFRR) and the LCD Contrast Control Register (LCDCCR). Check the documents mentioned above to see what bit patterns should be assigned to configure the LCD with drive time 300 microseconds, contrast control voltage 3.35 V, external asynchronous clock source, 1/3 bias, 1/4 duty cycle, 25 segments enabled, prescaler setting N=16, clock divider setting D=8, LCD enabled, low power waveform, no frame interrupt, no blanking. Do you understand what initialization we did in the first exercise?

In the rest of the program you will turn on different segments of the LCD. Each segment is related to one bit of the registers LCD Data Registers 0 through 19. To understand what segments correspond to each bit you should read pages 6 through 9 of AVR065LCDdriver.pdf document and make experiments (the names of the segments refer to figure 2-6 on page 6 of the document). You achieve what you want by assigning suitable bit patters to the proper registers LCDDRx. As you need to compile and upload new programs to your Butterfly you will need to modify the makefile so that the line starting with TARGET mentions the name of the file where you store the program (the makefile you got says butterflyTest on that line). Write programs to Turn on the : : segments (segments col1 and col2 in the documentation, figure 2-6 on page 6 of the LCD driver documentation) Turn on the numbers and arrows in segments s1 through s7 (refers to figure 2-6 on page 6 of the LCD driver documentation) Turn on the segments needed to write a 7 using digit segments 7, 6 in using digit segments 6, 5 using digit segments 5 (refers to figure 2-6 on page 6 of the LCD driver documentation).

Submit the last version of the butterflyTest (in which you display digits 7, 6 and 5 on the LCD). Submit your program in the same .zip file as your program for practical 0; do distinguish the two sets of programs by putting them in two different folders named Part 1 and Part 3.

Back to Embedded Systems Programming