130 likes | 239 Views
ECE 447: Lecture 3. Microcontroller Programming in C. ECE 447: Class Exercise. Write a program in C that transfers 512 bytes of data starting at address 6000H to the block of memory starting at address 8000H. $0000-$01FF 512 bytes RAM. $0000. $1000. $ 2 000. $1000-$103F
E N D
ECE 447: Lecture 3 Microcontroller Programming in C
ECE 447: Class Exercise Write a program in C that transfers 512 bytes of data starting at address 6000H to the block of memory starting at address 8000H.
$0000-$01FF 512 bytes RAM $0000 $1000 $2000 $1000-$103F 64 bytes I/O registers $2000-$B5FF 37.5 kbytes $B600 $B600-$B7FF 512 bytes EEPROM $D000 $D000-$FFFF 12 kbytes ROM $FFFF Expanded bus mode ECE 447: 68HC11E9 Memory Map External RAM External RAM recommended for use recommended for use External RAM
$0000-$01FF 512 bytes RAM $0000 $1000 $6000 $2000 $1000-$103F 64 bytes I/O registers $6000-$B5FF 21.5 kbytes $2000-$5FFF 16 kbytes $B600 $B600-$B7FF 512 bytes EEPROM $D000 $FFFF Expanded bus mode ECE 447: Memory Map: Linker file Program area - text External RAM Data area – data External RAM
Text editor Assembly source C source .c .s Cross-compiler m6811-elf-gcc Cross-assembler m6811-elf-as Object listing .lst Relocatable object .o Relocatable object .o libraries Linker m6811-elf-ld (m6811-elf-gcc) {lib_name}.a Linker command file User libraries memory.x {lib_name}.a Non-relocatable executable program (a.out) ECE 447: Software Cycle
Non-relocatable executable image a.out Downloadable file converter : m6811-elf-objcopy Downloadable file a.s19 ECE 447: Software Cycle
ECE 447: Class Exercise 2 Write a program in C that continuously transfers data from PORT E to PORT C of MC68HC11.
RAM CPU ROM EEPROM A/D SPI TIMER SCI 8 (4) 8 4 2 PORT A PORT B PORT C PORT D PORT E 3 3 2 8 8 6 8 (4) ECE 447: Organization of MC68HC11
ECE 447: Class Exercise 3 Write a program in C that continuously scanspin PE5of PORT E of MC68H11. Whenevera falling edge is detected at PE5, the microcontroller shouldclear the pin PC4,and toggle pin PC2 of MC68HC11.
ECE 447: Setting and Clearing a bit Clearing a bit Setting a bit #define BIT3 0x04 unsigned char c = 5; void set_bit3(void) { c |= BIT3; } #define BIT3 0x04 unsigned char c = 5; void clear_bit3(void) { c &= ~BIT3; }
ECE 447: Toggling a bit #define BIT3 0x04 unsigned char c = 5; void toggle_bit3(void) { c ^= BIT3; }
ECE 447: Setting a bit at a given memory location #define BIT3 0x04 #define ADDR 0x1005 void set_bit3(void) { unsigned char *ptr; ptr = (unsigned char *) ADDR; *ptr |= BIT3; }