CEG411/611 Microprocessor Based System Design What is this course about? Computer : Processor, Memory, I/O Microprocessor versus microcontroller Embedded.

Slides:



Advertisements
Similar presentations
EE 362 Microprocessor Systems and Interfacing © 1-1 Lecture 1: Introduction to Microprocessor Based Systems Microprocessor Architecture Microprocessor.
Advertisements

ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Assembler Programming Chapter 6. EEL-4746 Best Practices.
68HC11 Polling and Interrupts
The 68HC11 Microcontroller Minnesota State University, Mankato
H. Huang Transparency No.1-1 The 68HC11 Microcontroller Chapter 1: Introduction to 68HC11 The 68HC11 Microcontroller.
Chapter 1 Introduction to HCS12/MC9S12. Computer Hardware Organization What is a Computer? Software Hardware.
Programming the HC12 in C. Some Key Differences – Note that in C, the starting location of the program is defined when you compile the program, not in.
Railway Foundation Electronic, Electrical and Processor Engineering.
EET 2261 Unit 2 HCS12 Architecture
Railway Foundation Electronic, Electrical and Processor Engineering.
© 2010 Kettering University, All rights reserved..
Lab 1 – Assembly Language and Interfacing Start date: Week 3 Due date: Week 4 1.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
Machine Instruction Characteristics
ME4447/6405 The George W. Woodruff School of Mechanical Engineering ME4447/6405 Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics.
Revised: Aug 1, ECE 263 Embedded System Design Lessons 23, 24 - Exceptions - Resets and Interrupts.
EECC250 - Shaaban #1 Lec # 20 Winter Microcontroller Basics A microcontroller is a small, low-cost computer-on-a-chip which usually includes:
Stacks and Subroutines. Some example stacks Stacks and subroutine usage The stack is a special area of the random access memory in the overall memory.
Objectives Implement pointers using indexed addressing modes Use pointers to access arrays, strings, structures, tables, and matrices Present finite-state.
ECE 265 – LECTURE 8 The M68HC11 Basic Instruction Set The remaining instructions 10/20/ ECE265.
Interrupts and reset operations. Overview  Introduction to interrupts – What are they – How are they used  68HC11 interrupt mechanisms – Types of interrupts.
ELE22MIC Lecture 15 Applications of Parallel Input Output (I/O)
9-1 EE 319K Introduction to Microcontrollers Lecture 9:I/O Synchronization; LCD Interfacing; Implementing Local Variables using a Stack Frame; Parameter.
6-1 EE 319K Introduction to Microcontrollers Lecture 6: Indexed Addressing Mode and Variants, Functional Debugging, Arrays, Strings.
ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.
ME4447/6405 The George W. Woodruff School of Mechanical Engineering ME4447/6405 Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
ECE 265 – LECTURE 5 The M68HC11 Basic Instruction Set 12/8/ ECE265.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
1 Stacks, Subroutines, I/O Routines Today: First Hour: Stacks, Subroutines –Section 3.9,3.10 of Huang’s Textbook –In-class Activity #1 Second Hour: I/O.
Motorola MC68HC811E2 Microcontrollers
1 Basic Microcontroller System Chapter 2 Introduction to M68HC11 Hardware.
1 ECE 372 – Microcontroller Design Assembly Programming HCS12 Assembly Programming Addressing Modes Stack Operations Subroutines.
8-1 EE 319K Introduction to Microcontrollers Lecture 8:Fixed Point Numbers, Local Variables, Binding, Allocation, Access, Deallocation.
Ch.2 Intro. To Assembly Language Programming
ECE Lecture 21 Typical Assembly Language Program Bugs.
Ch.2 Intro. To Assembly Language Programming From Introduction to Embedded Systems: Interfacing to the Freescale 9s12 by Valvano, published by CENGAGE.
ECE 447: Lecture 16 Common Errors & Good Programming Style.
Advanced Assembly Language Programming
ECE 447: Lecture 11 Introduction to Programming in Assembly Language.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
Embedded Systems Lecture 5 January 25 th, 2016.
Subroutines and Stacks. Stack The stack is a special area in memory used by the CPU to store register information or general data information during program.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
Physics 413 Chapter 4: Advanced Assembly Programming.
1 Subroutines Advanced Programming. 2 Top-Down approach to problem solving Algorithm step by step description of how to solve a problem Divide and Conquer.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
Revised: Aug 1, EE4390 Microprocessors Lessons 11, 12 Advanced Assembly Programming.
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
ELE22MIC Lecture 17 Writing 68HC11 software 68HC11 Main Timer System –Output Compare –What is different about TOC1?
5-1 EE 319K Introduction to Microcontrollers Lecture 5: Conditionals, Loops, Modular Programming, Sub- routines, Parameter passing.
ELEC 418 Advanced Digital Systems Dr. Ron Hayne
ELE22MIC Lecture 18 Writing 68HC11 software 68HC11 Main Timer System
ECE 3430 – Intro to Microcomputer Systems
Addressing Modes in Microprocessors
68HC11 Interrupts & Resets.
HC11 Programming.
Control Structure Applications
ELE22MIC Lecture 18 Writing 68HC11 software 68HC11 Main Timer System
Wed. Sept 6 Announcements
Control Structure Applications
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME4447/6405 Microprocessor Control of Manufacturing Systems and
ECE 3430 – Intro to Microcomputer Systems
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ECE 447: Lecture 15 Stack Operations.
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
Presentation transcript:

