An Introduction to Picmicro Microcontrollers
Total Page:16
File Type:pdf, Size:1020Kb
An introduction to PICMicro Microcontrollers Nicholas Amadori 21 novembre 2003 Indice 1 Architecture and Hardware Design 8 1.1 Generalities . 8 1.2 PIC Families . 12 1.2.1 Memory Varieties . 12 1.2.2 Logical Families . 13 1.2.3 Packages . 15 1.2.4 How to choose the right MCU for your needs . 15 1.3 Core Features . 18 1.3.1 CPU (Central Processing Unit) . 18 1.3.2 ALU (Arithmetic Logical Unit) . 18 1.3.3 Oscillator . 20 1.3.4 Reset logic . 24 1.3.5 Memory Organization . 26 1.3.6 Device configuration bits . 30 1.3.7 Watchdog Timer . 30 1.3.8 Low power mode (Sleep) . 31 1.3.9 Table Read/Write . 32 1.3.10 Interrupts . 32 1.4 Peripherals . 33 1.4.1 Generic I/O . 35 1.4.2 Timers . 38 1.4.3 Capture, Compare, PWM (CCP) . 41 1.4.4 Serial ports and protocols . 45 1.4.5 LCD driver . 50 1.4.6 Comparators . 51 1.4.7 Voltage References . 53 1.4.8 A/D converters . 53 1.4.9 Parallel Slave Port (PSP) . 56 1.4.10 USB . 57 1.5 In-Circuit Serial Programming . 58 2 Interfacing PICs 60 2.1 LED . 60 2.2 Switch de-bounce . 61 2.3 Relais and Solenoids . 62 1 INDICE 2 2.4 Motors . 63 2.5 RS232 . 65 3 Programmazione 67 3.1 Linguaggio Assembly . 67 3.1.1 Direttive di compilazione . 68 3.2 Linguaggio C . 68 3.3 Application Maestro . 69 3.4 FilterLab . 70 3.5 MPLAB IDE . 71 3.5.1 Programmare e compilare . 71 3.5.2 Simulare . 72 3.6 Programmare con l’ICD 2 . 72 3.7 Debug con l’ICD2 . 73 4 Esempi 75 4.1 Lampeggio LED . 75 4.2 Generazione PWM . 80 4.3 Controllore per motori stepper . 81 5 Descrizione della PICDEM2 plus 86 A Realizzazione di una demo-board 88 A.1 16F84 . 88 A.1.1 Schema elettrico . 88 A.1.2 Circuito stampato . 88 B Instruction sets 91 B.1 PIC16F84A e PIC16F87x . 91 B.2 PIC18F45x . 91 C Glossary 97 D Application Notes 111 Elenco delle figure 1.1 MID-Range PICMicro architecture . 9 1.2 Architectures: Harvard vs. von Neumann . 10 1.3 Two-stage Pipeline . 11 1.4 Packaging of PICmicro MCUs . 16 1.5 Packaging of PICmicro MCUs (continued) . 17 1.6 ALU and WREG register operation . 19 1.7 8 x 8 Unsigned Multiply Routine . 20 1.8 8 x 8 Signed Multiply Routine . 20 1.9 Internal instruction clock (TCY) . 21 1.10 Typical crystal oscillator configuration . 22 1.11 Typical RC oscillator configuration . 23 1.12 Example RC Oscillator Frequency vs. VDD . 24 1.13 Reset circuitry . 26 1.14 Mid-range devices memory map . 27 1.15 Example: call of a subroutine in page 1 from page 0 . 28 1.16 PIC18x PC structure . 29 1.17 Example: Specify configuration bits using the CONFIG directive . 31 1.18 Example: Interrupt Service Routine Template . 34 1.19 Example: Interrupt Initialization . 35 1.20 Generic I/O port . 37 1.21 Initializing PORTA . 38 1.22 PORTB block diagram . 39 1.23 Timer0 simplified block diagram . 40 1.24 Initializing Timer0 on PIC16F . 40 1.25 PWM Output . 43 1.26 I2C connections and data format . 49 1.27 Example of a CAN network . 50 1.28 Single Comparator . 51 1.29 Comparator Modes . 52 1.30 Vref diagram . 53 1.31 8-bit A/D converter module diagram . 54 1.32 A/D conversion example . 56 1.33 USB external circuitry . 58 1.34 Typical In-Circuit Serial Programming (ICSP) Application Circuit . 59 3 ELENCO DELLE FIGURE 4 2.1 LED connection . 61 2.2 Multiple 7-segments display wiring . 61 2.3 Swich bouncing signal . 61 2.4 Hardware debounce circuit . 62 2.5 Relay control circuit . 63 2.6 H-bridge circuit . 64 2.7 Using the 293D to control a motor . 64 2.8 Functional block diagram of LMD18200 . 65 2.9 Piedinatura e descrizione del MAX232 . 66 3.1 La finestra principale di Application Maestro . 69 3.2 FilterLab in azione . 70 3.3 Files generati dal compilatore . 71 4.1 Lampeggio di un LED senza interrupt . 76 4.2 Lampeggio Led: Diagramma di flusso . 77 4.3 Lampeggio di un LED, Codice HEX . 78 4.4 Lampeggio di un LED con interrupt . 79 4.5 Posizione in memoria dell’esempio Lampeggio LED con interrupt . 80 4.6 Generazione PWM (1/4) . 82 4.7 Generazione PWM (2/4) . 83 4.8 Generazione PWM (3/4) . 84 4.9 Generazione PWM (4/4) . 85 5.1 PICDEM2 plus hardware . ..