/**********************************************************************
太原工业学院机器人队
作者:
功能:iic双机通讯中的从属接收
**********************************************************************///
#include"../ucos-ii/includes.h" /* uC/OS interface */
#include "../ucos-ii/add/osaddition.h"
#include "../inc/drivers.h"
#include "../inc/sys/lib.h"
#include "../inc/sys/spi.h"
#include "../inc/sys/gpio_usr.h"
#include <string.h>
#include <stdio.h>
void init()
{
rGPEUP |= 0xc000; //Pull-up disable
rGPECON &= ~0xf0000000;
rGPECON |= 0xa0000000; //GPE15:IICSDA , GPE14:IICSCL
rIICCON = 0xaf;
rIICADD = 0x10; //2410 slave address = [7:1]
rIICSTAT = 0x10; //从属接受模式 //IIC bus data output enable(Rx/Tx)
}
void waitsame()
{
while(!(rIICSTAT&0x4)); //检测接受到的与IICADD中的地址值是否匹配
while(!(rIICCON&0x10)); //检测是否收到数据,不管是地址还是一般的数据
rIICCON &=~(1<<4); //恢复寄存器操作,不然主机不能发数据;
}
void restring(char *data,int len)
{
int i;
waitsame(); //匹配检测
for(i=0;i<len;i++) //连收数据
{
while(!(rIICCON&0x10));
rIICCON &=~(1<<4);
data = rIICDS;
Uart_Printf(0,"the number is %d\n",data);
}
}
void task2(int num)
{
int j;
char str2[]={1,1,1,1,1,1,1,1,1};
for(j=0;j<num;j++)
{
restring(str2,9);
}
}
int main(void)
{
INT32U ostimeget,p;
int y;
ARMTargetInit(); //串口的初始化及波特率设置,115200,9600,9600
init();
task2(2);
return 0;
}
|