PIC Microcontroller - 1

Transcription

PIC Microcontroller - 1Introduction to PIC MicrocontrollerPIC MicrocontrollerProf. Yan Luo, UMass Lowell1

Moving Towards EmbeddedHardwareTypical components of a PC: x86 family microprocessorMegabytes or more of main (volatile) memoryGigabytes or more of magnetic memory (disk)Operating System (w/ user interface)Serial I/OParallel I/OReal-time clockKeyboardVideo DisplaySound cardMouseNIC (Network Interface Card)etc.PIC MicrocontrollerProf. Yan Luo, UMass Lowell2

Overview of Microcontrollers Basically, a microcontroller is a device which integrates a number of thecomponents of a microprocessor system onto a single microchip.Reference: 1/micro01notes.html#1.4PIC MicrocontrollerProf. Yan Luo, UMass Lowell3

The PIC 16F87x SeriesMicrocontrollerSome of the characteristics of the PIC 16F87x series High performance, low cost, for embedded applicationsOnly 35 instructionsEach instruction is exactly one word long and is executed in 1cycle (except branches which take two cycles )4K words (14bit) flash program memory192 bytes data memory (RAM) 128 bytes EEPROM datamemoryEight level deep hardware stackInternal A/D converter, serial port, digital I/O ports, timers, andmore!PIC MicrocontrollerProf. Yan Luo, UMass Lowell4

What these changes meanwhen programming? Since there is no DOS or BIOS, you’ll have towrite I/O functions yourself. Everything is donedirectly in assembly language.Code design, test, and debug will have to bedone in parallel and then integrated after thehardware is debugged.Space matters! Limitations on memory maymean being very clever about algorithms andcode design.PIC MicrocontrollerProf. Yan Luo, UMass Lowell5

PIC Microcontroller (PIC16F684) High performance, low cost, for embedded applications Low Power 8.5uA @ 32KHz, 2.0VPeripheral Features Only 35 different instructionsInterrupt capabilityDirect, indirect, relative addressing mode12 I/O pins with individual direction control10-bit A/D converter8/16-bit timer/counterSpecial Microcontroller Features Internal/external oscillatorPower saving sleep modeHigh Endurance Flash/EEPROM cellEtc.PIC MicrocontrollerProf. Yan Luo, UMass Lowell6

PIC16F684 Block DiagramPIC MicrocontrollerProf. Yan Luo, UMass Lowell7

PIC16F684 12 pins, 2048 instructions, 128 bytevariable memory, ADC, comparator,Timers, ICDPIC MicrocontrollerProf. Yan Luo, UMass Lowell8

Harvard vs Von Neumann Organization of program and datamemoryPIC MicrocontrollerProf. Yan Luo, UMass Lowell9

Instruction Pipelining It takes one cycle to fetch the instruction and another cycleto decode and execute the instructionEach instruction effectively executes in one cycleAn instruction that causes the PC to change requires twocycles.PIC MicrocontrollerProf. Yan Luo, UMass Lowell10

Program Memory Space 13-bit program counter toaddress 8K locations (only first2K is implemented in 16F684)PIC16F675 has only 1K (x14bit) program memory - theupper bit is simply ignoredduring fetches from programmemoryEach location is 14-bit wide(instructions are 14 bits long)RESET vector is 0000h When the CPU is reset, its PCis automatically cleared tozero.Interrupt Vector is 0004h PIC MicrocontrollerProf. Yan Luo, UMass Lowell0004h is automatically loadedinto the program counter whenan interrupt occurs11

Data Memory SpacePIC MicrocontrollerProf. Yan Luo, UMass Lowell12

Two Special addresses Reset Vector Address (0000h) When the CPU starts up from its reset state, its PC is automatically clearedto zero. Assign goto Mainline instructionMainlinecallMainLoopcallcall callgoto Initial;Initialize everythingTask1Task2;Deal with task1;Deal with task2LoopTimeMainLoop;Force looptime to a fixed value;repeatInterrupt Vector Address (0004h) 0004h is automatically loaded into the program counter when an interruptoccurs. Assign goto IntService instruction there: cause the CPU to jump to thebeginning of the interrupt service routine, located elsewhere in the memoryspace.PIC MicrocontrollerProf. Yan Luo, UMass Lowell13

Special Function RegistersPIC MicrocontrollerProf. Yan Luo, UMass Lowell14

Status RegisterPIC MicrocontrollerProf. Yan Luo, UMass Lowell15

PCL and PCLATH PC: Program Counter, 13 bitsPCL (02h): 8 bits, the lower 8bits of PCPCLATH (0Ah): PC Latch,provides the upper 5 (or 2) bitsof PC when PCL is written to1st example: PC is loaded bywriting to PCL2nd example: PC is loadedduring a CALL or GOTOinstructionPCLATH is used to for jumpingacross 2K pages (thus, notneeded in PIC16F684)PIC MicrocontrollerProf. Yan Luo, UMass Lowell16

Stack 8-level deep x 13-bit wide hardware stackThe stack space is not part of either program or data space andthe stackpointer is not readable or writable.The PC is “PUSHed” onto the stack when a CALL instruction isexecuted, or an interrupt causes a branch.The stack is “POPed” in the event of a RETURN, RETLW or aRETFIE instruction execution.However, NO PUSH or POP instructions !PCLATH is not affected by a “PUSH” or “POP” operation.The stack operates as a circular buffer: after the stack has been PUSHed eight times, the ninth pushoverwrites the value that was stored from the first push.PIC MicrocontrollerProf. Yan Luo, UMass Lowell17

AcknowledgementSome slides are revised based on lecturenotes used in WPI ECE 2801PIC MicrocontrollerProf. Yan Luo, UMass Lowell18

PIC Microcontroller Prof. Yan Luo, UMass Lowell 16 PCL and PCLATH PC: Program Counter, 13 bits PCL (02h): 8 bits, the lower 8 bits of PC PCLATH (0Ah): PC Latch, provides the upper 5 (or 2) bits of PC when PCL is written to 1st example: PC is loaded by writing to PCL 2nd example: PC is loaded during a CALL or GOTO instruction