PIC Short Course
PIC Short Course
Introduction
Web Resources
Course: http://psut.edu.jo/sites/qaralleh Text book:
Designing Embedded Systems with PIC Microcontrollers (principles and applications), 1st Ed. By: Tim Wilmshurst published by Newnes, 2007.
http://www.elsevier.com/wps/find/bookdescription.c ws_home/708502/description#toc
What is a Microcontroller?
Mini-Computer
Microprocessor
The Brains Arithmetic Logic Unit (ALU) Control Unit
PIC Architecture
Memory
CPU
Timer 0
Timer 1
Timer 2
PWM 1
PWM 2
A Computer on a chip
Microcontroller Families
Counter/Timer modules.
Modules 0,2 (8-Bits) Modules 1,3 (16-Bits)
CCP Modules. I2C/SPI serial port. USART port. ADC 10-bits with 8-way input multiplexer. EEPROM 256 Bytes
Reset
A reset puts the PIC in a well-defined initial state so that the processor starts executing code from the first instruction. Reset can results from :
External reset by MCLR pulled down. Reset on power-up Reset by watchdog timer overflow Reset on power supply brown-out
Microprocessor Unit
Includes Arithmetic Logic Unit (ALU), Registers, and Control Unit
Example ADDWF F, d, a
Registers
Bank Select Register (BSR)
4-bit register used in direct addressing the data memory
Memory
Control signals
Read and Write
PIC18F452/4520 Memory
Program memory with addresses (Flash) Data memory with addresses
FFF=212=16x256=4096=4K
Program Memory
The RESET vector address is at 0000h and the interrupt vector addresses are at 0008h and 0018h.
A 21-bit program counter is capable of addressing the 2Mbyte program memory space.
PIC18F452 each have 32 Kbytes of FLASH memory. This means that it can store up to 16K of single word instructions
Accessing a location between the physically implemented memory and the 2-Mbyte address will cause a read of all 0s (a NOP instruction).
Data Memory up to 4k bytes Divided into 256 byte banks Half of bank 0 and half of bank 15 form a virtual bank that is accessible no matter which bank is selected
Bank 1 GPR
1FFh 200h
Bank 2 GPR
2FFh
D00h
Bank 13 GPR
DFFh E00h
256 Bytes
Bank 14 GPR
EFFh F00h F7Fh F80h FFFh
Data Memory also known as Register File We will discuss the access to every region later, while talking about PIC18 instructions
FFF=212=16x256=4096=4K
8 bits of the 16-bit instruction specify any one of 256 locations The 9th bit specifies either the Access Bank (=0) or one of the banks (=1)
25
Each FSR has an INDF register associated with it The INDFn register is not a physical register. Addressing INDFn actually addresses the register whose address is contained in the FSRn register.
28
LFSR 02, num1 ;load FSR2 with the add. of num1 MOVWF INDF2, W ; move WREG to the register ; pointed by FSR2
29
30
31
SFRs Examples
I/O Ports
35
36
37
40
Hardware:
PORTC
bidirectional (input or output) port; should be setup as output port for display
Illustration (2 of 5)TRISC=0
Interfacing LEDs to PORTC Port C is F82H Note that PORT C is set to be an output! Hence, TRISC (address 94H) has to be set to 0
Illustration (3 of 5)
Program (software)
Logic 0 to TRISC sets up PORTC as an output port Byte 55H turns on alternate LEDs
MOVLW 00 ;Load W register with 0 MOVWF TRISC, 0 ;Set up PORTC as output MOVLW 0x55 ;Byte 55H to turn on LEDS MOVWF PORTC,0 ;Turn on LEDs SLEEP ;Power down