ME 475 Lab2 Introduction of PIC and Programming Instructor: Zhen Wang 2013.1.25
Outline Lecture Introduction of PIC microcontroller Programming cycle Read CH5 Programming guidelines Read CH6 Sample program for each module 2
PIC microcontroller Microcomputer systems 3
PIC microcontroller A microcontroller is a simplified version of a similar architecture, placed on one chip 4
Main features Program memory and Data memory An accumulator (also called the working register, W) Separate data bus for program memory data memory. 40 pin packages 5 bidirectional I/O ports 15 interrupts 35fixed width instructions 8 A/D input channels Implemented with Parallel Slave Port 5
Separate data bus Harvard architecture Concurrent instruction fetching and data accessing Von Neumann architecture One operation at one time 6
Memory organization 8K 14 bit words of Flash program memory, 368 bytes of data RAM, 256bytes of data EEPROM 8 level x 13 bit wide hardware stack. 7
Data RAM Divided into 4 banks contains the General Purpose Registers (GPR) and thespecial Function Registers (SFR). 8
Register file map 9
Data RAM SFRs Control the core" operation of the microcontroller GPRs Each has accessible and unique address. 8 bit wide in memory space 10
Data RAM Addressing of the entire data memory directly using the absolute address of each register file (7 bit wide), or indirectly through the INDirect File (INDF) register and the File Sl Select Register (FSR) 11
Example of SFR Status Register (8 bit wide) arithmetic status of the ALU, the Reset status the bank select bits for data memory. Description of each register e is aaabe available in PIC manual. 13
14
Bank1: 01 Bank1: 01 Register file address: 83 (HEX) 10000011(Binary) 9 bit address for direct addressing: 0110000011
Flash program memory and ROM Thedata EEPROM and Flash program memory is readable and writable during normal operation. Not directly mapped in the register file space indirectly addressed d through hthe several SFR (EECON1, EECON2, EEDATA, EEDATH, EEADR, EEADRH) 16
Working register (W) Also called accumulator Aregisterthat is used to store the intermediate calculation results. Not part of the program or data memory space 17
I/O ports 18
I/O ports Bidirectional Five data direction registers: TRISA, B, C, D, E For PORTA, TRISA bit (= 1), PORTA pin being an input TRISA bit (= 0), PORTA pin being an output 19
I/O ports Multi functional Some pins for I/O ports are multiplexed with an alternate functionfor for the peripheral features on the device. E.g. AN analog input PSP parallel slave port 20
I/O ports 21
Instruction set 35 single word instructions Each instruction is a 14 bit word include: an opcode which h specifies the instruction ti type and one or more operands which further specify the operation of the instruction. 22
Instruction set 23
Instruction set In general, the instruction set is comprised of three basic categories: Byte oriented operations operation on W registor and indexed register E.g. addwf (add W and F) Bit oriented operations Operation on a register number and a bit number E.g. BCF (Bit Clear f) Literal and control operations: Include Call, Goto and Return 24
Control transfers 25
Control transfers 26
INSTRUCTION SET 27
28
Programming cycle 29
New folder with software 30
Copy the source code 31
32
Assemble source code 33
Assemble source code 34
Assemble source code 35
Assemble source code 36
Assemble source code 37
Downloading program 38
Downloading program 39
Downloading program 40
Downloading program 41
Downloading program 42
Downloading program 43
Downloading program 44
Downloading program 45
Downloading program 46
Downloading program 47
Downloading program 48
Downloading and running program 49
Running program 50
Downloading and running program 51
Thanks 52