DOC PREVIEW
NMT EE 308 - EE 308 Lab

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

EE 308 Lab Spring 2009 ________________________________________________________________________ C Language Programming, Interrupts and Timer Hardware In this sequence of three labs, you will learn how to write simple C language programs for the MC9S12 microcontroller, and how to use interrupts and timers. WEEK 1 Introduction and Objectives The C programming language is used extensively in programming microprocessors. In this lab you will write some simple C programs which do the things you did in assembly language in Lab 2. For example, the following C program displays a counting pattern on the LEDs connected to Port B: Figure 1. A C program to increment LEDs connected to Port B.EE 308 Lab Spring 2009 ________________________________________________________________________ PreLab For the prelab write the program for Part 4 of this lab. The Lab 1. The procedure for compiling a program using the Gnu C compiler and the EGNU IDE is discussed in detail in Section 5.10 of the text. Start the EGNU IDE, and select File, then New source file. Type in the above C program, then select File, then Save unit as, and give it the name inc.c, and save it in your EE 308 directory. Select File, then New project, give the project an appropriate name (such as Lab3_Part1.prj), and save it in your EE 308 directory. (Note: The project name must be different than the C program base name. If the C program name is inc.c, the project name cannot be inc.prj.) When Project options pops up, click on the down arrow below Hardware Profiles, and select Dragon12. Click on Edit Profile, and make sure the addresses and lengths of the memory locations are reasonable. Make sure inc.c is part of your project. Also, make sure the file hcs12.h is in your directory. Compile and link your project by selecting Build, then Make. You should now have a file “*.s19” and a “*.dmp”. The “*.s19” can be run on the MC9S12. 2. The Lab3_Part1.dmp contains the assembly language listing generated by the C compiler. Look at the file and try to understand what it does. Note that there may be some things which do not make sense to you. At the very least, find the assembly language code which increments Port B. 3. The file Lab3_Part1.dmp also shows the addresses of the start of the functions in the program, as well as the addresses of any global variables. (Since the inc.c program does not use any global variables, none will appear in the Lab3_Part1.dmp file. The local variables used in inc.c are allocated on the stack when they are needed.) Note that the function and variable names are denoted by the symbol <_var name>. Note also that there is a function <_exit>. Find the address of this function. Look at the file Lab3_Part1.s19. This contains the op codes that will be loaded into the HC12. Reverse assemble the <_exit> function. What does it do? Load the file inc.s19 into your MC9S12 and run it. Verify that the LEDs increments. 4. Using the program inc.c as a model, write a C program to implement the program from Lab 2, week 3. Compile and run your program. Have an instructor verify that it works. 5. Look at the output of the GNU IDE and determine how many bytes the program takes (the length of the .text segment). Compare this to the length of last week’s program written in assembly. 6. Put your program in the EEPROM at address 0x0400. Remember, when you put code into EEPROM you need to do some setup which DBug12 normally does for you. You need to convert the assembly-language code (which multiplies the clock by 6) from Lab 2 into C code, and add it as the first lines of you program. There is no C statement to implement the assembly-language instruction “sei”. You can use the asm() function to insert this (or any other assembly language instruction) into you program: asm(“ sei;”); You will want the array which stores the turn signal patterns into the EEPROM (so the array will not disappear when you turn off power). You will want variables which will change as the program is executed to be placed in RAM. You can tell the compiler to put constant data (such as an array of patterns to beEE 308 Lab Spring 2009 ________________________________________________________________________ display on LEDs) immediately following the code (so the data will be loaded into EEPROM) by defining the data as type const. An example of setting up an array of type const is: Finally you need to tell the compiler to put the program into EEPROM. You can do this in one of two ways. In the directory with your project there should be a file called memory.x. You can edit memory.x to look like this: OUTPUT_FORMAT("elf32-m68hc12", "elf32-m68hc12","elf32-m68hc12") OUTPUT_ARCH(m68hc12) ENTRY(_start) SEARCH_DIR(C:\usr\lib\gcc-lib\m6811-elf\3.3.5-m68hc1x-20050515\m68hc12\mshort) MEMORY { ioports (!x) : org = 0x0000, l = 0x400 eeprom (!i) : org = 0x0f00, l = 0x0100 data (rwx) : org = 0x1000, l = 0x1000 text (rx) : org = 0x0400, l = 0x0b00 } PROVIDE (_stack = 0x3c00); This will tell the compiler to put text at address 0x400, which is in the EEPROM. Compile your program, load it into the 9S12, and verify that it runs correctly out of EEPROM. Another way to do this is to go to the Options menu, select Project Options, and make sure the Hardware Profile is set to Dragon12. Then select Edit Profile, and set eeprom to start at f00 with length 100, set text to start at 400 with length b00, set data to start at 1000 with length 2c00, and set the stack to 3c00. Click OK to accept these settings. Then go to Build and select Create memory.x. (Note: you will have to change memory.x back to its old values when you want to reload programs into RAM.)EE 308 Lab Spring 2009 ________________________________________________________________________ USING THE MC9S12 TIMER OVERFLOW INTERRUPT AND REAL TIME INTERRUPT WEEK 2 Introduction and Objectives Enabling an interrupt on the MC9S12 allows your program to respond to an external event without continually checking to see if that event has occurred. Once the event occurs, the MC9S12 interrupt subsystem will transfer control of your program to an interrupt service routine (ISR) to handle the event, and then return control to your original code sequence. In this week’s lab you will write assembly and C language program which enable and use interrupts. The interrupts on the MC9S12 which are easiest to use are the Timer Overflow Interrupt and the Real Time


View Full Document

NMT EE 308 - EE 308 Lab

Documents in this Course
Load more
Download EE 308 Lab
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view EE 308 Lab and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view EE 308 Lab 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?