STM8S103 IO口控制
2021-09-03 来源:eefocus
STM8的IO口控制,说好听点是灵活多变,可以各种定制,可是用起来那真是烦,要定义的好多!
void io_init()
{
PA_DDR |= (1<<3);
PA_CR1 |= (1<<3);
PA_CR2 &= ~(1<<3);//PA3设置为推挽输出
PD_DDR |= (1<<5);
PD_CR1 |= (1<<5);
PD_CR2 &= ~(1<<5); //PD5设置为推挽输出
PD_DDR &= ~(1<<6); //PD6设置为悬浮输入
PD_DDR |= (1<<3);
PD_CR1 |= (1<<3);
PD_CR2 &= ~(1<<3); //PD3设置为推挽输出
PD_ODR |= (1<<3); //PD3初始电平为高
PA_DDR |= (1<<1);
PA_CR1 |= (1<<1);
PA_CR2 &= ~(1<<1);
PA_ODR |= (1<<1); //LEGD初始为1
PA_DDR |= (1<<2);
PA_CR1 |= (1<<2);
PA_CR2 &= ~(1<<2);
PA_ODR |= (1<<2); //LEDR初始为1
}
相关文章