OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3980|回复: 2

纯小白求教,怎么把一个引脚的输出值赋给另一个引脚?

[复制链接]

3

主题

7

帖子

0

精华

新手上路

积分
27
金钱
27
注册时间
2018-8-16
在线时间
13 小时
发表于 2018-10-12 23:11:36 | 显示全部楼层 |阅读模式
10金钱
原理图上有16个DI口,与16个GPIO相连;24个DO口,与24个GPIO相连,我想设置所有DO输出高电平,也就是GPOI_SetBits(),把一个DO的输出给一个DI,也就是把DO的输出值赋给DI,用来测试DI/DO是否正常,这两个函数GPIO_GetDI(DI_PORT enDIPort,BOOL *pbBitstatus){}和GPIO_SetDO(DO_PORT enDOPort,BOOL bBitstatus){}括号里怎么写啊?有具体的代码最好,非常感谢!!!

typedef enum DI_PORT
{
        DI_01,
        DI_02,
        DI_03,
        DI_04,
        DI_05,
        DI_06,
        DI_07,
        DI_08,
        DI_09,
        DI_10,
        DI_11,
        DI_12,
        DI_13,
        DI_14,
        DI_15,
        DI_16,
        DI_BUTT
}DI_PORT;


typedef enum DO_PORT
{
        DO_01=0,
        DO_02,
        DO_03,
        DO_04,
        DO_05,
        DO_06,
        DO_07,
        DO_08,
        DO_09,
        DO_10,
        DO_11,
        DO_12,
        DO_13,
        DO_14,
        DO_15,
        DO_16,
        DO_17,
        DO_18,
        DO_19,
        DO_20,
        DO_21,
        DO_22,
        DO_23,
        DO_24,
        DO_BUTT
}DO_PORT;

typedef enum {false,ture}BOOL;


DI_GPIO_Init(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD.ENABLE);
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG,ENABLE);
       
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN;
        GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOD,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN;
        GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOG,&GPIO_InitStructure);       
}

DO_GPIO_Init(void)
{
        GPIO_InitTypeDef GPIOInitStructure;
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE|RCC_AHB1Periph_GPIOF,ENABLE);
       
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOA,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOB,&GPIO_InitStructure);       
       
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4|GPIO_Pin_5;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOC,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOD,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOE,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOF,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOG,&GPIO_InitStructure);
}

GPIO_GetDI(DI_PORT enDIPort,BOOL *pbBitstatus)
{
               
}


GPIO_SetDO(DO_PORT enDOPort,BOOL bBitstatus)
{

}


正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165524
金钱
165524
注册时间
2010-12-1
在线时间
2116 小时
发表于 2018-10-13 02:06:16 | 显示全部楼层
先好好学习下我们的GPIO例程。。
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复

使用道具 举报

1

主题

66

帖子

0

精华

高级会员

Rank: 4

积分
526
金钱
526
注册时间
2018-8-13
在线时间
62 小时
发表于 2018-10-13 07:49:50 | 显示全部楼层
GPIO_Write( GPIOx, GPIO_ReadInputData(GPIOx));这样就可以了,第一个GPIOx为想要输出的那个端口(16位),第二个GPIOx为想要读入的那个端口(16位)当然在些之前还需要做初始化及硬件连接工作,如果是想要一位一位的读写可以用GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);当然读取输入的函数得到的参数做个判断,再根据结果是0还是1来决定输入函数BitVal的值。希望对你有帮助。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-8 12:27

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表