我用HT66F40的C写了个iic中断接收程序,与上位机通讯。
可是老是不进中断,请高手指教。
我是仿照一个汇编程序写的,汇编的可以进中断。
贴出程序:
#include "HT66F40.h"
#define uchar unsigned char
#define _pc5 _20_5
unsigned char _eec @0x40;
#pragma vector m_funct2 @ 0x20
uchar read_eeprom(void);
void send_8bit(void);
void display_temperature(void);
void delay(void);
uchar iic_adress;
uchar iic_data;
uchar disaddr;
uchar voltadpwm;
uchar iicsendcnt;
#pragma rambank0
bit test;
#pragma norambank
const uchar iicbuffer[10]={10,11,12,13,14,15,16,17,18,19};
const uchar led_num_tab[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void m_funct2()
{if(_simf==1)
{if(_haas==1)
{if(_srw==1)
{iicsendcnt=0;
_htx=1;
_mp1=iicbuffer[iicsendcnt];
_simd=_iar1;
iicsendcnt++;
_simf=0;
}
}
else
{if(_htx==1)
{if(_rxak==0)
{_mp1=iicbuffer[iicsendcnt];
_simd=_iar1;
iicsendcnt++;
_simf=0;
}
}
}
}
test=1;
}
void main()
{_pcpu=0;
_pdpu=0;
_pdc=0;
_pcc=0x10;
//_intc2=1;
_mf2f=0;
_cp0c=8;
_cp1c=8;
_simc0=0xc2;
_simc1=0;
_prm0=0x53;
_prm1=0x05;
_prm2=0x2f;
_sime=1;
_mf2i=1;
_bp&=0xfe;
iic_adress=0;
_eea=iic_adress;
iic_data=read_eeprom();
_sima=iic_data;
_emi=1;
disaddr=0x98;
_pc&=0xfb;
send_8bit();
_pc|=0x04;
iicsendcnt=0;
test=0;
while(1)
{display_temperature();
delay();
}
}
void delay(void)
{unsigned long int i,j;
for(i=650;i>0;i--)
for(j=50;j>0;j--);
}
uchar read_eeprom(void)
{uchar data;
_bp|=1;
_mp1=_eec;
_iar1|=3;
while(_iar1&0x01);
data=_eed;
_iar1=0;
_bp&=0xfe;
return data;
}
void send_8bit(void)
{uchar k;
k=8;
while(k)
{if((disaddr&0x01)==1)
_pc|=0x01;
else
_pc&=0xfe;
#asm
nop
nop
#endasm
_pc5=0;
#asm
clr WDT
nop
#endasm
_pc5=1;
k--;
disaddr>>=1;
}
}
void display_temperature(void)
{uchar i,j;
if(test==1)
iic_data=0x55;
else
iic_data=0;
i=led_num_tab[iic_data&0x0f];
j=led_num_tab[(iic_data&0xf0)>>4];
//i=led_num_tab[voltadpwm&0x0f];
//j=led_num_tab[(voltadpwm&0xf0)>>4];
disaddr=0xc4;
_pc&=0Xfb;
send_8bit();
disaddr=i;
send_8bit();
_pc|=0x04;
disaddr=0xc3;
_pc&=0xfb;
send_8bit();
disaddr=j;
send_8bit();
_pc|=0x04;
} |