程序如下
#include<stdio.h>
#include<string.h>
#include "system.h"
int main ()
{
char* msg = "Detected the character 't'.\n";
FILE* fp;
char prompt = 0;
printf("Please Enter some characters: \n");
fp = fopen ("/dev/uart_0", "r+"); //打开文件进行读和写
if (fp)
{
while (prompt != 'v') // 循环直至接收到 'v'
{
prompt = getc(fp); // 从JTAG UART中获取字符
if (prompt == 't')
{ // 如果字符为 't' 打印信息
fwrite (msg, strlen (msg), 1, fp);
}
if (ferror(fp))// 检查错误是否与文件指针一起出现
clearerr(fp);// 如果是,清除它
}
fprintf(fp, "Closing the UART file handle.\n");
fclose (fp);
}
else
{
printf("Fail to open file...\n");
}
return 0;
} 错误如下
错误的原因
详细的连接地址http://www.altera.com.cn/support/kdb/solutions/rd10152012_873.html