91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

國賽包含第 5 789 屆賽題代碼 省賽包含第 456789 屆賽題代碼 其中省賽第八屆題目還沒找到個(gè)人覺得較好的實(shí)現(xiàn)方法,望廣大網(wǎng)友指點(diǎn)。 下載完的同學(xué)如果覺得好,麻煩給個(gè)五星/哈哈哈

資源截圖

代碼片段和文件信息

/*
??程序說明:?CT117E嵌入式競賽板GPIO模擬I2C總線驅(qū)動(dòng)程序
??軟件環(huán)境:?Keil?uVision?4.10?
??硬件環(huán)境:?CT117E嵌入式競賽板
??日????期:?2011-8-9
*/

#include?“i2c.h“

/**?I2C?總線接口?*/
#define?I2C_PORT?GPIOB
#define?SDA_Pin GPIO_Pin_7
#define?SCL_Pin?GPIO_Pin_6

#define?FAILURE?0
#define?SUCCESS?1

//配置SDA信號線為輸入模式
void?SDA_Input_Mode()
{
GPIO_InitTypeDef?GPIO_InitStructure;

GPIO_InitStructure.GPIO_Pin?=?SDA_Pin;
?? GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_2MHz;
?? GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_IPD; ?

?? GPIO_Init(I2C_PORT?&GPIO_InitStructure);
}

//配置SDA信號線為輸出模式
void?SDA_Output_Mode()
{
GPIO_InitTypeDef?GPIO_InitStructure;

GPIO_InitStructure.GPIO_Pin?=?SDA_Pin;
?? GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_2MHz;
?? GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_Out_PP;

?? GPIO_Init(I2C_PORT?&GPIO_InitStructure);
}

//
void?SDA_Output(?uint16_t?val?)
{
if?(?val?)?{
GPIO_SetBits(I2C_PORTSDA_Pin);
}?else?{
GPIO_ResetBits(I2C_PORTSDA_Pin);
}
}

//
void?SCL_Output(?uint16_t?val?)
{
if?(?val?)?{
GPIO_SetBits(I2C_PORTSCL_Pin);
}?else?{
GPIO_ResetBits(I2C_PORTSCL_Pin);
}
}

//
uint8_t?SDA_Input()
{
return?GPIO_ReadInputDataBit(?I2C_PORT?SDA_Pin);
}

//延時(shí)程序
void?delay1(unsigned?int?n)
{
unsigned?int?i;
for?(?i=0;i}

//I2C總線啟動(dòng)
void?I2CStart(void)
{
SDA_Output(1);delay1(500);
SCL_Output(1);delay1(500);
SDA_Output(0);delay1(500);
SCL_Output(0);delay1(500);
}

//I2C總線停止
void?I2CStop(void)
{
SCL_Output(0);?delay1(500);
SDA_Output(0);?delay1(500);
SCL_Output(1);?delay1(500);
SDA_Output(1);?delay1(500);

}

//等待應(yīng)答
unsigned?char?I2CWaitAck(void)
{
unsigned?short?cErrTime?=?5;
SDA_Input_Mode();?
delay1(500);
SCL_Output(1);delay1(500);
while(SDA_Input())
{
cErrTime--;
delay1(500);
if?(0?==?cErrTime)
{
SDA_Output_Mode();
I2CStop();
return?FAILURE;
}
}
SDA_Output_Mode();
SCL_Output(0);delay1(500);?
return?SUCCESS;
}

//發(fā)送應(yīng)答位
void?I2CSendAck(void)
{
SDA_Output(0);delay1(500);
delay1(500);
SCL_Output(1);?delay1(500);
SCL_Output(0);?delay1(500);

}

//
void?I2CSendNotAck(void)
{
SDA_Output(1);
delay1(500);
SCL_Output(1);?delay1(500);
SCL_Output(0);?delay1(500);

}

//通過I2C總線發(fā)送一個(gè)字節(jié)數(shù)據(jù)
void?I2CSendByte(unsigned?char?cSendByte)
{
unsigned?char??i?=?8;
while?(i--)
{
SCL_Output(0);delay1(500);?
SDA_Output(cSendByte?&?0x80);?delay1(500);
cSendByte?+=?cSendByte;
delay1(500);?
SCL_Output(1);delay1(500);?
}
SCL_Output(0);delay1(500);?
}

//從I2C總線接收一個(gè)字節(jié)數(shù)據(jù)
unsigned?char?I2CReceiveByte(void)
{
unsigned?char?i?=?8;
unsigned?char?cR_Byte?=?0;
SDA_Input_Mode();?
while?(i--)
{
cR_Byte?+=?cR_Byte;
SCL_Output(0);delay1(500);?
delay1(500);?
SCL_Output(1);delay1(500);?
cR_Byte?|=??SDA_Input();?
}
SCL_Output(0);delay1(500);?
SDA_Output_Mode();
return?cR_Byte;
}

//I2C總線初始化
void?i2c_init()
{
GPIO_InitTypeDef?GPIO_InitStructure;

RCC_A

評論

共有 條評論