【完美体育·(中国)手机网页版MYD-Y6ULX-V2开发板】LED流水灯
文章来源: 发布日期:2023.3.13 浏览次数:582 次 |
由评测者“华仔stm32”提供。
对GPIO操作是最基本的功能之一。
【材料准备】
1、LED灯3个
2、杜绑线4条
3、面包板一块
【软件准备】
1、查看\01_Documents\User_Manual\Chinese\硬件手册 下面的MYD-Y6ULX-V2 硬件用户手册-V1.0.pdf。找到第23页4.7. GPIO/I2C/SPI/UART 接口。由于没有给出专门的GPIO接品,这里利用UART3接口来做GPIO输出。
2、查看IMX6ULL数据手册(工业级)找到对UART3的端口定义:
这里我们采用GPIO1_24 到26作为输出端口
J14的5、6、8分析接到面包板LED的正极,3脚接到面包板的地
3、编写led.c代码如下:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
int main(void)
{
FILE *fp=NULL;
int i=0;
fp = fopen("/sys/class/gpio/export", "w");
if (fp == NULL)
{
perror("fopen");
return -1;
}
fprintf(fp,"%d",24);
fclose(fp);
fp = fopen("/sys/class/gpio/export", "w");
if (fp == NULL)
{
perror("fopen");
return -1;
}
fprintf(fp,"%d",25);
fclose(fp);
fp = fopen("/sys/class/gpio/export", "w");
if (fp == NULL)
{
perror("fopen");
return -1;
}
fprintf(fp,"%d",26);
fclose(fp);
fp = fopen("/sys/class/gpio/gpio24/direction","w");
fprintf(fp,"out");
fclose(fp);
fp = fopen("/sys/class/gpio/gpio25/direction","w");
fprintf(fp,"out");
fclose(fp);
fp = fopen("/sys/class/gpio/gpio26/direction","w");
fprintf(fp,"out");
fclose(fp);
for(i=0; i<100;i++) {
fp = fopen("/sys/class/gpio/gpio24/value", "w");
fprintf(fp,"%d",1);
fclose(fp);
fp = fopen("/sys/class/gpio/gpio25/value", "w");
fprintf(fp,"%d",0);
fclose(fp);
fp = fopen("/sys/class/gpio/gpio26/value", "w");
fprintf(fp,"%d",0);
fclose(fp);
sleep(1);
fp = fopen("/sys/class/gpio/gpio24/value", "w");
fprintf(fp,"%d",0);
fclose(fp);
fp = fopen("/sys/class/gpio/gpio25/value", "w");
fprintf(fp,"%d",1);
fclose(fp);
fp = fopen("/sys/class/gpio/gpio26/value", "w");
fprintf(fp,"%d",0);
fclose(fp);
sleep(1);
fp = fopen("/sys/class/gpio/gpio24/value", "w");
fprintf(fp,"%d",0);
fclose(fp);
fp = fopen("/sys/class/gpio/gpio25/value", "w");
fprintf(fp,"%d",0);
fclose(fp);
fp = fopen("/sys/class/gpio/gpio26/value", "w");
fprintf(fp,"%d",1);
fclose(fp);
sleep(1);
}
fp = fopen("/sys/class/gpio/unexport","w");
fprintf(fp,"%d",24);
fclose(fp);
fp = fopen("/sys/class/gpio/unexport","w");
fprintf(fp,"%d",25);
fclose(fp);
fp = fopen("/sys/class/gpio/unexport","w");
fprintf(fp,"%d",26);
fclose(fp);
return 0;
}
编译好后上传开发板,运行程序,就可以看到三个LED交替闪烁了。