งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

PIC Code Execution II PIC B0 B1 B2 B3 B4 B5 B6 B7.

งานนำเสนอที่คล้ายกัน


งานนำเสนอเรื่อง: "PIC Code Execution II PIC B0 B1 B2 B3 B4 B5 B6 B7."— ใบสำเนางานนำเสนอ:

1 PIC Code Execution II http://mango.e-cpe.org

2 PIC B0 B1 B2 B3 B4 B5 B6 B7

3 Memory Mapped I/O (MMIO) BSF06.0 BCF06.0 BSF = Bit Set File, BCF = Bit Clear File

4 ข้อดีข้อเสียของ Memory Mapped I/O ไม่ต้องออกแบบคำสั่งเฉพาะสำหรับ I/O MOVWF 06 MOVWF 21 I/O Operation Mem Operation

5 ข้อดีข้อเสียของ Memory Mapped I/O Memory Mapped I/O ใช้คำสั่งชุดเดียวในการเข้าถึง Memory และอุปกรณ์รอบข้าง ช่วยลดความซับซ้อนของ CPU ทำให้ราคาถูกลง และ ใช้ งานได้ง่าย Memory MappedPort-Mapped With some exceptions

6 ข้อดีข้อเสียของ Memory Mapped I/O แต่ก็ต้องเสียตำแหน่งใน Memory ไปบางส่วน เช่น PIC16F886 จะเสียพื้นที่ไป 128 Byte จากทั้งหมด 368 Bytes (~35%) เพื่อใช้ทำ Memory Mapped I/O 128 Bytes I/O Mapped 240 Bytes Available RAM

7 3.x GB?? 4 GB The 3 Gig RAM Problem 32 bit OS InstalledUsable ระบบ 32 บิตควรใช้งาน RAM ได้ 2^32 = 4GB พอดี แต่ ทำไมในความเป็นจริง กลับใช้ได้แค่ 3.x GB

8 The 3 Gig RAM Problem ~1 GB 3 GB Address Space Video Card BIOS PCI Bus Etc. RAM (4 GB) ที่อยู่ของหน่วยความจำส่วนบนถูกเอาไปใช้สำหรับ I/O

9 ข้อดีข้อเสียของ Memory Mapped I/O ถ้า Memory และ I/O ใช้ data bus เดียวกัน อาจทำให้ Memory Access ช้าลง เนื่องจากต้องรอคำสั่ง I/O ที่ทำงานช้ากว่า MOVWF 06 MOVWF 21 Slow I/O Operation Fast Mem Operation

10 Port Mapped I/O (PMIO) ใช้คำสั่งแยกกันระหว่าง Memory Operation กับ Peripheral Operation ปัจจุบัน CPU ที่ใช้ Port Mapped I/O มักใช้ Memory Mapped I/O ควบคู่กันไปด้วย

11 ข้อดี / เสียของ Port Mapped I/O การใช้คำสั่งเฉพาะทางทำให้ประสิทธิภาพ โดยรวมดีกว่า แต่ CPU จะมีความซับซ้อนที่สูงขึ้นจากคำสั่งที่ เพิ่มขึ้นมาเหล่านี้ การใช้งานยากขึ้นสำหรับผู้พัฒนา PIC 16FIntel x86 35 Instructions1,000+ Instructions* * See http://en.wikipedia.org/wiki/X86_instruction_listings

12 Memory Mapped I/O Case Study PIC 16F, Tri-state I/O, Memory Organization

13 Look at the complete ASM code for output_high(PIN_B0).................... output_high(PIN_B0); 00ED: BSF 03.5 00EE: BCF 06.0 00EF: BCF 03.5 00F0: BSF 06.0 Q: Why do we need these commands? A: Before using a PIN on the PIC, we need to configure it’s direction

14 Each MCU PIN can be in 3 states (Tri-State) StateDescription HighThe pin sources 5V LowThe pin sinks to GND High ImpedanceThe pin is an input Output Mode Input Mode

15 Tri-state PIN configuration Telling the MCU which mode we want to use an IO pin 0 = Output 1 = Input

16 .................... output_high(PIN_B0); 00EE: BCF 86.0 -> Clear bit 0 of TRISB 00F0: BSF 06.0 -> Set bit 0 of PORTB.................... output_high(PIN_B0); 00ED: BSF 03.5 00EE: BCF 06.0 00EF: BCF 03.5 00F0: BSF 06.0 So, the code should be like this … But why is it like this?

17 The problem with “BCF 86.0” 0x86 = 1000 0110 The space for the file register address is limited to 7 bits

18 Status Register (Address 03) See section “Register 5-1” in the handout for details of the Status Register Bit 6,7 ใช้เลือก Register Bank 00 = Bank 0 01 = Bank 1 10 = Bank 2 11 = Bank 3

19 Bank 0 Bank 1Bank 2 Bank 3

20 แบบฝึกหัด – ทำไฟวิ่งบน PIC Simulator IDE ; set PORTB as output bsf status,5 bcf status,6 movlw 0 movwf trisb ; disable Analog inputs bsf status,6 movwf 0x9 ; switch to FSR Bank 0 bcf status,5 bcf status,6 bsf portb,0 ; trun on LED on B0 กำหนดโปรแกรมส่วนต้นให้เพื่อ setup ระบบดังนี้

21 The RLF command Rotates the bits in a file register through the carry bit RLF Example: MOVLW1 MOVWF0x6 ; RAM value = 0000 0001 2 RLF 0x6,F ; value is now 0000 0010 2

22 Status Register (Address 03) Carry Bit = จะรับบิตที่เกินออก มาทางซ้ายของ W register See section “Register 5-1” in the handout for details of the Status Register

23 PIC-C Trick: RAM access #byte b_port = 6 // mem pointer #bit B0 = b_port.0 b_port = 0xff; // drive port b B0 = 1; // set bit B0 to 1

24

25 Methods Write Machine Code Manually Write Assembly Code Use a High-Level Compiler

26 Writing Machine Code ENIAC

27

28 Benefits of High-Level Compilers Poor optimization Non-Optimal Hardware Utilization Drawbacks of High-Level Compilers Simple for the programmer Reduce development time Allows for the development of larger programs Easier to port to different hardware systems

29 Poor Optimazation.................... while (1).................... output_b(i); Loop: BSF 03.5 CLRF 06 BCF 03.5 MOVF 21,W MOVWF 06 GOTO Loop No need to set TRIS bits every time

30 Poor Optimization Ex 2.................... int i;.................... i = 5; 000D: MOVLW 05 000E: BCF 03.5 000F: MOVWF 21.................... do {.................... i--; 0010: DECF 21,F.................... } while (i>0); 0011: MOVF 21,F 0012: BTFSS 03.2 0013: GOTO 010 DECF already sets the Z bit

31 Non-Optimal HW Utilization Blinking LED example Our code from exercise BSF06.0 Loop: RLF06 GoTo Loop Code generated by PIC-C Loop: BCF 03.5 MOVF 0x21,W MOVWF 06 RLF 0x21, F GOTO Loop

32

33


ดาวน์โหลด ppt PIC Code Execution II PIC B0 B1 B2 B3 B4 B5 B6 B7.

งานนำเสนอที่คล้ายกัน


Ads by Google