首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

Nios IDE 编程高手过来看了

Nios IDE 编程高手过来看了

在这个编程环境里,对LCD、RS232的操作都是对文件的读写操作。可是当我对RS232写操作好着哪,读的时候就读不出来!请教!
急急急急急急急!
liangliang
咋没人回哪!
我已经搞定了,就不麻烦各位了!呵呵
liangliang
请教大大是参考哪些资料写的阿,小弟我最近摸rs232实在摸不着头绪说,烦请给点参考罗 ^^
leliang 可以把你做的过程详细点说出来,大家可以分享下。谢谢
你好
这是我整理的IO操作资料! 希望对大家有所帮助! LCD显示 有关的宏定义 #define ESC_TOP_LEFT "[1;0H"//定位光标位置为1行1列 #define ESC_BOTTOM_LEFT "[2;0H"//定位光标位置为2行1列 #define ESC_CLEARE 'K' //清屏 static unsigned char esc = 0x1b; FILE *lcd; lcd = fopen("/dev/lcd_display", "w"); fprintf(lcd, string); 键盘 : 全局变量 volatile int edge_capture; //捕获一个 中断 static void handle_button_interrupts(void* context, alt_u32 id) { /* Cast context to edge_capture's type. * It is important to keep this volatile, * to avoid compiler optimization issues. */ volatile int* edge_capture_ptr = (volatile int*) context; /* Store the value in the Button's edge capture register in *context. */ *edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE); /* Reset the Button's edge capture register. */ IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0); } 初始化 static void init_button_pio() { /* Recast the edge_capture pointer to match the alt_irq_register() function * prototype. */ void* edge_capture_ptr = (void*) &edge_capture; /* Enable all 4 button interrupts. */ IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0xf); /* Reset the edge capture register. */ IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0x0); /* Register the interrupt handler. */ alt_irq_register( BUTTON_PIO_IRQ, edge_capture_ptr,handle_button_interrupts); } 测试 static void TestButtons( void ) { alt_u8 buttons_tested; alt_u8 all_tested; /* Variable which holds the last value of edge_capture to avoid * "double counting" button/switch presses */ int last_tested; /* Initialize the Buttons/Switches (SW0-SW3) */ init_button_pio(); /* Initialize the variables which keep track of which buttons have been * tested. */ buttons_tested = 0x0; all_tested = 0xf; /* Initialize edge_capture to avoid any "false" triggers from * a previous run. */ edge_capture = 0; /* Set last_tested to a value that edge_capture can never equal * to avoid accidental equalities in the while() loop below. */ last_tested = 0xffff; /* Print a quick message stating what is happening */ printf("\nA loop will be run until all buttons/switches have been pressed.\n\n"); printf("\n\tNOTE: Once a button press has been detected, for a particular button,\n\tanyfurther presses will be ignored!\n\n"); /* Loop until all buttons have been pressed. * This happens when buttons_tested == all_tested. */ /* last_tested = 0xffff; * edge_capture = 0; * buttons_tested = 0x0; * all_tested = 0xf;*/ while ( buttons_tested != all_tested ) { if (last_tested == edge_capture) { continue; } else { last_tested = edge_capture; switch (edge_capture) { case 0x1: printf("\nButton 1 (SW0) Pressed.\n"); buttons_tested = buttons_tested | 0x1; break; case 0x2: printf("\nButton 2 (SW1) Pressed.\n"); buttons_tested = buttons_tested | 0x2; break; case 0x4: printf("\nButton 3 (SW2) Pressed.\n"); buttons_tested = buttons_tested | 0x4; break; case 0x8: printf("\nButton 4 (SW3) Pressed.\n"); buttons_tested = buttons_tested | 0x8; break; } } } /* Disable button interrupts for anything outside this loop. */ IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0x0); printf ("\nAll Buttons (SW0-SW3) were pressed, at least, once.\n"); usleep(2000000); return; } 七段码 相关的宏定义 static void sevenseg_set_hex(alt_u8 hex) { static alt_u8 segments[16] = { 0x81, 0xCF, 0x92, 0x86, 0xCC, 0xA4, 0xA0, 0x8F, 0x80, 0x84, /* 0-9 */ 0x88, 0xE0, 0xF2, 0xC2, 0xB0, 0xB8 }; /* a-f */ alt_u32 data = segments[hex & 15] | (segments[(hex >> 4) & 15] << 8);*/ IOWR_ALTERA_AVALON_PIO_DATA(SEVEN_SEG_PIO_BASE,data); } static void SevenSegCount( void ) { alt_u32 count; for (count = 0; count <= 0xff; count++) { sevenseg_set_hex( count ); usleep(50000); } } 串口: FILE *uart; uart=fopen("/dev/uart1","w+"); // 初始化 if(uart==NULL) { printf("Unable to open uart\n"); exit(0); } char *str; fprintf(uart,str); //向串口写 fscanf(uart,"%s",str); //向串口读
liangliang
好象还没有说完吧。
你好
ding
太感谢了!~~老大,有没有串口具体的做法,给小弟发一份,谢谢。我的邮箱是xiaoyu3729@126.com
为了中国的电子行业发展尽自已的一份力!!!!`~~~
请问如果我要是用uart发送,而用电脑的串口接受是否可以?用串口调试助手。 我是这样 main() { .... char* str="hello world/n"; fp = fopen("/dev/uart1","w"); while(1) { if(fp) { fprintf(fp,str); for(i=0;i<400000;i++){}; } } } 也就是让串口不停的发数据,是否可以?可是我却接受不到。why?
baomi
已经搞定,竟然范了一大错误,faint
baomi
兄弟的大错是什么呢,拿出来说说啊,避免以后有同样的人出现 啊!
太感谢了!~~
挑战颠峰,挑战生活!
谢谢楼主整理.

ytiger,我也遇到pc机收不到的问题,你是怎么解决的??
我的问题是txd发送的绿灯都亮了,可pc收不到(也是用调试工具comtools)?
我思故我在
返回列表