VI ĐIỀU KHIỂN PIC - ĐẶNG LÊ KHOA - TRƯỜNG ĐH KHTN - KHOA ĐIỆN TỬ VIỄN THÔNG docx

50 848 11
VI ĐIỀU KHIỂN PIC - ĐẶNG LÊ KHOA - TRƯỜNG ĐH KHTN - KHOA ĐIỆN TỬ VIỄN THÔNG docx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

TRƯ NG ð I H C KHOA H C T NHIÊN KHOA ðI N T - VI N THÔNG VI ðI U KHI N PIC ð ng Lê Khoa Tài li u tham kh o • Sách: Sách: Designing Embedded Systems with PIC Microcontrollers (principles and applications), 1st Ed, Tim Wilmshurst, Wilmshurst, published by Newnes, 2007 Newnes, • Bài gi ng • Link tham kh o: http://psut.edu.jo/sites/qaralleh o: CHƯƠNG 1: GI I THI U • H th ng nhúng • Vi u n • Các h vi ñi u n H th ng nhúng • “A system whose principal function is not computational, but which is controlled by a computer embedded within it” • ng d ng r t ph bi n thi t b nhà, văn phịng, u n xe • Thư ng s d ng vi ñi u n M ts ng d ng h th ng nhúng Vi ñi u n gì? • Mini-Computer – Microprocessor • The Brains • Arithmetic Logic Unit (ALU) • Control Unit • Program/ Data Storage • Peripherals (Input/Output) • Low-Cost Ki n trúc Vi ñi u n Memory Timer Timer CPU Timer PWM PWM I/O (Ports A, B & C) 10-bit A/D USART A Computer on a chip Microcontroller Families PIC12F508/509 block diagram 10 CHƯƠNG 4: CÁC C NG I/O 36 PIC18F452 I/O Ports • Five I/O ports – – – – – PORT A through PORT E Most I/O pins are multiplexed Generally have eight I/O pins with a few exceptions Addresses already assigned to these ports in the design stage Each port is identified by its assigned SFR 37 Parallel I/O Combined I/O Structure 38 Parallel I/O ports Main Features • Simple memory mapped access • Can be configured through software as either input or output • Ability to set or reset individual bits • Can have internal pull-ups • Can drive small loads like LEDs • Can be multifunction • Different capability for pins (i.e larger current) 39 Parallel I/O ports • For most ports, the I/O pin’s direction (input or output) is controlled by the data direction register TRISx (x=A,B,C,D,E): a ‘1’ in the TRIS bit corresponds to that pin being an input, while a ‘0’ corresponds to that pin being an output • The PORTx register is the latch for the data to be output Reading PORTx register read the status of the pins, whereas writing to it will write to the port latch • Example: Initializing PORTB (PORTB is an 8-bit port Each pin is individually configurable as an input or output) bcf STATUS, RP0 ; select bank0 bcf STATUS, RP1 clrf PORTB ; clear PORTB output data latches bsf STATUS, RP0 ; select bank1 movlw 0xCF ; value used to initialize data direction movwf TRISB ; PORTB=inputs, PORTB=outputs, ; PORTB=inputs 40 Relationship between TRIS and PORT Registers 41 Illustration: Displaying a Byte at an I/O Port (1 of 5) • Problem statement: – Write instructions to light up alternate LEDs at PORTC • Hardware: – PORTC • bidirectional (input or output) port; should be setup as output port for display – Logic will turn on an LED in Figure 2.10 42 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 43 Illustration (3 of 5) • Program (software) – Logic to TRISC sets up PORTC as an output port – Byte 55H turns on alternate LEDs • • • • • MOVLW 00 ;Load W register with MOVWF TRISC, ;Set up PORTC as output MOVLW 0x55 ;Byte 55H to turn on LEDS MOVWF PORTC,0 ;Turn on LEDs SLEEP ;Power down 44 PIC18F Programming Model and Its Instruction Set PIC18F Programming Model • The representation of the internal architecture of a microprocessor, necessary to write assembly language programs • Divided into two groups – ALU Arithmetic Logic Unit (ALU) – Special Function Registers (SFRs) from data memory Registers • WREG – 8-bit Working Register (equivalent to an accumulator) • BSR: Bank Select Register – 4-bit Register (0 to F) • Only low-order four bits are used to provide MSB four bits of a12-bit address of data memory • STATUS: Flag Register Flags in Status Register Example: 9F+52 =F1 1001 1111 0101 0010 1111 0001 N=1,OV=0, Z=0, C=0, DC=1 • C (Carry/Borrow Flag): – set when an addition generates a carry and a subtraction generates a borrow • DC (Digit Carry Flag): – also called Half Carry flag; set when carry generated from Bit3 to Bit4 in an arithmetic operation • Z (Zero Flag): – set when result of an operation is zero • OV (Overflow Flag): – set when result of an operation of signed numbers goes beyond seven bits • N (Negative Flag): – set when bit B7 is one of the result of an arithmetic /logic operation File Select Registers (FSR) • There are three registers: • FSR0, FSR1, and FSR2 • Each register composed of two 8-bit registers (FSRH and FSRL) • Used as pointers for data registers • Holds 12-bit address of data register Other Registers • Program Counter (PC) – 21-bit register functions as a pointer to program memory during program execution • Table Pointer – 21-bit register used as a memory pointer to copy bytes between program memory and data registers • Stack Pointer (SP) – Register used to point to the stack • Stack – 31 word-sized registers used for temporary storage of memory addresses during execution of a program • Special Function Registers (SFRs): – Data registers associated with I/O ports, support devices, and processes of data transfer ... ports: • A (6-Bits) • B, C and D (8-Bits) • E ( 3- bits) – Counter/Timer modules • Modules 0,2 (8-Bits) • Modules 1,3 (16-Bits) – I2C/SPI serial port – USART port – ADC 10-bits with 8-way input... ch Các tín hi u u n B nh PIC1 8F452 B nh chương trình B nh d li u ð nh v ñ a ch 20 PIC1 8F - Address Buses • BUS đ a ch – Bus ñ a ch có 21-bit: có b nh 2MB – Bus đ a ch 12-bit: có kh qu n lý b nh... Peripherals (Input/Output) • Low-Cost Ki n trúc Vi ñi u n Memory Timer Timer CPU Timer PWM PWM I/O (Ports A, B & C) 10-bit A/D USART A Computer on a chip Microcontroller Families PIC1 2F508/509 block diagram

Ngày đăng: 23/03/2014, 09:20

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan