memory organization ii

19
Memory Organization II Microprocessor and Interfacing 261214

Upload: rashad

Post on 07-Jan-2016

37 views

Category:

Documents


2 download

DESCRIPTION

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. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Memory Organization II

Memory Organization IIMicroprocessor and Interfacing

261214

Page 2: Memory Organization II

PIC Flash Memory Segments

2K2K2K2K

01012

Page 3: Memory Organization II

PIC’s RAM Banking

Page 4: Memory Organization II

Instruction Format

Page 5: Memory Organization II

f = 7 bitMaximum memory = 2^7 = 128 Bytes

Page 6: Memory Organization II

PIC 16F877 has 512 bytes of RAM: How do we access all of it?

STATUS (F# 0x03)

Bit 5-6 (RP0,RP1) in STATUS are used for RAM Page selection

07

Total Memory becomes 2^9 = 512 Bytes

Page 7: Memory Organization II

Creating a 9 bit RAM address

STATUS

07

068

f (File#)

06713

9 Bit RAM Address

OPCODE

Page 8: Memory Organization II

void main(){

int i;i = 1;i++;

}

.................... int i;

....................

.................... i=1; 000D: MOVLW 01000E: BCF 03.5000F: MOVWF 21.................... i++; 0010: INCF 21,F

This code should now make sense

Page 9: Memory Organization II

RAM location

First 32 bytes of every pageare reserved. Except on pages 3 and 4

User RAM space.Last 16 Bytes are mirrored

Page 10: Memory Organization II

The big picture: where the bits are

Bit 5-6 (RP0,RP1) in STATUS are used for RAM Page selection

07

Bit 3-4 in PCLATH are usedfor memory access

07 4 3

6 5

Page 11: Memory Organization II

2. เร่�ง Memory Operations ด้�วย Indirect Addressing

Page 12: Memory Organization II

ทำ��ไมต้�องม� Indirect Addressing?สมม�ติ�ว่�าเราม� Array ในภาษา C ดั�งน��

int value[8];

หลั�งจากที่��ใช้�งานม�นไปส�กพั�กเราอยาก Clear ค่�าใน array ที่��งหมดัม�ค่�าเป#น 0

Code จะเป#นอย�างไรถ้�าเราไม�สามารถ้ใช้�ติ�ว่แปรอ�างติ'าแหน�งใน Array เช้�นห�ามใช้� value[i] = 0;

Page 13: Memory Organization II

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;

Page 14: Memory Organization II

PIC’s Indirect Addressing

Opcode File

Page 15: Memory Organization II

Creating a 9 bit indirect RAM address

STATUS

07

078

8-bit address

07

9 Bit RAM Address

FSR (File #4)

Page 16: Memory Organization II
Page 17: Memory Organization II

Example: clear RAM locations 0x20 – 0x27 (8 Bytes)

Instruction Comment

BCF 0x03, 7 ;select page

MOVLW 0x20

MOVWF 0x04 ;Set FSR

Next CLRF 0x00 ;clear RAM

INCF FSR,F ;increase counter

BTFSS FSR,3 ;all done?

GOTO Next ; no, clear next

0x20 = 0b0010 00000x27 = 0b0010 0111

Page 18: Memory Organization II

The big picture: where the bits are

Bit 5-6 (RP0,RP1) in STATUS are used for RAM Page selection

07

Bit 3-4 in PCLATH are usedfor memory access

07 4 3

6 5

Bit 7 (IRP) in STATUS is used for indirect Addressing

Page 19: Memory Organization II

Indirect Addressing ExFind the sum of values in RAM address 0x22-0x25 and storeat address 0x21

Address Function

0x21 Sum

0x22 Value1

0x23 Value2

0x24 Value3

0x25 Value4

End Result: Sum = Value1+Value2+Value3+Value4

; 0x21 = sum result variableclrf 0x21; 0x22 - 0x25 = input numbers to be summedmovlw 4movwf 0x22movlw 3movwf 0x23movlw 2movwf 0x24movlw 1movwf 0x25