2 - 1 - CLO2 - Architecture and Features of PIC18F52 Microcontroller
2 - 1 - CLO2 - Architecture and Features of PIC18F52 Microcontroller
Features of
PIC18F52
Microcontroller
Introduction to PIC18F Series
Agenda Comparison Between PIC16F and PIC18F
Architecture of PIC18FXX2
Memory Organization
Clock and Reset System
Input/Output (I/O) Ports
Timers
Capture/Compare/PWM (CCP) Modules
Analog-to-Digital Converter (ADC)
Interrupt System
Exercises
Conclusion
Overview of PIC18F Series
Memory
PIC18F • Program memory addressing up to 2MB
• Data memory up to 4KB
Series Architecture
Hardware Features
Timers
Analog-to-Digital Converter (ADC)
Communication Protocols
Additional Features
Enhanceme Doubled Instruction Set
• Increased efficiency and performance
Memory Banks
• 16 banks available
• 256 bytes each
• 6 banks used in PIC18F452
General Purpose Registers (GPR)
• Used for temporary storage
Special Function Registers (SFR)
• Used for peripheral control
Bank Switching
• Handled by compiler
Clock and External Clock Sources
• Crystal
Reset • Resonator
• RC oscillator
Reset Mechanisms
• Power-on Reset (POR)
• Brown-out Reset (BOR)
• Watchdog Timer (WDT)
I/O Ports Overview
PORTA
• 7-bit
PORTB
• 8-bit
• Interrupt-on-Change
PORTC
• 8-bit
• USART, SPI, I2C
PORTD
• 8-bit
• Parallel Slave Port support
PORTE
Port Latches
Ports in Microcontrollers
• Include latches such as LATA and LATB
• Store the last written values
Timers Timer 0
• 8-bit or 16-bit mode
• External/internal clock
Timer 1
• 16-bit
• Used for real-time clock applications
Timer 2
• 8-bit
• Used for PWM generation
Timer 3
• 16-bit
• Similar to Timer 1
CCP Module Functions
Capture Mode
• Records time of external event
Compare Mode
• Generates output when timer matches a preset value
PWM Mode
• Produces Pulse Width Modulation
• Used for motor control, LED dimming, etc.
Analog-to-Digital
Converter (ADC)
10-bit Resolution
• Provides precise digital representation
8 Input Channels
• Channels labeled AN0 to AN7
Conversion Time
• 34.5 µs maximum
• Maximum sampling rate of approximately 29kHz
Result Storage
• Uses ADRESH/ADRESL registers
• Stores 10-bit conversion results
Interrupt External Interrupts
• INT0
Sources • INT1
• INT2
Timer Interrupts
• TMR0
• TMR1
• TMR2
• TMR3
Control • INTCON2
• INTCON3
Registers Interrupt Flags
• PIR1
• PIR2
Interrupt Enables
• PIE1
• PIE2
Interrupt Priorities
• IPR1
Interrupt Priorities and Vectors
Extended Memory
• Supports larger and more complex programs
Advanced Peripherals
• Offers a range of built-in functionalities
Feature Details
Up to 2MB (21-bit addressable), 32KB in
Memory Size
PIC18F452
Memory Type Flash (Reprogrammable)
Instruction Width 16-bit (some 32-bit)
Stack Depth 31 levels
Interrupt Vectors 0008H (High), 0018H (Low)
Execution Speed Pipelined, 4 cycles per instruction
Data
Data Memory Overview
• Organized into a 12-bit addressable space
- First 128
Data Memory Organization bytes from
Bank 0 →
• Organized into 16 banks General
Purpose
• Each bank has 256 bytes Registers
(0x000 -
Access Bank
Usage in PIC18F Models (256 Bytes
0x07F) -
Second 128
Total)
• Only a portion of banks used bytes from
Bank 15 →
• Example: PIC18F452 Special
Function
Registers
(0x080 -
0x0FF)
EEPROM
Stores data
(Non-Volatile 256 Bytes
permanently
Memory)
Banked Memory Addressing
Banked Memory • Used to access more than 256 bytes of RAM
Organization
efficiently
• Each bank consists of 256 bytes
Bank Select Register (BSR)
• Used to select a specific bank
Access Bank
• 256 bytes allowing direct access without
bank switching
• First 128 bytes from Bank 0 (General Purpose
RAM)
• Second 128 bytes from Bank 15 (SFRs)
Example of Banked Memory Addressing
• MOVWF 0x20: Store value in GPR (requires
BSR selection)
• MOVWF 0xF80: Store value in SFR (direct
access)
General Purpose Registers
(GPRs)
Location and Usage
• Located in each bank
• Used for storing variables and program data
• Compiler handles bank switching automatically
Access Bank
• First 128 bytes (0x000 - 0x07F) of the Access Bank are GPRs from Bank
0
Example: Storing and Retrieving a Value in RAM
• MOVLW 0x55: Load WREG with 0x55
• MOVWF 0x20: Store in GPR memory (requires correct BSR)
• MOVF 0x20, W: Retrieve from GPR memory into WREG
Special Function Control Peripheral Operations
• Timers, ADC, USART, and interrupts
Registers (SFRs) Location of SFRs
• Upper half of Bank 15 (0xF80 - 0xFFF)
• Second 128 bytes (0x080 - 0x0FF) of the
REGISTER FUNCTION Access Bank
Accessibility
TMR0, TMR1, TMR2 Timer Registers
• Directly accessible without using the BSR
INTCON Interrupt Control
Important SFRs
PORTA, PORTB, etc. I/O Ports • Example: Setting PORTB as an output
• CLRF TRISB: Set all PORTB pins as output
Configure I/O
TRISA, TRISB, etc. • MOVLW 0xFF
Direction
• MOVWF PORTB: Turn ON all PORTB pins
ADC
ADCON0, ADCON1
Configuration
Access Bank Total Size of Access Bank
• 256 bytes (0x000 - 0x0FF)
Division of Access Bank
• First 128 bytes (0x000 - 0x07F)
• Second 128 bytes (0x080 -
0x0FF)
Contents of Each Section
• First 128 bytes: General
Purpose Registers (Bank 0)
• Second 128 bytes: Special
Function Registers (Bank 15)
Direct Access Capability
• Allows direct access to both
GPRs and SFRs without
switching banks
EEPROM EEPROM Characteristics
• Stores data permanently