⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 new0001.c

📁 基于at91rm9200的串口驱动
💻 C
字号:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
int main()
{
 char szsendbuf[4];
 int fd,c,res,nsize = 4;
 FILE *pfile;
 int filel;
 struct termios oldtio,newtio;
 struct stat st;
 fd = open("/dev/ttyS0",O_RDWR | O_NOCTTY);
 tcgetattr(fd, &oldtio);
 bzero(&newtio, sizeof(newtio));
 newtio.c_cflag = B115200 | CRTSCTS | CS8 | CLOCAL | CREAD;
 newtio.c_iflag = IGNPAR | ICRNL;
 tcflush(fd, TCIFLUSH);
 tcsetattr(fd, TCSANOW, &newtio);
 stat("a.txt", &st);
 pfile = fopen("a.txt", "r");
 filel = st.st_size;
 while(4 == nsize)
 {
  bzero(szsendbuf, 4);
  nsize = fread(szsendbuf, 1, 4, pfile);
  nsize = write(fd, szsendbuf, nsize);
 }
 fclose(pfile);
 tcsetattr(fd, TCSANOW, &oldtio);
 close(fd);
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -