190 likes | 356 Views
Memory Organization II. Microprocessor and Interfacing 261214. PIC Flash Memory Segments. 12. 10. 0. 2K. 2K. 2K. 2K. PIC’s RAM Banking. Instruction Format. f = 7 bit Maximum memory = 2^7 = 128 Bytes. PIC 16F877 has 512 bytes of RAM: How do we access all of it?. 7. 0.
E N D
Memory Organization II Microprocessor and Interfacing261214
PIC Flash Memory Segments 12 10 0 2K 2K 2K 2K
f = 7 bit Maximum memory = 2^7 = 128 Bytes
PIC 16F877 has 512 bytes of RAM: How do we access all of it? 7 0 STATUS (F# 0x03) Bit 5-6 (RP0,RP1) in STATUS are used for RAM Page selection Total Memory becomes 2^9 = 512 Bytes
7 0 Creating a 9 bit RAM address 13 7 6 0 OPCODE f (File#) STATUS 8 6 0 9 Bit RAM Address
RAM location First 32 bytes of every page are reserved. Except on pages 3 and 4 User RAM space. Last 16 Bytes are mirrored
The big picture: where the bits are 6 5 7 0 4 3 7 0 Bit 5-6 (RP0,RP1) in STATUS are used for RAM Page selection Bit 3-4 in PCLATH are usedfor memory access
2. เร่ง Memory Operations ด้วยIndirect Addressing
ทำไมต้องมี Indirect Addressing? สมมุติว่าเรามี Array ในภาษา C ดังนี้ int value[8]; หลังจากที่ใช้งานมันไปสักพักเราอยาก Clear ค่าใน array ทั้งหมดมีค่าเป็น 0 Code จะเป็นอย่างไรถ้าเราไม่สามารถใช้ตัวแปรอ้างตำแหน่งใน Array เช่นห้ามใช้ value[i] = 0;
With indirect addressing For (i=0 ; i<8 ; i++) { value[i] = 0; } Without indirect addressing Value[0] = 0; Value[1] = 0; Value[2] = 0; Value[3] = 0; Value[4] = 0; Value[5] = 0; Value[6] = 0; Value[7] = 0;
Opcode File PIC’s Indirect Addressing
7 0 Creating a 9 bit indirect RAM address 7 0 FSR (File #4) 8-bit address STATUS 8 7 0 9 Bit RAM Address
Example: clear RAM locations 0x20 – 0x27 (8 Bytes) 0x20 = 0b0010 0000 0x27 = 0b0010 0111
The big picture: where the bits are 7 6 5 0 Bit 5-6 (RP0,RP1) in STATUS are used for RAM Page selection 4 3 7 0 Bit 7 (IRP) in STATUS is used for indirect Addressing Bit 3-4 in PCLATH are usedfor memory access
Indirect Addressing Ex Find the sum of values in RAM address 0x22-0x25 and store at address 0x21 ; 0x21 = sum result variable clrf 0x21 ; 0x22 - 0x25 = input numbers to be summed movlw 4 movwf 0x22 movlw 3 movwf 0x23 movlw 2 movwf 0x24 movlw 1 movwf 0x25 End Result: Sum = Value1+Value2+Value3+Value4