完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
#include #include "system.h" #include "altera_avalon_pio_regs.h" #include #include "sys/alt_irq.h" #include "alt_types.h" #include "clock.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;//保u23384 一u20010 月u20013 的u26368 大u22825 数 static int flag; static int begin; static alt_u8 str1[17]; static alt_u8 str2[17]; volatile int edge_capture; 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); IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE,0xf); } 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_write_cmd(LCD_DISPLAY_BASE,0x38);//设u23450 接u21475 为位u-244 2行u-244 5*8字u20307 usleep(2000); lcd_write_cmd(LCD_DISPLAY_BASE,0x0C);//开u26174 示 usleep(2000); lcd_write_cmd(LCD_DISPLAY_BASE,0x01);//清u23631 usleep(2000); lcd_write_cmd(LCD_DISPLAY_BASE,0x06);//模u24335 设u23450 usleep(2000); lcd_write_cmd(LCD_DISPLAY_BASE,0x80);//设u23450 DDRAM地u22336 usleep(2000); } //------------------------------------------------------------------------- void LCD_Show_Text(char* Text) { int i; for(i=0;i lcd_write_data(LCD_DISPLAY_BASE,Text[i]); usleep(200); } } //------------------------------------------------------------------------- void LCD_Line2() { lcd_write_cmd(LCD_DISPLAY_BASE,0x80|0x40); usleep(200); } static void initial_time(){ hour=12; minute=30; second=0; year=2010; month=7; day=28; flag=0; begin=0; } void timer_set(){ if(flag<5) flag++; else flag=1; if(flag==1){ begin=0; second=0; edge_capture=0; } else if(flag==2){ begin=0; second=0; edge_capture=0; } else if(flag==3){ begin=0; edge_capture=0; } else if(flag==4){ begin=0; edge_capture=0; } else if(flag==5){ begin=0; edge_capture=0; } } static void display_day(){ alt_u8 Tyear, Hyear, Dyear, Nyear; Tyear = (alt_u8)(year/1000); Hyear = (alt_u8)((year%(1000*Tyear))/100); Dyear = (alt_u8)((year%(1000*Tyear+100*Hyear))/10); Nyear = (alt_u8)(year%(1000*Tyear+100*Hyear+10*Dyear)); str1[0]=' '; str1[1]=' '; str1[2]=' '; str1[3]= (alt_u8)(Tyear+0x30); str1[4]= (alt_u8)(Hyear+0x30); str1[5]= (alt_u8)(Dyear+0x30); str1[6]= (alt_u8)(Nyear+0x30); str1[7]='-'; str1[8]=(alt_u8)(month/10+0x30); str1[9]=(alt_u8)(month%10+0x30); str1[10]='-'; str1[11]=(alt_u8)(day/10+0x30); str1[12]=(alt_u8)(day%10+0x30); str1[13]=' '; str1[14]=' '; str1[15]=' '; str1[16]=' |