TA的每日心情 | 开心 2021-12-2 16:03 |
---|
签到天数: 271 天 连续签到: 1 天 [LV.8]以坛为家I
|
经过一段时间的学习,底层文件有了基本的了解,但确实还不够,还要继续下面就简单分享给下一个简单的流水灯程序,
首先就是IO端口的初始化了,在init()函数里,初始化所需要用到的引脚,
ioport_set_pin_dir(PIO_PA17_IDX, IOPORT_DIR_OUTPUT);
ioport_set_pin_level(PIO_PA17_IDX, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_dir(PIO_PA18_IDX, IOPORT_DIR_OUTPUT);
ioport_set_pin_level(PIO_PA18_IDX, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_dir(PIO_PA24_IDX, IOPORT_DIR_OUTPUT);
ioport_set_pin_level(PIO_PA24_IDX, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_dir(PIO_PC23_IDX, IOPORT_DIR_OUTPUT);
ioport_set_pin_level(PIO_PC23_IDX, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_dir(PIO_PA0_IDX, IOPORT_DIR_OUTPUT);
ioport_set_pin_level(PIO_PA0_IDX, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_dir(PIO_PA3_IDX, IOPORT_DIR_OUTPUT);
ioport_set_pin_level(PIO_PA3_IDX, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_dir(PIO_PA21_IDX, IOPORT_DIR_OUTPUT);
ioport_set_pin_level(PIO_PA21_IDX, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_dir(PIO_PA11_IDX, IOPORT_DIR_OUTPUT);
ioport_set_pin_level(PIO_PA11_IDX, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_dir(PIO_PA12_IDX, IOPORT_DIR_OUTPVEL_LOW);
这里将他初始化为低电平输出,
在主函数里面
const char table1[]={17,24,87,0,3,21,11,12};
while(1)
for(m1=10;m1<300;m1+=10) {
for (int j = 0; j < 8; j++) {
gpio_set_pin_low(table1[j]);
delay_ms(m1);
gpio_set_pin_high(table1[j]);
}
for (int j = 0; j < 8; j++) {
gpio_set_pin_low(table1[7-j]);
delay_ms(m1);
gpio_set_pin_high(table1[7-j]);
}
}
}
这里用table1[]来保存相应的引脚号
通过m1 来调节流水灯的快慢,通过两个循环语句是其往返流动
下面是实验现象
http://v.youku.com/v_show/id_XNjI0OTMyNTUy.html
|
|