📄 iic_test.c
字号:
/*********************************************************************************************
* File name: iic.c
* Author: Embest
* Descript: iic source code.
* History:
* Ahthor Xu Fub 16th 2006
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include "2410lib.h"
/*------------------------------------------------------------------------------------------*/
/* global variables */
/*------------------------------------------------------------------------------------------*/
int f_nGetACK;
/*********************************************************************************************
* name: iic_write_24c08
* func: write data to 24C08
* para: unSlaveAddr --- input, chip slave address
* unAddr --- input, data address
* ucData --- input, data value
* ret: none
* modify:
* comment:
*********************************************************************************************/
void slave_transmit_16byte(void)
{
int ucData = 0;
f_nGetACK = 0;
// Initialize iic
rIICADD = 0x10; // S3C2410X slave address
rIICCON = 0xaf; // Enable ACK, interrupt, SET IICCLK=MCLK/16
rIICSTAT = 0x70; // Slave Tx,Start,Enable TX/RX
while(f_nGetACK == 0); // Wait ACK
f_nGetACK = 0;
// Send 16 byte data
while(1)
{
rIICDS = ucData++;
rIICCON = 0xaf; // Resumes IIC operation.
if((rIICSTAT|0x20) == 0) // Detect stop condition
return ;
while(f_nGetACK == 0); // Wait ACK
f_nGetACK = 0;
}
}
/*********************************************************************************************
* name: iic_int_24c04()
* func: IIC interrupt handler
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void __irq iic_int_24c08(void)
{
ClearPending(BIT_IIC);
f_nGetACK = 1;
}
/*********************************************************************************************
* name: iic_test
* func: test iic
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void iic_test(void)
{
f_nGetACK = 0;
// Enable interrupt
rINTMOD = 0x0;
ClearPending(BIT_IIC);
rINTMSK &= ~BIT_IIC;
pISR_IIC = (unsigned)iic_int_24c08;
// Write 16 byte into 24C08
slave_transmit_16byte();
rINTMSK |= BIT_IIC;
uart_printf("\n end.\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -