microcontrollers
Microcontrollers
An integrated circuit that contains many of the same items that a desktop computer has, such as CPU, memory, etc., but does not include any human interface devices like a monitor, keyboard, or mouse. Microcontrollers are small (micro) and designed for machine control (controller) applications, rather than human interaction.
WorldWide Microcontroller Shipments (in millions of dollars $) '94 '95 '96 '97 '98 '99 '00 4-bit $1,761 1,826 1,849 1,881 1,856 1,816 1,757 8-bit 4,689 5,634 6,553 7,529 8,423 9,219 9,715 16-bit 810 1,170 1,628 2,191 2,969 3,678 4,405 (2006) A new comprehensive analysis on the Microcontroller market predicts that 2007 worldwide microcontroller revenue will increase by 10 percent. 2014 The fastest growing segment within microcontrollers is the 32-bit market, which is estimated to be growing at a compound annual growth rate of 16 percent each year, compared to the overall market for microcontrollers which should garner around 8 percent growth each year on average.
Average Semiconductor Content per Automobile (in dollars $) '94 '95 '96 '97 '98 '99 '00 $ 1,068 1,237 1,339 1,410 1,574 1,852 2,126 This Car Runs on Code (ieee) LOC (2007)High growth application areas for automotive semiconductors include safety (airbags, cruise control, collision avoidance, antilock brakes) and cockpit electronics (entertainment, telematics, instrumentation, phones). Electrical and electronics content, including software, represents around 20 percent of the cost of the average vehicle. A lower-priced vehicle built in 2004 probably has 25 to 30 electronic control modules, including 150 to 180 components, while higher-priced vehicle might contain 70 control modules with more than 400 components.
Examples: controlling traffic lights CD players simple game consoles many children's games TV remote controls microwave oven timers clock radios car engine management systems central heating controllers environmental control systems

Microsim intro
Get the Microsim software ! Register using the Clarion University school code (ask me for ID#)
Read the documentation - it is VERY good...
The simulator consists of: HW CPU - can alter speed 256 bytes of random access memory (RAM) VDU 64 bytes of output : C0 thru FF Seven IO ports (00 thru 06) used for simulated peripherals Four 8-bit user registers: al, bl, cl, dl Three special registers: ip, sp (stack), sr (status) On Interrupt (02) triggered by a hardware timer (simulated) An assembler Ability to single step through or continuously run programs. On-line help
In real life,RAM would be replaced by ROM and the system would run one program hard wired into the ROM.
I/O Port Numbers: 00 - real keyboard 01 - lift 02 - seven seg 03 - heater/thermostat 04 - maze 05 - stepper motor 06 - lift 07 - virtual keyboard 08 - keypad
RAM Addresses: 00 - FF ======= 00 - BF => used for program & data storage C0 - FF => 64 bytes for VDU (4 rows x 16 chars) C0 is upper left char, C1 is next char, etc

Programming Microsim
Can use register to output binary codes that will control the device associated with that I/O port. ========================================================== 7 segment display - Uses port2 (Out 2) Outputs whatever is in al register 1 in lo bit activates right, 0 in lo bit activates left
This will light up left display - all segments mov al, FE out 02
This will light up right display - 3 segments mov al, A3 out 02

Controlling the peripheral devices


The LIFT (elevator) is controlled via I/O port 6. Code that controls a lift: ========================= mov al,0 out 06 ; clear device register loop: in 06 ; Test for lift at top push al ; done 'cause you can't mov bl,al pop bl ; bl now has what was in al ; now create a mask and test and bl,5 ; Test for MotorUp & TopSwitch cmp bl,5 jz StopTop in 06 ; Test lift at bottom push al pop bl and bl,A ; Test for MotorDown AND BottomSwitch cmp bl,A jz StopBot push al pop bl and bl,10 ; test for the Call Down button jnz CallDown push al pop bl and bl,20 ; test for the Call Up button jnz CallUp jmp loop

Programming for Asynchronous Events: Interrupts
Interrupts ========== When a hardware component (ex: a peripheral device) needs CPU attention, the controller associated with this component: 1. sends Interrupt Request (INTR) signal to the CPU 2. puts Interrupt Number (0 to FFh) on data bus CPU uses interrupt number to index into interrupt vector table (IVT) Each entry of this table is called an interrupt vector Each entry contains address of Interrupt Handler (ISR) CPU transfers control to the corresponding ISR Interrupt returns with an IRET

microsim: STI turns on HW interrupts Interrupt is always INT 02 (only 1 interrupt) Vectors to address 2 MUST have an address of an interrupt routine at address 2 Use ORG to put routine at a particular address Inside the interrupt handler save registers (push) save flags (pushf) process restore flags (popf) restore registers (pop) IRET from interrupt
EXAMPLE ======= Jmp Start ; jump over vector DB 40 ; address of isr Start: STI ; turn on interrupts Rep: ; ; regular code goes here ; JMP Rep ORG 40 ; int 02 ; ; interrupt code goes here ; IRET END

;------------------------ ; ; HWStepVDUint.asm ; ;------------------------ ; An example of using hardware interrupts. ; This program spins the stepper motor continuously and ; steps the traffic lights on each hardware interrupt. ; WHAT HAPPENS WHEN CLOCK IS ... S L O W ??? ; -------------------------------------------------------------- JMP Start ; Jump past table of interrupt vectors DB 50 ; Vector at 02 pointing to address 50 - DON'T MOVE DB "HI!" ; Load text string into RAM DB 0 ; Null terminated Start: STI ; Set I flag. Enable hardware interrupts MOV AL, 11 ; 11 hex = 00010001b - for stepper start Rep: OUT 05 ; Stepper motor ROR AL ; Rotate bits in AL right 00010001,10001000,01000100 JMP Rep ;----------------------------------- ; --- INT 02 ORG 50 push al ; Save AL onto the stack. push bl ; Save BL onto the stack. pushf ; Save flags onto the stack. MOV AL, 84 ; Red Green OUT 01 ; Send AL data to traffic lights MOV AL, 30 ; Green Red OUT 01 ; Send AL data to traffic lights MOV CL, C0 ; Video ram base address MOV BL, 03 ; Offset of text string WRITE: ; Text output to vdu MOV AL,[BL] ; Text pointer into AL CMP AL,0 ; At end yet JZ END1 ; Jump out of loop MOV [CL],AL ; AL into video memory INC CL ; Next video location INC BL ; Next text character JMP WRITE ; Not there yet END1: popf ; Restore flags to their previous value pop bl ; Restore BL to its previous value pop al ; Restore AL to its previous value IRET END