今天看了一个例程,在nios2中用c实现一个电子钟. c是大概是这样的#include <stdio.h> #include "system.h" #include "altera_avalon_pio_regs.h" #include <unistd.h> #include "sys/alt_irq.h" #include "alt_types.h" #include "LCD.h"//自己设计的头文件 static volatile alt_u8 hour; static volatile alt_u8 minute; static volatile alt_u8 second; static volatile alt_u16 year; static volatile alt_u8 month; static volatile alt_u8 day; static volatile alt_u8 max_day; static int flag; static int begin; static alt_u8 str1[17]; static alt_u8 str2[17]; volatile int edge_capture; alt_u8 Tyear, Hyear, Dyear, Nyear;
static void last_day(){ if(month==4||month==5||month==9||month==11) max_day=30; else if(month==2){ if((year%4==0&&year%100!=0)||year%400==0) max_day=29; else max_day=28; } else max_day=31; } static void handle_button_interrupts(void* context, alt_u32 id){ volatile int* edge_capture_ptr=(volatile int*)context; *edge_capture_ptr=IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE); IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE,0); } static void init_button_pio(){ void* edge_capture_ptr=(void*)&edge_capture; IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE,0xf); IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE,0x0); alt_irq_register(BUTTON_PIO_IRQ,edge_capture_ptr,handle_button_interrupts); } void LCD_Init()//lcd初始化 { lcd_write_cmd(LCD_DISPLAY_BASE,0x38); //lcd_write_cmd在头文件"LCD.h"中对应IOWR(base, 0, data) usleep(2000); lcd_write_cmd(LCD_DISPLAY_BASE,0x0C); usleep(2000); lcd_write_cmd(LCD_DISPLAY_BASE,0x01); usleep(2000); lcd_write_cmd(LCD_DISPLAY_BASE,0x06); usleep(2000); lcd_write_cmd(LCD_DISPLAY_BASE,0x80); usleep(2000); }
....... ....... static void handle_button_press(){ if(flag==0){ switch(edge_capture){ case 0x1: timer_set(); display_time1(); usleep(500000); display_time(); break; case 0x2: display_day(); break; case 0x4: display_time(); break; default: display_time(); break; } } ........ ........ int main() { init_button_pio(); LCD_Init(); initial_time(); while(1){ if(begin==0){ usleep(1000000); second++; if(second>=60){ second=0; minute++; } if(minute>=60){ minute=0; hour++; } if(hour>=24){ hour=0; day++; } last_day(); if(day>max_day){ day=1; month++; last_day(); } if(month>12){ day=1; year++; } } if(edge_capture!=0){ handle_button_press(); } else{ if(flag==3||flag==4||flag==5||flag==6) display_day(); else display_time(); } } 我想问一下:以上程序中标红色的那些字 1.(void LCD_Init中)应该是为了在对lcd初始化中实现某项功能吧?? 这些数对应的是什么功能呢?或者比如我自己要写程序时哪里能查到??我查了altra的几个文档都没有说明啊 2.(void handle_button_press中)应该是edge_capture在电路板上按下不同按键时捕获的值吧?? 哪里说明的那几个按键对应的是这几个数字?? 小弟初学,请帮帮忙 谢谢了!! |