Memory Random Access Memory ReadWrite volatile ReadOnly Memory

  • Slides: 43
Download presentation

 • Memory – Random Access Memory • Read/Write, volatile – Read-Only Memory •

• 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 –

• 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

• 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

• 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

• 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.

• 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

• 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

• • 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,

• 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) •

• 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

• 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

• 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

• 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

• • • 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

• __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

• • • 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

• 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 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; }

 • __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;

 • • 2764: ---x xxxx xxxx 0100 0000 = 4000 h 0101 1111

• • 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 rom[8192]; __xdata __at 0 x. C 000

__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 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;

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

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

 • 0011 1 xxx xxxx • 0011 1000 0000 = 3800 h •

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

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

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

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

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

Stack

Stack

 • 110 x xxxx • 1100 0000 = C 000 h • 1101

• 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;