- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <string.h>
- int main(int argc, char const *argv[])
- {
- char buf[128] = {0};
- int fd = open("/dev/mychrdev", O_RDWR);
- if (fd < 0)
- {
- printf("打开设备文件失败\n");
- return -1;
- }
- printf("打开设备文件成功\n");
- while (1)
- {
- printf("请输入要进行的操作:0(关灯)1(开灯)>");
- fgets(buf, sizeof(buf), stdin); // 在终端读一个字符串
- buf[strlen(buf) - 1] = '\0';
- write(fd, buf, sizeof(buf)); // 将数据传递给内核
- }
- close(fd);
- return 0;
- }
- #ifndef __HEAD__H__
- #define __HEAD__H__
- #define PHY_LED1_MODER 0X50006000
- #define PHY_LED2_MODER 0X50007000
- #define PHY_LED3_MODER 0X50006000
- #define PHY_LED1_ODR 0X50006014
- #define PHY_LED2_ODR 0X50007014
- #define PHY_LED3_ODR 0X50006014
- #define PHY_RCC 0X50000A28
-
- #endif
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <string.h>
- int main(int argc, char const *argv[])
- {
- char buf[128] = {0};
- int fd = open("/dev/mychrdev", O_RDWR);
- if (fd < 0)
- {
- printf("打开设备文件失败\n");
- return -1;
- }
- printf("打开设备文件成功\n");
- while (1)
- {
- printf("请输入要进行的操作:0(关灯)1(开灯)>");
- fgets(buf, sizeof(buf), stdin); // 在终端读一个字符串
- buf[strlen(buf) - 1] = '\0';
- write(fd, buf, sizeof(buf)); // 将数据传递给内核
- }
- close(fd);
- return 0;
- }
