EE 308 -- LAB 04
C Programming Language
Introduction
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 the last lab.
For example, the following C program increments Port B:
/* A C Language Program to Increment Port B on a 68HC11 * Bill Rison * January 12, 1996 */ #include <hc11.h> /* Get the HC11 definitions */ #define D_100MS 6667 /* To delay 100 ms */ #define TRUE 1 /* A normal C define */ /* Function to delay 100 milliseconds */ void delay_100ms(void) { int i; i = 0; while (i < D_100MS) { i = i + 1; } } void main() /* The main program */ { while (TRUE) /* Do forever */ { PORTB = PORTB + 1; /* Increment Port B */ delay_100ms(); /* Wait 100 ms */ } }
Pre-Lab
e:\icc11\iccsetup
icc11 -l inc.c
You should now have a file named inc.s in your directory. This is the assembly language file which the C compiler generated. Look at the file and try to understand what it does. Note that there will be some things which will not make sense to you. At the very least, find the assembly language code which adds one to what was in Port B, and stores it back into Port B. (Note that the C compiler produces assembly code in decimal rather than hexadecimal. Port B has an address of 0x1004, or 0d4100. You'll want to see where inc.s accesses address 4100.)
The Lab
icc11 -btext=0xb600 -bdata=0x0000 -d_stack=0x01ff inc.c
This will produce a file inc.s19 which has the code at address 0xB600, the data at address 0x0000, and loads the stack pointer at address 0x01FF . Load this file into your HC11 and run it. (Remember that 0xB600 is in EEPROM, so you will have to load your file at 300 baud, as you did in Lab 2.) Verify that Port B increments.