#include #include #include #include #define DELAY_TIME 10 #define FALSE 0 #define TRUE 1 const unsigned char SCL_PIN=0x01; const unsigned char SDA_OIN=0x02; static void SET_SCL(void) { asm{ mov dx,0x378 in ax,dx or ax,SCL_PIN out dx,ax } } static void CLR_SCL(void) { asm{ mov dx,0x378 in ax,dx or ax,0xff-SCL_PIN out dx,ax } } static void SET_SDA(void) { asm{ mov dx,0x378 in ax,dx or ax,SDA_PIN out dx,ax } } static void CLR_SDA(void) { asm{ mov dx,0x378 in ax,dx or ax,0xff-SDA_PIN out dx,ax } } void DELAY(int t=DELAY_TIME) { for(int i=0;i } void IIC_Start(void) { SET_SDA(); SET_SCL(); DELAY(); CLR_SDA(); DELAY(); CLR_SCL(); DELAY(); } void IIC_Stop(void) { CLR_SDA(); SET_SCL(); DELAY(); SET_SDA(); DELAY(); CLR_SCL(); DELAY(); } void SEND_0(void) { CLR_SDA(); SET_SCL(); DELAY(); CLR_SCL(); DELAY(); } void SEND_1(void) { SET_SDA(); SET_SCL(); DELAY(); CLR_SCL(); DELAY(); } int Check_Acknowledge(void) { SET_SDA(); SET_SCL(); DELAY(DELAY_TIME/2); unsigned char b=inportb(0x378); DELAY(DELAY_TIME/2); CLR_SCL(); DELAY(); if(b&0xSDA_PIN) return FLASE; return TRUE; }
阅读(1918) | 评论(0) | 转发(2) |