//---------------------------
// write into mbf register
//---------------------------
void Write_Reg(unsigned char reg,unsigned char data)
{
DDRC = 0xFF; //portc as output
//select a particular register
PORTA &= ~(1<<PA0);
PORTA |= (1<<PA1);
PORTA &= ~(1<<PA2);
PORTC = reg;
//send data to register
_delay_us( 45 );; //40us delay
PORTA |= (1<<PA0);
PORTC = data;
_delay_us( 45 );; //40us delay
}
//---------------------------
// mbf initialization
//---------------------------
void mbf_initial(void)
{
Write_Reg(0x08,0x00); //reset value of CTRLA reg
Write_Reg(0x0F,0x33); //set threshold value(houzee) (adjust)
Write_Reg(0x09,0x0D); //set value of CTRLB register
_delay_us( 45 );; //40us delay
Write_Reg(0x06,0x40); //discharge time register value(houzee)
Write_Reg(0x07,0x10); //discharge current register value(houzee)
Write_Reg(0x0C,0x08); //gain setting (houzee) (adjust)
Write_Reg(0x0E,0x03); //clear pending work
Write_Reg(0x0D,0x51); //Interrupt control register (*)
_delay_us( 110 );; //100us delay
}