funguamongu
Newbie
Hello
I recently got my hands on Megawin MG82F6D17 mcus. They are cheaper than PIC and ATMEGA mcus in my county. I have been trying to use the sample code provided by the support site of the manufacturer but I cannot figure out how to get it to work with the LCD.
This was the sample code in the package, I need help getting it to work
Many thanks
Full sample code for I2C provided by Megawin
I recently got my hands on Megawin MG82F6D17 mcus. They are cheaper than PIC and ATMEGA mcus in my county. I have been trying to use the sample code provided by the support site of the manufacturer but I cannot figure out how to get it to work with the LCD.
Code:
u8 TWI0_WriteBuf(u8 DevAddr,u16 RegStartAddr,u8 *pBuf,u8 Len)
{
u8 i;
u8 Flag;
Flag=1;
SICON |=STA; // Send START
TWI0OvTime=5;
SICON &=~SI;
while((SICON&SI)!=SI){if(TWI0OvTime==0) goto TWI0_WRITE_ERR;} // wait completed, if time overflow,then return fail.
SICON &=~STA;
SICON=SICON|(AA);
Flag++;
SIDAT = DevAddr&0xFE; // send Slave Device address
TWI0OvTime=5;
SICON &=~SI;
while((SICON&SI)!=SI){if(TWI0OvTime==0) goto TWI0_WRITE_ERR;} // wait completed, if time overflow,then return fail.
Flag++;
SIDAT = HIBYTE(RegStartAddr); // send Slave Data address high
TWI0OvTime=5;
SICON &=~SI;
while((SICON&SI)!=SI){if(TWI0OvTime==0) goto TWI0_WRITE_ERR;} // wait completed, if time overflow,then return fail.
Flag++;
SIDAT = LOBYTE(RegStartAddr); // send Slave Data address low
TWI0OvTime=5;
SICON &=~SI;
while((SICON&SI)!=SI){if(TWI0OvTime==0) goto TWI0_WRITE_ERR;} // wait completed, if time overflow,then return fail.
Flag++;
i=0;
while(i<Len)
{
if(i==(Len-1))
{
SICON=SICON&(~AA);
}
else
{
SICON=SICON|(AA);
}
SIDAT=pBuf[i]; // send Data
TWI0OvTime=5;
SICON &=~SI;
while((SICON&SI)!=SI){if(TWI0OvTime==0) goto TWI0_WRITE_ERR;} // wait completed, if time overflow,then return fail.
i++;
}
Flag++;
SICON |= STO; // Send STOP
TWI0OvTime=5;
SICON &=~SI;
while((SICON&STO)==STO){if(TWI0OvTime==0) goto TWI0_WRITE_ERR;} // wait completed, if time overflow,then return fail.
SICON &=~STO;
SICON = SICON &(~SI);
return 0;
TWI0_WRITE_ERR:
return Flag;
}
Many thanks
--- Updated ---
Full sample code for I2C provided by Megawin