用的是W78E58B,24M晶振。从W78E58B的AUX-RAM写到AT29C020怎么也写不对,有时前两个字节对,后面全是0。有时干脆都不对。换成从程序存储器写到AT29C020,一点问题也没有。弄了一天多,还是不知道问题出在哪儿。 程序如下,请高手帮忙分析分析是什么原因。
#include<reg_w78e58b.h> #include<absacc.h>
#define uchar unsigned char #define uint unsigned int #define ulong unsigned long
unsigned char code sct_data[]= { 0x00,0x08,0x00,0x01,0x75,0xc0,0x02,0xee,0x20,0x02,0xba,0x20,0x00,0x66,0x20,0x40, 0x07,0x0a,0x40,0x05,0x00,0x03,0x9e,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x08,0x00,0x01,0x75,0xc0,0x02,0xee,0x20,0x02,0xba,0x20,0x00,0x66,0x20,0x40, 0x07,0x0a,0x40,0x05,0x00,0x03,0x9e,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x08,0x00,0x01,0x75,0xc0,0x02,0xee,0x20,0x02,0xba,0x20,0x00,0x66,0x20,0x40, 0x07,0x0a,0x40,0x05,0x00,0x03,0x9e,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x08,0x00,0x01,0x75,0xc0,0x02,0xee,0x20,0x02,0xba,0x20,0x00,0x66,0x20,0x40, 0x07,0x0a,0x40,0x05,0x00,0x03,0x9e,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, };
#define ce_29020 P22 #define oe_29020 P23 #define we_29020 P24
/*** load mmry data to eep ***/ void cpy_mmry_29c020(uchar data sct_num) { uint data tmp; uchar data seg; uchar data nu;
oe_29020=1;
/* A16 *, A17 在程序外设置 */
ce_29020=0; /* load aa to 0x5555 */ P0=0; P27=0; P27=1; P0=0x55;_nop_(); P25=0; P25=1; P0=0x08;_nop_(); P27=0; P27=1; P0=0x55;_nop_(); P25=0; P25=1; P0=0xaa;for(nu=0;nu<4;nu++) _nop_(); we_29020=0; we_29020=1;
/* load 55 to 0x2aaa */ P0=0; P27=0; P27=1; P0=0xaa;_nop_(); P25=0; P25=1; P0=0x08;_nop_(); P27=0; P27=1; P0=0x2a;_nop_(); P25=0; P25=1; P0=0x55;for(nu=0;nu<4;nu++) _nop_(); we_29020=0; we_29020=1;
/* load aa to 0x5555 */ P0=0; P27=0; P27=1; P0=0x55;_nop_(); P25=0; P25=1; P0=0x08;_nop_(); P27=0; P27=1; P0=0x55;_nop_(); P25=0; P25=1; P0=0xa0;for(nu=0;nu<4;nu++) _nop_(); we_29020=0; we_29020=1;
// to lock mid 8 bit addr P0=0x08;_nop_(); P27=0; P27=1; P0=sct_num;_nop_(); P25=0; P25=1;
for(tmp=0;tmp<256;tmp++) { seg=PBYTE[tmp]; /* 访问W78E58B AUX-RAM */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* 此处有问题,如改成下一句,访问程序存储器 */ /* 则正常。 */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
// seg=sct_data[tmp];
P25=1;
P0=0; P27=0; P27=1; P0=tmp;_nop_(); P25=0; P25=1; // to lock low 8 bit addr / P0=seg;for(nu=0;nu<10;nu++) _nop_(); we_29020=0; we_29020=1; // write 29c020 / }
ce_29020=1;
}
void deal32(uchar data ky) { ......
EA=0; cpy_mmry_29c020(rcd_sct_num1); EA=1;
...... }
void t0() interrupt 1 { ...... }
void main() { ......
CHPENR=0x87; CHPENR=0x59; CHPCON|=0x10; CHPENR=0x00; TR0=1; EA=1; ......
while(1) { ...... } }
|