Memory Random Access Memory ReadWrite volatile ReadOnly Memory


























![void main(void) { int i; for(i=0; i<8192; i++) ram[i]=0; } void main(void) { int i; for(i=0; i<8192; i++) ram[i]=0; }](https://slidetodoc.com/presentation_image_h/27390b4de70cc313f14792e83b8160c7/image-27.jpg)
![• __xram __at 0 x. C 000 int ram[4096]; for(i=0; i<4096; i++) Ram[i]=I; • __xram __at 0 x. C 000 int ram[4096]; for(i=0; i<4096; i++) Ram[i]=I;](https://slidetodoc.com/presentation_image_h/27390b4de70cc313f14792e83b8160c7/image-28.jpg)


![__code __at 0 x 4000 unsigned char rom[8192]; __xdata __at 0 x. C 000 __code __at 0 x 4000 unsigned char rom[8192]; __xdata __at 0 x. C 000](https://slidetodoc.com/presentation_image_h/27390b4de70cc313f14792e83b8160c7/image-31.jpg)
![• __xdata __at 0 x 3000 unsigned int x[1024]; for(i=0; i<1024; i++) x[i]=i; • __xdata __at 0 x 3000 unsigned int x[1024]; for(i=0; i<1024; i++) x[i]=i;](https://slidetodoc.com/presentation_image_h/27390b4de70cc313f14792e83b8160c7/image-32.jpg)











- Slides: 43


• Memory – Random Access Memory • Read/Write, volatile – Read-Only Memory • Program, non-volatile • Programable ROM • Erasable PROM – UV EPROM – Electrical EPROM – Flash memory – Serial EEPROM


• 8051 write to 6264 – A 0~A 12 / 解碼電路 CS – D 0~D 7 – WR • 8051 read from 6264 – A 0~A 12 / 解碼電路 CS – RD – D 0~D 7


• Write 0 x 3 C to memory's 0 x 1 A 2 B • • P 2=0 x 1 A; P 1=0 x 2 B; P 0=0 x 3 C; P 3_5=0; P 3_6=1; P 3_5=1;

• Read from memory's 0 x 1 A 2 B • • MOV P 2, #1 Ah MOV P 1, #2 Bh CLR P 3. 5 CLR P 3. 7 P 0, #0 FFh MOV A, P 0 SETB P 3. 7 SETB P 3. 5

• READ – – 1. CS 2. A 0 -A 12 3. RD 4. D 0 -D 7 • WRITE – – 1. CS 2. A 0 -A 12 3. D 0 -D 7 4. WR


• READ – 1. CS – 2. A 0 -A 12 – 3. RD – 4. D 0 -D 7 • Program



• Write 0 x 3 C to memory's 0 x 1 A 2 B • MOV DPTR, #1 A 2 Bh • MOV A, #3 Ch • MOVX @DPTR, A


• • EPROM 2764: ---x xxxx xxxx 0100 0000 = 4000 h 0101 1111 = 5 FFFh • • RAM 6264: ---x xxxx xxxx 1000 0000 = 8000 h 1001 1111 = 9 FFFh

• Read from lowest address of EPROM 2764 (4000 h) • MOV DPTR, #4000 h • MOV A, #00 h • MOVC A, @A+DPTR

• Write 12 h to highest address of RAM 6264 (9 FFFh) • MOV DPTR, #9 FFFh • MOV A, 12 h • MOVX @DPTR, A

• Read from lowest address of 6264 (8000 h) • MOV DPTR, #8000 h • MOVX A, @DPTR

• MOVX @DPTR, A – – DPL P 0, DPH P 2 ALE A P 0 WR • MOVX A, @DPTR – – DPL P 0, DPH P 2 ALE RD A P 0

• MOVC A, @A+DPTR – – (DPTR+A)L P 0, (DPTR+A)H P 2 ALE PSEN A P 0 • Fetch instruction – – PCL P 0, PCH P 2 ALE PSEN Instruction Register P 0


• • • RAM 6264: ---x xxxx xxxx 1100 0000 = C 000 h 1101 1111 = DFFFh sdcc --xram-loc 0 x. C 000 test. c

• __data unsigned char test_data; • __xdata __at 0 x 7 FFE unsigned int chksum; • __idata unsigned char test_data; • __code unsigned char test_code=‘A’; • __bit test_bit;


• • • 110 x xxxx = C 000 h~DFFFh 010 x xxxx = 4000 h~5 FFFh __code __at 0 x 4000 unsigned char x=‘ 1’; __xdata __at 0 x. C 000 unsigned char y; y=x; x=y; Incorrect!

• Copy ROM to RAM • __code __at 0 x 4000 unsigned char rom[8192]; • __xram __at 0 x. C 000 unsigned char ram[8192]; void main(void) { int i; for(i=0; i<8192; i++) ram[i]=rom[i]; }
![void mainvoid int i fori0 i8192 i rami0 void main(void) { int i; for(i=0; i<8192; i++) ram[i]=0; }](https://slidetodoc.com/presentation_image_h/27390b4de70cc313f14792e83b8160c7/image-27.jpg)
void main(void) { int i; for(i=0; i<8192; i++) ram[i]=0; }
![xram at 0 x C 000 int ram4096 fori0 i4096 i RamiI • __xram __at 0 x. C 000 int ram[4096]; for(i=0; i<4096; i++) Ram[i]=I;](https://slidetodoc.com/presentation_image_h/27390b4de70cc313f14792e83b8160c7/image-28.jpg)
• __xram __at 0 x. C 000 int ram[4096]; for(i=0; i<4096; i++) Ram[i]=I;


• • 2764: ---x xxxx xxxx 0100 0000 = 4000 h 0101 1111 = 5 FFFh • • 6264: ---x xxxx 110 x xxxx 1100 0000 = C 000 h 1101 1111 = DFFFh
![code at 0 x 4000 unsigned char rom8192 xdata at 0 x C 000 __code __at 0 x 4000 unsigned char rom[8192]; __xdata __at 0 x. C 000](https://slidetodoc.com/presentation_image_h/27390b4de70cc313f14792e83b8160c7/image-31.jpg)
__code __at 0 x 4000 unsigned char rom[8192]; __xdata __at 0 x. C 000 unsigned char ram[8192]; void main() { int I; for (i=0; i<8192; i++) ram[i]=rom[i]; }
![xdata at 0 x 3000 unsigned int x1024 fori0 i1024 i xii • __xdata __at 0 x 3000 unsigned int x[1024]; for(i=0; i<1024; i++) x[i]=i;](https://slidetodoc.com/presentation_image_h/27390b4de70cc313f14792e83b8160c7/image-32.jpg)
• __xdata __at 0 x 3000 unsigned int x[1024]; for(i=0; i<1024; i++) x[i]=i;

• 10 xx xxxx • 1000 0000 = 8000 h • 1011 1111 = BFFFh

• 0011 1 xxx xxxx • 0011 1000 0000 = 3800 h • 0011 1111 = 3 FFFh


• xx 00 0 xxx xxxx • xx 00 0000 = • xx 00 0111 1111 =



• MOV DPTR, #7 FFFh • MOVX @DPTR, A • MOV DPTR, #0000 h • MOVX A, @DPTR

Stack



• 110 x xxxx • 1100 0000 = C 000 h • 1101 1111 = DFFFh • __xdata __at 0 x. C 000 unsigned char x[8192]; • int i; • for(i=0; i<8192; <i++) – x[i]=0;