📄 chap9.c
字号:
// Chapter 9 6812 C programs// Jonathan W. Valvano// This software accompanies the book,// Embedded Microcomputer Systems: Real Time Interfacing// published by Brooks Cole, 1999// Program 9.1. Software to configure the chip select for the external PROM.void PROMinit(void){ CSSTR0=(CSSTR0&0xF3)|0x08;} // 2 cycle stretch on CSP0// Program 9.2. Software to configure the chip select for the external RAM.void RAMinit(void){ MODE=0x3B // special expanded narrow mode PEAR=0x2C; // enable E, R/W, LSTRB(not needed) WINDEF=WINDEF&0x7F; // disable DPAGE CSCTL0=CSCTL0|0x10; // enable CSD CSCTL1=CSCTL1|0x10; // CSD $0000 to $7FFF CSSTR0=(CSSTR0&0xFC)|0x01;} // 1 cycle stretch on CSD// Program 9.3. Software to configure the mode for the external RAM.void RAMinit(void){ MODE=0x39 // special expanded narrow mode MISC=(MISC&0xF3)|0x08; // 2 cycle stretch on external PEAR=0x2C;} // enable DBE, E, R/W, LSTRB(not needed)// Program 9.4. Software to configure the chip select for the external PROM.void PROMinit(void){ CSSTR0=(CSSTR0&0xF3)|0x04;} // 1 cycle stretch on CSP0// Program 9.5. Software to configure the chip select for the external RAM.void RAMinit(void){ MODE=0x7B // special expanded wide mode PEAR=0x2C; // enable E, R/W, LSTRB WINDEF=WINDEF&0x7F; // disable DPAGE CSCTL0=CSCTL0|0x10; // enable CSD CSCTL1=CSCTL1|0x10; // CSD $0000 to $7FFF CSSTR0=(CSSTR0&0xFC)|0x01;} // 1 cycle stretch on CSD// Program 9.6. Software to configure the mode for the external RAM.void RAMinit(void){ MODE=0x79 // special expanded wide mode MISC=(MISC&0xF3)|0x08; // 2 cycle stretch on external PEAR=0x2C;} // enable DBE, E, R/W, LSTRB// Program 9.7. Software to configure the mode for the extended RAM.void RAMinit(void){ MODE=0x7B // special expanded wide mode PEAR=0x2C; // enable E, R/W, LSTRB WINDEF=WINDEF|0x80; // enable DPAGE MXAR=0x03; // enable A17, A16 on Port G CSCTL0=CSCTL0|0x10; // enable CSD CSCTL1=CSCTL1&0xEF; // CSD $7000 to $7FFF CSSTR0=(CSSTR0&0xFC)|0x01;} // 1 cycle stretch on CSD// Program 9.8. Method for accessing extended RAM.struct addr20{ unsigned char msb; // bits 19-12, only 17-12 used in this interface unsigned int lsw; // bits 11-0};typedef struct addr20 addr20Type;char ReadMem(addr20Type addr){ char *pt; DPAGE=addr.msb; // set address bits 19-12, only 17-12 used pt=(char *)(0x7000+addr.lsw); // set address bits 11-0 return *pt;} // read accessvoid WriteMem(addr20Type addr, char data){ char *pt; DPAGE=addr.msb; // set address bits 19-12, only 17-12 used pt=(char *)(0x7000+addr.lsw); // set address bits 11-0 *pt=data;} // write access// Program 9.9. Software to configure the mode for the extended PROM.void PROMinit(void){ MODE=0x7B // special expanded wide mode PEAR=0x2C; // enable E, R/W, LSTRB (none needed) WINDEF=WINDEF|0x40; // enable PPAGE MXAR=0x01F; // enable A20-A16 on Port G CSSTR0=(CSSTR0&0xF3)|0x04;} // 1 cycle stretch on CSP0// Program 9.10. Method for accessing extended PROM.struct addr22{ unsigned char msb; // bits 21-14, only 20-14 used in this interface unsigned int lsw; // bits 13-0};typedef struct addr22 addr22Type;char ReadPROM(addr22Type addr){ char *pt; PPAGE=addr.msb; // set address bits 21-14 pt=(char *)(0x8000+addr.lsw); // set address bits 13-0 return *pt;} // read access
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -