Upload
rashad
View
35
Download
2
Embed Size (px)
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
Citation preview
Memory Organization IIMicroprocessor and Interfacing
261214
PIC Flash Memory Segments
2K2K2K2K
01012
PIC’s RAM Banking
Instruction Format
f = 7 bitMaximum memory = 2^7 = 128 Bytes
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
Creating a 9 bit RAM address
STATUS
07
068
f (File#)
06713
9 Bit RAM Address
OPCODE
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
RAM location
First 32 bytes of every pageare reserved. Except on pages 3 and 4
User RAM space.Last 16 Bytes are mirrored
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
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;
PIC’s Indirect Addressing
Opcode File
Creating a 9 bit indirect RAM address
STATUS
07
078
8-bit address
07
9 Bit RAM Address
FSR (File #4)
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
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
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