-
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <termios.h>
- #include <errno.h>
- #include <ctype.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include <unistd.h>
- #include"pthread.h"
- #include <sys/ioctl.h>
- //#include "serial_test.h"
- int main()
- {
- int led_on;
- int led_num;
- char arge[3];
- int uart_fd;
- int led_fd;
- int beep_fd;
- beep_fd=open("/dev/PWM-Test",0);
- uart_fd=open("/dev/tq2440_serial0",O_RDWR,0);
- led_fd=open("/dev/GPIO-Control",0);
- if((beep_fd&&uart_fd&&led_fd)<0)
- {
- perror("Open device fail");
- exit(1);
- }
- write(uart_fd,"uart control leds\n",18);
- while(1)
- {
- read(uart_fd,arge,2);
- write(uart_fd,arge,2);
- if(arge[0]>0x31||arge[0]<0x30&&arge[1]>0x33||arge[1]<0x30)
- {
- ioctl(beep_fd,1,10);
- usleep(500000);
- ioctl(beep_fd,0);
- }
- ioctl(led_fd,(arge[0]-48),(arge[1]-48));
- }
- // printf("The number is:%d\n",arge[0]);
- close(uart_fd);
- close(led_fd);
- close(beep_fd);
- }
串口取数字,点亮LED灯,取值出错蜂鸣器响一下!
|