复制代码
- void I2C_Start(void)
- {
- I2C_Busy=1;
- I2CMSCR=0x81;
- while(I2C_Busy);
- }
-
- void I2C_SendData(unsigned char dat)
- {
- I2CTXD=dat;
- I2C_Busy=1;
- I2CMSCR=0x82;
- while(I2C_Busy);
- }
-
- void I2C_RecvACK(void)
- {
- I2C_Busy=1;
- I2CMSCR=0x83;
- while(I2C_Busy);
- }
-
- //unsigned char I2C_RecvData(void)
- //{
- // I2C_Busy=1;
- // I2CMSCR=0x84;
- // while(I2C_Busy);
- // return I2CRXD;
- //}
-
- //void I2C_SendACK(void)
- //{
- // I2CMSST=0x00;
- // I2C_Busy=1;
- // I2CMSCR=0x85;
- // while(I2C_Busy);
- //}
-
- //void I2C_SendNAK(void)
- //{
- // I2CMSST=0x01;
- // I2C_Busy=1;
- // I2CMSCR=0x85;
- // while(I2C_Busy);
- //}
-
- void I2C_Stop(void)
- {
- I2C_Busy=1;
- I2CMSCR=0x86;
- while(I2C_Busy);
- }
复制代码
- void Init(void)
- {
- P_SW2|=EAXFR;
- P3M0=0x00;
- P3M1=0x00;
- P5M0=0x00;
- P5M1=0x00;
- P3PU=0x0c;
- I2CCFG=0xC1; //921.6K@11.0592M
- I2CMSCR=EMSI;
- I2CMSST=0x00;
- EA=1;
- }
复制代码
- void I2C_Isr(void) interrupt 24
- {
- _push_(P_SW2);
- P_SW2|=EAXFR;
- if(I2CMSST&MSIF)
- {
- I2CMSST&=~MSIF;
- I2C_Busy=0;
- }
- _pop_(P_SW2);
- }
复制代码
|