Presentation is loading. Please wait.

Presentation is loading. Please wait.

Department of Electronic & Electrical Engineering Introduction to microcontrollers A microcontroller is a small computer on a single integrated circuit.

Similar presentations


Presentation on theme: "Department of Electronic & Electrical Engineering Introduction to microcontrollers A microcontroller is a small computer on a single integrated circuit."— Presentation transcript:

1 Department of Electronic & Electrical Engineering Introduction to microcontrollers A microcontroller is a small computer on a single integrated circuit containing: ● Processor core (CPU) ● Memory ● Programmable input/output peripherals. ● Program memory ● More... Microcontrollers are designed for embedded applications, in contrast to the microprocessors used in personal computers or other general purpose applications.

2 Department of Electronic & Electrical Engineering Applications ● Car industry ● Telephones ● Appliances ● Cameras ● Displays ● Gadgets ● Remote controls ● Washing machine

3 Department of Electronic & Electrical Engineering Remote schematic

4 Department of Electronic & Electrical Engineering Typical Input and output ● Switches ● LEDs ● LCD ● Sensors(light,sound, humidity) ● ADC (often in the chip) ● DAC ● Control Power Electronics

5 Department of Electronic & Electrical Engineering PIC microcontroller Made by Microchip Technology P eripheral I nterface C ontroller We will be using the PIC16F84A. ● Simple ( 35 instructions RISC ) ● Cheap ( ~ £3 ) ● Robust (I haven't broken one yet!!!)

6 Department of Electronic & Electrical Engineering Background reading The Quintessential PIC (quite advanced) Many simpler online articles on PIC programing.

7 Department of Electronic & Electrical Engineering VOltmeter demo

8 Department of Electronic & Electrical Engineering PIC 16F84A pin layout

9 Department of Electronic & Electrical Engineering Summary of pins OSC1/CLKIN: Oscillator crystal input. OSC2/CLKOUT: Oscillator crystal output. MCLR(inv): Master clear(reset)input. Programming voltage input. RA0 - RA3: Bi-directional I/O port. RA4/T0CKI: Bi-directional I/O port. Clock input to the TMR0 timer. RB0/INT : Bi-directional I/O port. External interrupt pin. RB1 - RB7: Bi-directional I/O port. VSS: Ground VDD: Positive supply(+2.0V to +5.5V)

10 Department of Electronic & Electrical Engineering PIC development.

11 Department of Electronic & Electrical Engineering

12

13

14 LAB INTRO DEMO

15 Department of Electronic & Electrical Engineering END OF LECT 1

16 Department of Electronic & Electrical Engineering Understanding the architecture To program a PIC you need to know about the device. Not like high level programming (Matlab JAVA C?). The internal structure of the device is called the architecture. The following slide shows the internal structure of the PIC16F84A Registers ALU Buses Memory (Program / User)

17

18 Department of Electronic & Electrical Engineering FOCUS program data IO

19 Department of Electronic & Electrical Engineering Registers Registers store binary numbers. In the PIC16F84A registers are 8 bit. Programming a PIC is mostly about moving information from one register to another and simple operation on the data. The WORKING register is a special register that is used a lot! The ARITHMETIC LOGIC UNIT (ALU) is used to operate on data. The STATUS register --- bits tell us about result of an operation.

20 Department of Electronic & Electrical Engineering ALU and working register STATUS REGISTER IN OUT ALU WORKING REGISTER

21 Department of Electronic & Electrical Engineering File Registers. The PIC has 2 banks of 8 bit registers. ● Some of these are special purpose ● IO ● Status ● interrupts ● 68 general purpose storage ● Store variables ● counters

22 Department of Electronic & Electrical Engineering Registers and addresses Each register has a unique address. Instructions use this address to read/write a particular register

23 Selects the bank 7 bits from opcode

24 Department of Electronic & Electrical Engineering Important registers STATUS : result of an operation (e.g. 0) also used to select register bank W: special register used to store result of operation (not got an address) PC: program counter. Address in program memory of next instruction. Usually incremented by 1 after instruction has been executed.

25 Department of Electronic & Electrical Engineering PIC16F84A program memory Program memory is separate from user data (Harvard architecture) ● 1024 words of program memory (instructions) ● Each instruction has 14 bits ● You can not read or write to program memory ● Execution starts at address 0

26 Department of Electronic & Electrical Engineering Opcode and Operands Instructions have ● opcode ➔ what it does (e.g. move something) ● operand(s) ➔ What it does it too (e.g. what we move)

27 Department of Electronic & Electrical Engineering Machine Instructions (PIC16F84A) ● Each instruction is 14 bits ● For example 000010 0 0100000 ● 000010 --- subtract the contents of a register from W ● 0 --- were we put result (W or file register) ● 010000 --- which register Definition: opcode (instruction) operand (data or address of data) 000010 0 010000

28 Department of Electronic & Electrical Engineering Assembly code We would go mad trying to program in machine code so we use ASSEMBLY CODE For example 000010 0 0100000 is written as subwf 20h, w Subtract W from register number 20h and put the result in W. A program called an assembler converters assembly code into machine code (MPLABX uses mpasm).

29 Department of Electronic & Electrical Engineering

30

31 Instruction Descriptions (page 37...)

32 Department of Electronic & Electrical Engineering mpasm reference (Assembly language). If you want to know more about the assembler please look at the E_Book mpasm_reference.pdf You can find this in the Resources folder. http://people.bath.ac.uk/eespjl/courses/Embedded/Resources/E-books/ Note that it might be easier to learn from the examples (depends on how your brain works). There are many features of mpasm that are not in the examples.

33 Department of Electronic & Electrical Engineering

34 Simple program (REDO) We want to do: NUM_2 = NUM_1 + 101; Assembly code: movf 15,w ; Copy the variable NUM_1 to W addlw D'101' ; Add the literal constant 101 decimal to it movwf NUM_2 ; Copy NUM_1+101 into NUM_2 Address Machine code: 0 001000 0 0001111 1 111110 0 1100101 2 000000 1 0010000 Column one is blank (unless it's a label)

35 Department of Electronic & Electrical Engineering Simulator doing prev slide

36 Department of Electronic & Electrical Engineering TALK ABOUT LAB1 PROGRAM.

37 Department of Electronic & Electrical Engineering Template program NUM EQU 0 ORG MOV..

38 Department of Electronic & Electrical Engineering Summary ● PIC Architecture (Harvard) ● Program memory ● DATA memory ● Machine code (01001101001101) ● Assembly code (movlw H'F') ● working register ● ALU ● status register.


Download ppt "Department of Electronic & Electrical Engineering Introduction to microcontrollers A microcontroller is a small computer on a single integrated circuit."

Similar presentations


Ads by Google