DOC PREVIEW
NMT EE 308 - C Language Programming, Interrupts and Timer Hardware

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

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 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 8 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 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

EE 308 Lab Spring 2008________________________________________________________________________C Language Programming, Interrupts and Timer HardwareIn 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 1Introduction and ObjectivesThe 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 the first lab. For example, the following C program increments Port H:Figure 1. A C program to increment Port B.EE 308 Lab Spring 2008________________________________________________________________________PreLabFor the prelab write the program for Part 4 of this lab.The Lab1. 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. 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 H.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 Port H 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 add the following as the first few instructions of your C program:EE 308 Lab Spring 2008________________________________________________________________________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 be 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 = 0x400eeprom (!i) : org = 0x0f00, l = 0x0100data (rwx) : org = 0x1000, l = 0x1000text (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 2008________________________________________________________________________USING THE MC9S12 TIMER OVERFLOW INTERRUPT AND REALTIME INTERRUPTWEEK 2Introduction and ObjectivesEnabling 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 Interrupt. These interrupts allow you to interrupt the microcontroller after a specified amount of time has passed.PreLabFor the prelab, write the programs for Sections f and g. Also, calculate the time asked for in Part e.The Laba. Connect your MC9S12 to your computer. At the DBug 12 prompt, display the contents of the TCNT register. Do this several times. How do the values compare?b. Use DBug12 to modify the TSCR1 register to enable the counter. Repeat Part 1.c. Use DBug12 to modify the TSCR1 register to


View Full Document

NMT EE 308 - C Language Programming, Interrupts and Timer Hardware

Documents in this Course
Load more
Download C Language Programming, Interrupts and Timer Hardware
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 C Language Programming, Interrupts and Timer Hardware 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 C Language Programming, Interrupts and Timer Hardware 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?