CEG411/611 Microprocessor Based System Design What is this course about? Computer : Processor, Memory, I/O Microprocessor versus microcontroller Embedded Systems Processor I/O Memory Bus

EVB (Evaluation Board): Axiom CSM12C32 ( Chip: MC9S12C32 from Freescale (formerly, a Motorola division) –For chip documentation in PDF files, see C:\68HC12\ 9S12C32_Chip 68HC12 versus 68HCS12

Lab 1 Preparation Monitor, MON12, Monitor commands (Sec ) MD, MM, LOAD, CALL Address versus data Hexadecimal number system and Memory map C, Assembly, Machine Code ICC12 and as12 Step by step instructions S record file, list file, map file

Sample C Programs C review (Chapter 5, sample_c.c) –main( ), function call –data types (char, unsigned char, int, short, long, float) –Condition check (true, false, if, else) –for loop, while loop –putchar(), puts(), printf() tone.c : timer, output compare (Sec 8.6) switch_LED.c : simple parallel port usage

Let Y be a generic register which can be PORTA, PORTB, PORTE, PTAD, PTT, PTP, PTS, PTM, DDRA, DDRB, and so on. Contents of Y: Y 7 Y 6 Y 5 Y 4 Y 3 Y 2 Y 1 Y 0 Output (Use Y 1 as an example) –Set bits : Y |= 0x02; –Clear bits : Y &= ~0x02; or Y &= 0xFD; –Toggle bits : Y ^= 0x02; Input –Check if set : if( Y & 0x02 ) –Check if clear : if( !(Y & 0x02)) –Wait until set : while( !(Y & 0x02) ) ; –Wait until clear: while(Y & 0x02) ; Simple Parallel Port Usage

A simple parallel port usage example: switch_LED.c MC9S12C32 PB4 PE0 PP5 PA0 SW1VCCSW2VCC LED1 VCC LED2

Measuring Pulse Width Without Using Input Capture Use while loops and read TCNT to get T1, T2 If(T2 > T1) T = T2 – T1; else T = 0xffff – T1 + T2 + 1; Timer Overflow? 6812

Interrupt Programming Interrupt versus polling Interrupt programming –Write an ISR (interrupt service routine) –Register the ISR, p. 268 –Enable ISR (locally and globally) tone_interrupt.c example On EVB, pressing the reset button clears the MON12 (user) interrupt vector table contents Chapter 6

ADC (Chapter 12) ADC basics, a 2-bit ADC example, Sec , Example 12.1 Analog = V L + Digital * (V H -V L )/(2 N -1) ADC Internal: Successive Approximate Method, Sec Signal Conditioning Circuits based on OP Amp: Sec & ADC Programming: Sec –adc_scan.c

ADC Timing (ATDCTL4), p. 602 ATD Clock = Bus Clock / [2(PRS+1)] –Bus Clock : 24 MHz on EVB –PRS : bits 4 to 0 of ATDCTL4 ATD Conversion Time per Sample = [2 + 2(SMP+1) + B] ATD clock cycles –SMP : bits 6 and 5 of ATDCTL4 –B: 8 or 10 (for 8-bit and 10-bit ADC, respectively)

Assembly Programming Why assembly programming? –Understand computer/C internal operations –More efficient coding CPU Registers (Sec. 1.8) D (A:B) : accumulator; X, Y: index registers; SP : Stack Pointer; PC: Program Counter CCR : Condition Code Register S X H I N Z V C

Memory Addressing – Big-Endian versus Little-Endian – Memory Mapped I/O A sample assembly program (tonevb.asm) –Label, Opcode, Operands, Comments –Assembler directives (e.g., ORG) CPUMemory 16-bit Address 8/16-bit Data

Load/Store Instructions (Sec ) and Addressing Modes (Sec. 1.9) Examples –LDAA #$55 immediate mode –LDAA #55 immediate mode –LDD #$0F20 immediate mode –LDAA $55 direct mode –LDAA $0F20 extended mode –LDD $0F20 extended mode –LDAB 3,X indexed mode LDX, LDY, LEAS, LEAX, LEAY –LEAS -4,SP : SP ← (SP)-4 (to allocate space for local variables for subroutines) STAA, STAB, STD, STS, STX, STY

Example: int m, n; // assume m is at $3000 // assume n is at $3002 m = n + 5; LDD $3002 ADDD #5 STD $3000 How about char instead of int?

More instructions (Sec. 1.11) –Transfer (register to register) and Exchange (swap registers): TAB, TAP, TBA,....; EXG, XGDX, XGDY –Move (memory to memory): MOVB, MOVW –Add and Subtract (always involves CPU registers) Register + Register : ABA, ABX, ABY Register + Memory : ADCA, ADCB, ADDA, ADDB, ADDD Register – Register : SBA Register – Memory : SBCA, SBCB, SUBA, SUBB, SUBD

Assembler Directives (Sec. 2.3) –ORG (Origin), EQU (Equate) –Specify Constants: fcb (Form Constant Byte, or db), fcw (Form Constant Word, or dw), fcc (Form Constant Character, String), fill –Reserve Space: rmb (reserve memory byte), rmw (reserve memory word) Examples ORG $3800 array fcb $11,$22,$33,’5,25,100 buf rmb 20 msg fcc “Hello World” tmp fill $11,20

Program Loops (Sec. 2.6) –Loop constructs –Branch conditions/instructions compare (A to B, a register to a memory) or test (A, B, or a memory location) S X H I N Z V C CCR branch (BRA, BEQ, BNE, BLS,...)

Examples 2.14 (p. 68), 2.15 –Draw flowchart –Revise flowchart Example 2.17 –BRCLR oprand,mask,label branch to label if the bit(s) is (are) clear while(!(TFLG1 & 0x01)); // wait until flag is set // the above C statement is equivalent to here BRCLR $004E,$01,here Note that $004E is the address of TFLAG1 –BRSET oprand,mask,label

Subroutine Calls (Chapter 4) Stack, Stack Pointer, Push, Pull –PSHA, PSHB, PSHD, PSHX, PSHY : Decrement (SP) first, then write data –PULA, PULB, PULD, PULX, PULY : Read data first, then increase (SP) Example: Ex. 4.1 LDS #$3E00 LDAA #$3B LDD #$302F PSHA PSHD

BSR, JSR, RTS, Caller, Callee (Sec. 4.4) BSR SORT SORT RTS Parameter Passing, Result Returning, and Allocation of Local Variables (Sec. 4.5) –Using registers versus using stack

Stack Frames (Sec. 4.6), Ex. 4.3 Example C versus Assembly Local Variables Saved Registers Return Address Incoming Parameters & Return Values 1. Caller: PSHX 2. Caller: BSR 3. Callee: PSHD 4. Callee: LEAS -4,SP

void main() { int a, b; a = sum(b, 3); } int sum(int x, int y) { int s; s = x + y; return s; } LDD 5,sp *** b PSHD LDD #3 PSHD LEAS -2,sp *** result JSR Sum.... Sum: PSH... *** save reg LEAS -2,sp *** s......

More Timer Functions Timer Overflow (p. 367): TSCR2 bit 7 (TOI), TFLAG2 bit 7(TOF) Input Capture (Sec. 8.5) and Examples Real-Time Interrupt (Sec. 6.7): CRGINT bit 7 (RTIE), CRGFLG bit 7 (RTIF) n = RTICTL bits 6-4; m = RTICTL bits 3-0 OSCCLK (16MHz on EVB)/[(m+1)2 (n+9) ] Pulse Accumulator (Sec. 8.7): a 16-bit counter Pulse Width Modulation (PWM) (Sec. 8.10)

Parallel Ports, I/O Synchronization and Handshaking (Sec. 7.4) –Strobe vs. Handshake –Input/Output Handshaking Protocols Serial Interface (Chap. 9 & 10): –SCI vs. SPI –SCI: RS-232, Start-bit, Stop-bit, Parity –SPI (p.482): SCK, SS, MISO, MOSI –Other Serial Interface Protocols: USB, PCI Express, SATA, Ethernet