到井号那里就无法再执行下去了,仿佛是在中断里出不来了,请高手帮忙看一看啊,小弟急啊!!!!
#include "option.h" #include "def.h" #include "44b.h" #include "44blib.h"
#define WRDATA (1) #define RDDATA (2) #define SETRDADDR (3)
void Isr_Init(void); void HaltUndef(void); void HaltSwi(void); void HaltPabort(void); void HaltDabort(void); void Wr24C040(U32 slvAddr,U32 addr,U8 data); void Rd24C040(U32 slvAddr,U32 addr,U8 *data); void __irq IicInt(void); volatile int _iicDataCount; volatile int _iicMode; U8 _iicaddr; U8 _iicdata;
void Main(void) { unsigned int i; U8 data[256];
rSYSCFG=SYSCFG_8KB; #if (PLLON==1) ChangePllValue(PLL_M,PLL_P,PLL_S); #endif
Isr_Init(); Port_Init(); Uart_Init(0,115200); Uart_Select(0); Delay(0); //calibrate Delay() Led_Display(7); Delay(1000); //calibrate Delay() Led_Display(0); Delay(5000); //calibrate Delay() Led_Display(7); Uart_Printf("
start
");
pISR_IIC=(unsigned)IicInt; rINTMSK=~(BIT_GLOBAL|BIT_IIC); rIICCON=0xaf; rIICSTAT=0x10; rIICADD=0x10; Uart_Printf("Write test data into KS24C080
");
for(i=0;i<16;i++) Wr24C040(0xa0,(U8)i,i);
for(i=0;i<16;i++) data=0;
Uart_Printf("Read test data from KS24C080
"); for(i=0;i<16;i++) Rd24C040(0xa0,(U8)i,&(data)); for(i=0;i<16;i++) { Uart_Printf("%2x ",data); Uart_Printf("
"); }
}
void Wr24C040(U32 slvAddr,U32 addr,U8 data) { _iicMode=WRDATA; _iicaddr=addr; _iicdata=data; _iicDataCount=3; rIICDS=slvAddr; rIICSTAT=0xf0; ############################################################ Uart_Printf("
test1
"); while(_iicDataCount!=-1); }
void Rd24C040(U32 slvAddr,U32 addr,U8 *data) { _iicMode=SETRDADDR; _iicaddr=addr; _iicDataCount=2; rIICDS=slvAddr; rIICSTAT=0xf0; while(_iicDataCount!=0); _iicMode=RDDATA; _iicDataCount=2; rIICDS=slvAddr; rIICSTAT=0xb0; //MasRx,Start rIICCON=0xaf; //resumes IIC operation. while(_iicDataCount!=0); *data=_iicdata; }
void __irq IicInt(void) { U32 i;
switch(_iicMode) { case WRDATA: if(_iicDataCount==1) { _iicDataCount--; Uart_Printf("_iicDataCount3=%d
",_iicDataCount); rIICSTAT=0xd0; rIICCON=0xaf; Delay(1); } else if(_iicDataCount==2) { _iicDataCount--; Uart_Printf("_iicDataCount2=%d
",_iicDataCount); rIICDS=_iicdata; for(i=0;i<10;i++); rIICCON=0xaf; } else if(_iicDataCount==3) { _iicDataCount--; Uart_Printf("_iicDataCount1=%d
",_iicDataCount); rIICDS=_iicaddr; for(i=0;i<10;i++); rIICCON=0xaf; } break;
case SETRDADDR: if(_iicDataCount==2) { _iicDataCount--; rIICDS=_iicaddr; for(i=0;i<10;i++); rIICCON=0xaf; } else { _iicDataCount--; } break;
case RDDATA: if(_iicDataCount==2) { _iicDataCount--; _iicdata=rIICDS; for(i=0;i<10;i++); rIICCON=0x2f;//resumes IIC operation with NOACK. } else { _iicDataCount--; rIICSTAT=0x90; //stop MasRx condition rIICCON=0xaf; //resumes IIC operation. Delay(1); //wait until stop condtion is in effect. //too long time... } break;
default: break; }
}
void Isr_Init(void) { U32 i; pISR_UNDEF=(unsigned)HaltUndef; pISR_SWI =(unsigned)HaltSwi; pISR_PABORT=(unsigned)HaltPabort; pISR_DABORT=(unsigned)HaltDabort; for(i=_RAM_STARTADDRESS;i<(_RAM_STARTADDRESS+0x20);i+=4) { *((volatile unsigned *)i)=0xEA000000+0x1FFE; }
rINTCON=0x5; // Non-vectored,IRQ enable,FIQ disable
rINTMOD=0x0; // All=IRQ mode rINTMSK|=BIT_GLOBAL|BIT_EINT3; // All interrupt is masked. }
void HaltUndef(void) { Uart_Printf("Undefined instruction exception!!!
"); while(1); }
void HaltSwi(void) { Uart_Printf("SWI exception!!!
"); while(1); }
void HaltPabort(void) { Uart_Printf("Pabort exception!!!
"); while(1); }
void HaltDabort(void) { Uart_Printf("Dabort exception!!!
"); while(1);
|