19,503
社区成员
发帖
与我相关
我的任务
分享
#define I2COWNER_ADDRESS (0x10>>1)
#define MEGA8_I2CADDRESS (0x60)
#define CMD_CTRL_BASE 0x0
#define CMD_CTRL (CMD_CTRL_BASE+0) //控制字
#define CMD_MST_ADDR (CMD_CTRL_BASE+1) //主控端地址
#define CMD_GET_MKEY (CMD_CTRL_BASE+2) //读取扫描键盘码
#define CMD_GET_TEST1 (CMD_CTRL_BASE+0xa) //读取测试寄存器
typedef __packed struct{
unsigned char cmd;
unsigned char ctrl;
}I2C_control;
void Key_Init(void)
{
I2C_control i2c_ctrl;
IIC_init();
Set_IIC_mode(MCU_IICCON, NULL);
i2c_ctrl.cmd=CMD_MST_ADDR;
i2c_ctrl.ctrl=I2COWNER_ADDRESS;
IIC_Send(MEGA8_I2CADDRESS, (const char*)&i2c_ctrl, sizeof(i2c_ctrl));
i2c_ctrl.cmd=CMD_CTRL;
i2c_ctrl.ctrl = CTRL_MKEn;
IIC_Send(MEGA8_I2CADDRESS, (const char*)&i2c_ctrl, sizeof(i2c_ctrl));
INTS_OFF();
SetISR_Interrupt(IRQ_KBD, Key_ISR, NULL);
INTS_ON();
}