欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
void IO_IN_UpData(void) 這C語言函數其中的邏輯關系 有大佬能指點下嗎?
[打印本頁]
作者:
0711zhao
時間:
2022-3-13 10:01
標題:
void IO_IN_UpData(void) 這C語言函數其中的邏輯關系 有大佬能指點下嗎?
#include <common.h>
#define IO_ON 1
#define IO_OFF 0
GPIO_TypeDef *IO_OUT_GPIOx[1] = {GPIOB};
uint16_t IO_OUT_GPIO_Pin[1] = {GPIO_Pin_9};
BitAction IO_OUT_BitVal[1] = {Bit_RESET};
uint8_t IO_IN_value[16];
void IO_Init(void)
{
uint8_t i;
for(i = 0; i < 16; i++)
IO_IN_value[i] = IO_OFF;
}
uint8_t* IO_GetDate() //16位IO口的數據
{
static uint8_t IN[16];//C不支持在函數外返回局部變量地址,除非定義局部變量為static
IN[0] = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_6);
IN[1] = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_7);
IN[2] = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0);
IN[3] = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1);
IN[4] = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_10);
IN[5] = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11);
IN[6] = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_12);
IN[7] = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_13);
IN[8] = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14);
IN[9] = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15);
IN[10] = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_8);
IN[11] = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_11);
IN[12] = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_12);
IN[13] = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_5);
IN[14] = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_6);
IN[15] = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_7);
return IN;
}
void IO_IN_UpData(void) //這個函數不是很明白其中的邏輯關系 有大佬能指點下嗎?
{
uint8_t i;
uint8_t *In_Buf;
static uint8_t IO_in_Buf[16]; //16位數據緩存
In_Buf = IO_GetDate(); //把獲取的16位IO口數據給緩存
for(i = 0; i < 16; i++)
{
IO_in_Buf[i] = IO_in_Buf[i] << 1; //沒得到一位數據左移一位
IO_in_Buf[i] &= 0x3f;
if((*(In_Buf+i)) == 0x01)
{
IO_in_Buf[i] |= 0x01; //為什么
}
}
for(i = 0; i < 16; i++)
{
if(IO_in_Buf[i] == 0)
{
IO_IN_value[i] = IO_OFF;
}
else if(IO_in_Buf[i] == 0x3f)
{
IO_IN_value[i] = IO_ON;
}
}
}
void IO_OUT_UpData(uint8_t add,uint8_t size,uint8_t *Mode,BitAction shanshuo)//(地址 大小 模式 閃爍)
//bitactiion就是一個枚舉類型的變量,表示這個位是高電平還是低電平
{
uint8_t i = 0;
for(i = add;i < (add + size);i++) //首地址+長度 累加
{
if(Mode[i] == 2)
{
IO_OUT_BitVal[i] = shanshuo; //模式為2 閃爍
}
else if(Mode[i] == 1)
{
IO_OUT_BitVal[i] = Bit_SET; //模式為1 高電平
}
else
{
IO_OUT_BitVal[i] = Bit_RESET; //其他為低電平
}
GPIO_WriteBit(IO_OUT_GPIOx[i], IO_OUT_GPIO_Pin[i], IO_OUT_BitVal[i]); //寫入GPIO的針腳的電平狀態
}
}
void IO_PowerRun(void)
{
uint8_t power_mode = 2; //電源模式為2
static BitAction LED_shanshuo = Bit_RESET; //LED閃爍 置0
if(Bit_RESET == LED_shanshuo)
{
LED_shanshuo = Bit_SET; //為0置1
}
else
{
LED_shanshuo = Bit_RESET; //為1置0 閃爍
}
IO_OUT_UpData(0,1,&power_mode,LED_shanshuo); //為什么沒有延遲
}
復制代碼
作者:
0711zhao
時間:
2022-3-13 10:02
里面的備注是我自己的理解加的 如果有錯誤希望大佬指正
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1