Teaching Assistants S. : F.G : M.G : B. : A.K : Serdar FT Fatih GKE Murat GENTAV Bura ZKAN Alper KILI (office: A402) (office: A301) (office: A401) (office: A401) (office: Security Lab)
2/28
Todays Outline
Introduction to PIC Lab Boards Introduction to PIC arhictecture PIC Assembly Language (Part I)
CEng336
3/28
Microcontroller vs Microprocessor
Microcontroller: Very little external support hardware. Most RAM, ROM and peripherals on chip. Computer on a chip, or System on chip (SOC) Microprocessor: Requires external support hardware E.g., External RAM, ROM, Peripherals.
CEng336
4/28
CEng336
5/28
We will use
CEng336
6/28
PIC Architecture
PICs use the Harvard Architecture Used mostly in RISC CPUs Separate program bus and data bus: can be different widths! For example, PICs use: Data memory (RAM): a small number of 8bit or 16bit registers Program memory (ROM): 12bit, 14bit, 16bit or 24bit wide (in EPROM, FLASH, or ROM)
CEng336
7/28
PIC16F877
14bit core - 35 instructions 200ns instruction time (Tclk = 20MHz) 8,092 14bit FLASH program memory 368 8bit data memory or registers (File registers) 256 8bit EEPROM (nonvolatile) data registers 8 level hardware stack Interrupt capability (up to 14 sources) 33 pin I/O (for 40 pin package) 3 Timer/Counter modules Timer0: 8-bit Timer1: 16-bit Timer2: 8-bit Two Capture, Compare, PWM modules - Capture: 16-bit - Compare: 16-bit - PWM: max. resolution is 10-bit 10-bit 8 channel Analog-to-Digital Converter Synchronous Serial Port (SSP) with SPI and I2C Universal Synchronous Asynchronous Receiver Transmitter (USART/SCI) with 9-bit address detection Parallel Slave Port (PSP) 8-bit
CEng336
8/28
For PIC16F877: MPLAB IDE with PIC Assembler SDCC - Small Device C Compiler open source development tool (from command line) For PIC18F4520: We will use FreeRTOS or PICOS18 open source development tool. UsbPicProg (install this version 0.4.0) To program the PIC on the development board
http://sourceforge.net/projects/usbpicprog/files/usbpicprog-software/usbpicprog-0.4.0-software/
Software Tools
CEng336
9/28
Resources
Datasheet (s) MOST IMPORTANT!!! Reference Book: Design with PIC Microcontrollers, John B. Peatman, Prentice Hall,1998. Serdar, Fatih, Murat, Bura and Alper Internet 336 news group Vendors web site www.microchip.com, http://forum.microchip.com Your friends (not recommended )
CEng336 10/28
HWs
4 HWs (3 hws with PIC16F877, last hw with PIC18F4520) 1st homework (7pts) and 2nd homework (8pts) will be coded in PIC assembler language. 3rd homework (10pts) will be coded in SDCC (Small Device C Compiler). 4th homework (15pts) will be on real time operating systems, FreeRTOS or PICOS18 will be used.
CEng336 11/28
PIC16F877 Program Memory Organization 13 Bit Program Counter capable of addressing an 8K x 14 program memory 8 level stack Reset Vector: The program comes to this address in the first start or after the microcontroller is reset. Interrupt Vector: When an interrupt occurs, the program automatically comes to this address.
CEng336 12/28
The upper 2 bits of the address are provided by PCLATH<4:3>. When doing a CALL or GOTO instruction, the user must ensure that the page select bits are programmed so that the desired program memory page is addressed.
CEng336
13/28
CEng336
15/28
CEng336
16/28
INSTRUCTION FORMATS
Some General Properties: Instructions are encoded in binary in ROM. The instructions are fixed format, each occupying 14 bits. Categories of instructions: Byte-oriented file register operations Bit-oriented file register operations Literal and Control operations
CEng336
17/28
INSTRUCTION FORMATS
Byte-oriented file register operations
CEng336
18/28
INSTRUCTION FORMATS
Example
ADD W register content to 47h address content and save the result to W register 000 111 0 100 0111
Destination is W
W := W + Reg[47h]
CEng336 19/28
INSTRUCTION FORMATS
Example
ADD W register content to 47h address content and save the result to 47h address 000 111
Only difference from previous instruction
100 0111
Destination is Reg[47]
Reg[47h] := W + Reg[47h]
CEng336 20/28
INSTRUCTION FORMATS
Bit-oriented file register operations
CEng336
21/28
INSTRUCTION FORMATS
Example
Clear 5th bit of 29h register content 0100 101 010 1001
Bit 5 is to be cleared
CEng336
22/28
INSTRUCTION FORMATS
Literal operations
CEng336
23/28
INSTRUCTION FORMATS
Example
ADD 0x17 value to W register content and save the result to W register 11 1110 0001 0111
CEng336
24/28
INSTRUCTION FORMATS
Control operations
CEng336
25/28
INSTRUCTION FORMATS
Example
GOTO
101
0x32
000 0011 0010
CEng336
26/28
Next Week
PIC Instruction Set will be continued MPLAB IDE will be introduced Demo programs and programming PIC
27/28
Questions???
28/28