Top Banner
Microprocessor and Interfacing 261214 PIC Code Execution II http://mango.e-cpe.org
33

Microprocessor and Interfacing 261214

Jan 06, 2016

Download

Documents

mimir

Microprocessor and Interfacing 261214. PIC Code Execution II. http ://mango.e-cpe.org. B0 B1 B2 B3 B4 B5 B6 B7. PIC. Memory Mapped I/O (MMIO). BSF06.0 BCF06.0. BSF = Bit Set File, BCF = Bit Clear File. ข้อดีข้อเสียของ Memory Mapped I/O. ไม่ต้องออกแบบคำสั่งเฉพาะสำหรับ I/O. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

Microprocessor and Interfacing 261313

Microprocessor and Interfacing261214PIC Code Execution IIhttp://mango.e-cpe.org

PICB0

B1

B2

B3

B4

B5

B6

B7

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

MOVWF 06MOVWF 21I/O OperationMem Operation

Memory Mapped I/OMemory Mapped I/O Memory CPU

Memory MappedPort-MappedWith some exceptions Memory Mapped I/O Memory PIC16F886 128 Byte 368 Bytes (~35%) Memory Mapped I/O

128 BytesI/O Mapped240 BytesAvailable RAM

3.x GB?? 4 GBThe 3 Gig RAM Problem32 bit OSInstalledUsable 32 RAM 2^32 = 4GB 3.x GB

The 3 Gig RAM Problem~1 GB3 GB

Address SpaceVideo CardBIOSPCI BusEtc.RAM(4 GB) I/O

Memory Mapped I/O Memory I/O data bus Memory Access I/O

MOVWF 06MOVWF 21Slow I/O OperationFastMem Operation

Port Mapped I/O (PMIO)Memory Operation Peripheral Operation CPU Port Mapped I/O Memory Mapped I/O / Port Mapped I/O CPU

PIC 16FIntel x8635 Instructions1,000+ Instructions** See http://en.wikipedia.org/wiki/X86_instruction_listingsMemory Mapped I/O Case StudyPIC 16F, Tri-state I/O, Memory OrganizationLook at the complete ASM code foroutput_high(PIN_B0).................... output_high(PIN_B0); 00ED: BSF 03.500EE: BCF 06.000EF: BCF 03.500F0: BSF 06.0Q: Why do we need these commands?A: Before using a PIN on the PIC, we need to configure its direction

Each MCU PIN can be in 3 states (Tri-State)StateDescriptionHighThe pin sources 5VLowThe pin sinks to GNDHigh ImpedanceThe pin is an inputOutputModeInputModeTri-state PIN configurationTelling the MCU which mode we want to use an IO pin

0 = Output1 = Input.................... output_high(PIN_B0); 00EE: BCF 86.0 -> Clear bit 0 of TRISB00F0: BSF 06.0 -> Set bit 0 of PORTB.................... output_high(PIN_B0); 00ED: BSF 03.500EE: BCF 06.000EF: BCF 03.500F0: BSF 06.0So, the code should be like this But why is it like this?The problem with BCF 86.0

0x86 = 1000 0110The space for the file register address is limited to 7 bitsStatus Register (Address 03)

See section Register 5-1 in the handoutfor details of the Status RegisterBit 6,7 Register Bank

00 = Bank 001 = Bank 110 = Bank 211 = Bank 3

Bank 0Bank 1Bank 2Bank 3 PIC Simulator IDE; set PORTB as outputbsf status,5bcf status,6movlw 0movwf trisb; disable Analog inputsbsf status,6movwf 0x189; switch to FSR Bank 0bcf status,5bcf status,6bsf portb,0 ; trun on LED on B0 setup The RLF commandRotates the bits in a file register through the carry bit

RLFExample:MOVLW1MOVWF0x6 ; RAM value = 0000 00012RLF 0x6,F ; value is now 0000 00102Status Register (Address 03)

Zero Bit = 1 ALU 0

See section Register 5-1 in the handoutfor details of the Status RegisterPIC-C Trick: RAM access#byte b_port = 6 // mem pointer#bit B0 = b_port.0

b_port = 0xff; // drive port bB0 = 1; // set bit B0 to 1

Machine Code Generation MethodsMethodsWrite Machine Code ManuallyWrite Assembly CodeUse a High-Level Compiler

Writing Machine CodeENIAC

Benefits of High-Level CompilersPoor optimizationNon-Optimal Hardware UtilizationDrawbacks of High-Level CompilersSimple for the programmerReduce development timeAllows for the development of larger programsEasier to port to different hardware systemsPoor Optimazation.................... while (1) .................... output_b(i); Loop:BSF 03.5CLRF 06BCF 03.5MOVF 21,WMOVWF 06GOTO LoopNo need to set TRIS bits every timePoor Optimization Ex 2.................... int i; .................... i = 5; 000D: MOVLW 05000E: BCF 03.5000F: MOVWF 21.................... do { .................... i--; 0010: DECF 21,F.................... } while (i>0); 0011: MOVF 21,F0012: BTFSS 03.2 0013: GOTO 010 DECF already sets the Z bitNon-Optimal HW UtilizationBlinking LED exampleOur code from exercise BSF06.0Loop: RLF06 GoTo Loop

Code generated by PIC-CLoop: BCF 03.5 MOVF 0x21,W MOVWF 06 RLF 0x21, F GOTO Loop