Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 447: Lecture 3 Microcontroller Programming in C.

Similar presentations


Presentation on theme: "ECE 447: Lecture 3 Microcontroller Programming in C."— Presentation transcript:

1 ECE 447: Lecture 3 Microcontroller Programming in C

2 ECE 447: Class Exercise 1 Write a function in C that transfers 512 bytes of data from the internal EEPROM of MC68HC11E9 to the block of external RAM starting at address $6000.

3 ECE 447: 68HC11E9 Memory Map $0000 $1000 $B600 $FFFF $0000-$01FF 512 bytes RAM $1000-$103F 64 bytes I/O registers $B600-$B7FF 512 bytes EEPROM Expanded bus mode $D000 $2000-$B5FF 37.5 kbytes $D000-$FFFF 12 kbytes ROM External RAM recommended for use $2000 recommended for use

4 ECE 447: Default Memory Map $0000 $1000 $B600 $FFFF $0000-$01FF 512 bytes RAM $1000-$103F 64 bytes I/O registers $B600-$B7FF 512 bytes EEPROM Expanded bus mode $D000 Program area - text $2000 $6000 Data area – data External RAM $2000-$5FFF 16 kbytes $6000-$B5FF 21.5 kbytes

5 ECE 447: Class Exercise 2 Write a program in C that continuously transfers data from PORT E to PORT C of MC68HC11.

6 ECE 447: Organization of MC68HC11 CPU RAM ROM EEPROM TIMER A/D SPI SCI PORT APORT BPORT CPORT DPORT E 8 8 (4) 8 2 4 6 8 332

7 ECE 447: Class Exercise 3 Write a program in C that continuously scans pin PE5 of PORT E of MC68H11. Whenever a falling edge is detected at PE5, the microcontroller should clear the pin PC4,and toggle pin PC2 of MC68HC11.

8 ECE 447: Running program continuously while (1) { ……….. } Sequence of operations repeated continuously

9 ECE 447: Setting and Clearing a bit Setting a bit #define BIT7 0x80 unsigned char c = …; c |= BIT7; Clearing a bit #define BIT7 0x80 unsigned char c = …; c &= ~BIT7;

10 ECE 447: Toggling a bit #define BIT7 0x80 unsigned char c = …; c ^= BIT7;

11 ECE 447: Testing a bit #define BIT7 0x80 unsigned char c = …; if (c & BIT7) ….. ; else ….. ;

12 ECE 447: Writing data to / Reading data from a particular memory location unsigned char * ADCTL_ptr = (volatile unsigned char *) 0x1030; unsigned char result; *ADCTL_ptr = …; result = *ADCTL_ptr; Method 1

13 ECE 447: Writing data to / Reading data from a particular memory location #define ADCTL (* (volatile unsigned char *) 0x1030); unsigned char result; ADCTL = …; result = ADCTL; Method 2

14 ECE 447: Writing data to / Reading data from a particular memory location #include “hc11e9.h” unsigned char result; ADCTL = …; result = ADCTL; Method 3 (not allowed in Experiment 1)

15 ECE 447: Waiting for a bit to set #define CCF 0x80 #define ADCTL (* (volatile unsigned char *) 0x1030); while (!(ADCTL & CCF)) ; do nothing


Download ppt "ECE 447: Lecture 3 Microcontroller Programming in C."

Similar presentations


Ads by Google