PIC18 Microcontroller Architecture and Programming Fundamentals
Classified in Computers
Written on in
English with a size of 2.31 MB
1. PIC18 Architecture Details
Harvard Architecture
Features distinct program memory and data memory. Includes the MPU, Program Memory, Data Memory, I/O Ports, and support devices like timers.
Microprocessor Unit (MPU)
ALU (Arithmetic Logic Unit)
Performs operations such as addition, subtraction, and logical operations.
Registers
Includes WREG (8-bit accumulator), Program Counter (PC), Stack Pointer (SP), and File Select Registers (FSRs).
Memory
Offers 2 MB of program memory and 4 KB of data memory.
Bank Switching
Data memory is divided into 16 banks, with one 256-byte access bank.
2. Data Formats and Representations
Unsigned Integers
These are 8-bit values, ranging from 0 to 255.
Signed Integers
Represented using 2's complement, with a range from -128 to 127.
BCD (Binary Coded Decimal)
Each byte is split into two 4-bit nibbles, representing decimal digits 0 through 9.
ASCII
A 7-bit alphanumeric code, with values ranging from 0x00 to 0x7F.
3. PIC18 Registers and Memory
Special Function Registers (SFRs)
These control the CPU and peripherals. Examples include
PORTx(for I/O ports),TMRx(timers), andSTATUS(arithmetic status).General Purpose Registers (GPRs)
Used primarily for variable storage during program execution.
4. Assembly Language Programming
Basic Instructions
Key instructions include
MOV,ADD,SUB,AND,OR,XOR,NOP, andGOTO.Control Flow
Control flow is managed using:
GOTO(long jump)BRA(short jump)CALLandRETURNfor subroutine handling.
Flags
Flags used in arithmetic and logical operations include N (Negative), Z (Zero), C (Carry), OV (Overflow), and DC (Digit Carry).
5. Timers, Interrupts, and I/O Ports
I/O Ports
Controlled by the
PORTxandTRISxregisters, allowing pins to be configured as input or output.Timers
The PIC18 features multiple timers, such as Timer0 and Timer1, for time-based operations.
Interrupt Handling
Interrupts can be configured to trigger on specific conditions, such as timer overflows or external events.
6. Peripheral Interfacing
LED and 7-Segment Displays
Interfacing involves setting I/O pins, often requiring multiplexing for multiple digits.
Keypad Interface
This typically involves scanning rows and columns to detect keypresses.