Embedded System Design - Chapter 3: Microcontroller

1. Introduction to PIC microcontroller
• PIC is a family of modified Harvard architecture microcontrollers
made by Microchip Technology
• The PIC1650 was originally developed by General Instruments
• The name PIC initially referred to "Peripheral Interface Controller 
pdf 34 trang thamphan 26/12/2022 3660
Bạn đang xem 20 trang mẫu của tài liệu "Embedded System Design - Chapter 3: Microcontroller", để tải tài liệu gốc về máy hãy click vào nút Download ở trên.

File đính kèm:

  • pdfembedded_system_design_chapter_3_microcontroller.pdf

Nội dung text: Embedded System Design - Chapter 3: Microcontroller

  1. 8/9/2016 ĐẠI HỌC QUỐC GIA TP.HỒ CHÍ MINH TRƯỜNG ĐẠI HỌC BÁCH KHOA KHOA ĐIỆN-ĐIỆN TỬ BỘ MÔN KỸ THUẬT ĐIỆN TỬ Embedded System Design Chapter 3: Microcontroller 1. Introduction to PIC microcontroller 2. PIC16F84 3. PIC16F877 4. Apply PIC microcontroller for embedded systems 1 1. Introduction to PIC microcontroller • PIC is a family of modified Harvard architecture microcontrollers made by Microchip Technology • The PIC1650 was originally developed by General Instruments • The name PIC initially referred to "Peripheral Interface Controller" Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 2 1
  2. 8/9/2016 PIC Microcontroller Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 5 Some members of PIC16 Series Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 6 3
  3. 8/9/2016 PIC Clock Three ways to provide the clock signal to a PIC Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 9 PIC’s program memory • PICs have two difference types of program storage: – EPROM (Erasable Programmable ROM) • need high voltage from programmer to program (~13V) • need windowed chips and UV light to erase • PIC examples: any ‘C’ part 12C50x, 17C7xx, – FLASH • rewriteable • much faster to develop on • PIC examples: any ‘F’ part 16F84, 16F87x, 18Fxxx Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 10 5
  4. 8/9/2016 The PIC 16F84A pin connection diagram Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 13 PIC16C8X PINOUT DESCRIPTION Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 14 7
  5. 8/9/2016 Architecture of the PIC16F84 Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 17 W Register Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 18 9
  6. 8/9/2016 16F84A memory features Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 21 PIC16F84 Memory There are two memory blocks in the PIC16C84; program memory and data memory. • Each block has its own bus, so that access to each can occur during the same clock cycle. • The data memory can be further broken down into general purpose memory and special purpose registers Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 22 11
  7. 8/9/2016 PIC16F84 Register‐Mapped I/O • PORTA and PORTB can be programmed 0x00 Ind. address. as an input or an output. 0x01 TMR0 0x02 PCL Special-purpose • PORTA is 5 bits wide and PORTB is 8 0x03 STATUS registers (Bit 4 of port A can be used for an 0x04 FSR Indirect pointer bits wide. 0x05 PORTA data PORT A external timer input.) 0x06 PORTB data PORT B • PORTA has pins/bits labelled RA4:RA0 0x07 Not used • PORTB has pins/bits labelled RB7:RB0 0x08 EEPROM prog. 0x09 “ • Referencing bits . Bits are numbered 0x0A PCLATH Program counter 0x0B INTCON Interrupt control 7‐0 from left to right, i.e., msb‐lsb. 0x0C \: \ • One of the most common | General-purpose | file registers. programming errors is incorrect / specification of bit numbers. / Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 25 PIC16F84A CONFIGURATION WORD • bit 13‐4 CP: Code Protection bit – 1 = Code protection disabled – 0 = All program memory is code protected • bit 3 PWRTE: Power‐up Timer Enable bit – 1 = Power‐up Timer is disabled – 0 = Power‐up Timer is enabled • bit 2 WDTE: Watchdog Timer Enable bit – 1 = WDT enabled – 0 = WDT disabled • bit 1‐0 FOSC1:FOSC0: Oscillator Selection bits – 11 = RC oscillator (Resistor/capacitor) – 10 = HS oscillator (High Speed Crystal/Resonator) – 01 = XT oscillator (Crystal/Resonator) – 00 = LP oscillator (Low Power Crystal) Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 26 13
  8. 8/9/2016 DIRECT/INDIRECT ADDRESSING • A simple program to clear RAM locations 20h‐2Fh using indirect addressing movlw 0x20 ;initialize pointer movwf FSR ;to RAM NEXT clrf INDF ;clear INDF register incf FSR ;inc pointer btfss FSR,4 ;all done? goto NEXT ;NO, clear next CONTINUE : ;YES, continue • An effective 9‐bit address is obtained by concatenating the 8‐ bit FSR register and the IRP bit (STATUS ) • However, IRP is not used in the PIC16F84A. Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 29 EEPROM Data Memory • EEPROM data memory – readable and writable during normal operation – indirectly addressed through the Special Function Register (SFR) • SRFs are: – EECON1 – EECON2 – EEDATA – EEADR Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 30 15
  9. 8/9/2016 Writing to the EEPROM Data Memory • Writing to the EEPROM data memory – write the address to the EEADR register and data to the EEDATA register – follow a specific sequence to initiate the write for each byte BSF STATUS, RP0 ; Bank 1 BCF INTCON, GIE ; Disable INTs. BSF EECON1, WREN ; Enable Write MOVLW 55h ; MOVWF EECON2 ; Write 55h MOVLW AAh ; Requirement MOVWF EECON2 ; Write AAh BSF EECON1,WR ; Set WR bit ; begin write BSF INTCON, GIE ; Enable INTs. Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 33 I/O Port • PORT A: – 5‐bit wide, bi‐direction port – Corresponding data direction register is TRISA (TRISA bit = 1: input; TRISA bit = 0: output) – On a Power‐on Reset, PORTA pins are configured as inputs and read as ‘0’ • PORT B: – 8‐bit wide, bi‐direction port – Corresponding data direction register is TRISB – RB7:RB4, have an interrupt‐on‐change feature Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 34 17
  10. 8/9/2016 Assignments 1. Design a PIC16F84 schematic in which – Port A is input, connected with 4 buttons – Port B is output, connected with 4 LEDs Write a program to control 4 LEDs by 4 buttons 2. Design a PIC16F84 schematic in which – PIC16F84 interfaces with ADC0808 and 4‐digit 7‐segment LED through Port B – RA0 and RA1 are to select digits of 7‐segment LED – RA2 is to control START signal of ADC0808 – RA3 is to control OE signal of ADC0808 Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 37 3. The PIC16F87x • PIC16F873/ 874/ 876/ 877 – 35 single word instructions – Operating speed • DC – 20MHz clock input • DC – 200ns instruction cycle – Timer: timer0/timer1/timer2 – 2 Capturer, Compare, PWM modules – 10‐bit multi‐channel ADC – SSP with SPI and I2C – USART Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 38 19
  11. 8/9/2016 The program memory map and stack PIC16F877/876 PIC16F874/873 Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 41 Data memory Organization • Data memory: – partitioned into multiple banks which contain the General Registers and the Special Function Register – Bits RP1 (STATUS ) and RP0 (STATUS ) are the bank select bits • Each bank extends up to 7Fh (128 bytes). – The lower locations of each bank are reserved for the Special Function Registers. – Above the Special Function Registers are General Purpose Registers Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 42 21
  12. 8/9/2016 Special Function Registers (1) Reference: 16F87X datasheet Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 45 Special Function Registers (2) Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 46 23
  13. 8/9/2016 Program Memory Paging (1) • All PIC16F87X devices are capable of addressing a continuous 8K word block of program memory. • The CALL and GOTO instructions provide only 11 bits of address to allow branching within any 2K program memory page. • When doing a CALL or GOTO instruction, the upper 2 bits of the address are provided by PCLATH . • When doing a CALL or GOTO instruction, the user must ensure that the page select bits are programmed so that the desired program memory page is addressed. • If a return from a CALL instruction (or interrupt) is executed, the entire 13‐bit PC is popped off the stack. • The contents of the PCLATH register are unchanged after a RETURN or RETFIE instruction Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 49 Program Memory Paging (2) • Example: – call of a subroutine in page 1 from page 0 – assumes that PCLATH is saved and restored by the Interrupt Service Routine (if interrupts are used). ORG 0x500 BCF PCLATH,4 BSF PCLATH,3 ;Select page 1 (800h‐FFFh) CALL SUB1_P1 ;Call subroutine in page 1 (800h‐FFFh) : ORG 0x900 ;page 1 (800h‐FFFh) SUB1_P1 : ;called subroutine page 1 (800h‐FFFh) : RETURN ;return to Call subroutine ;in page 0 (000h‐7FFh) Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 50 25
  14. 8/9/2016 Indirect Addressing (3) • A simple program to clear RAM locations 20h‐2Fh using indirect addressing MOVLW 0x20 ;initialize pointer MOVWF FSR ;to RAM NEXT CLRF INDF ;clear INDF register FSR,F ;inc pointer BTFSS FSR,4 ;all done? GOTO NEXT ;no clear next CONTINUE : ;yes continue Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 53 IO Ports Port APort BPort CPort DPort E Support 16F87X 16F87X 16F87X PIC16F874 PIC16F874 /877 /877 Width 6‐bit 8‐bit 8‐bit 8‐bit 3‐bit Direction Bi‐directional Bi‐directional Bi‐directional Bi‐directional Bi‐directional Direction TRISA TRISB TRISC TRISD TRISE register Buffer TTL buffer / TTL buffer / Schmitt Schmitt Schmitt Schmitt Schmitt trigger trigger trigger trigger trigger Multiplexed Analog input Serial USART, PWM, Parallel slave Analog input with Programming I2C, SPI port Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 54 27
  15. 8/9/2016 Port C Functions Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 57 Port D Functions Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 58 29
  16. 8/9/2016 PIC16CXXX Instruction Set (1) Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 61 PIC16CXXX Instruction Set (2) Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 62 31
  17. 8/9/2016 4. Apply PIC microcontroller for embedded systems • A simple security system using PIC microcontroller Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 65 PIC Applications  LED Flasher Loop: bsf PORTB, 0 call Delay_500ms bcf PORTB, 0 call Delay_500ms goto Loop Bộ môn Kỹ Thuật ĐiệnTử - ĐHBK Chapter 3 66 33