完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>
扫一扫,分享给好友
#include
#include "system.h" #include "altera_avalon_pio_regs.h" #include #include "sys/alt_irq.h" #include "alt_types.h" #include "clock.h" sta tic 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]=' '; LCD_Line2(); LCD_Show_Text(str1); } static void display_day1(){ str1[0]=' '; str1[1]=' '; str1[2]=' '; str1[3]=' '; str1[4]=' '; str1[5]=' '; str1[6]=' '; 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]=' '; LCD_Line2(); LCD_Show_Text(str1); } static void display_day2(){ 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]=' '; str1[9]=' '; str1[10]='-'; str1[11]=(alt_u8)(day/10+0x30); str1[12]=(alt_u8)(day%10+0x30); str1[13]=' '; str1[14]=' '; str1[15]=' '; str1[16]=' '; LCD_Line2(); LCD_Show_Text(str1); } static void display_day3(){ 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]=' '; str1[12]=' '; str1[13]=' '; str1[14]=' '; str1[15]=' '; str1[16]=' '; LCD_Line2(); LCD_Show_Text(str1); } static void display_time(){ str2[0]=' '; str2[1]=' '; str2[2]=' '; str2[3]=' '; str2[4]=(alt_u8)(hour/10+0x30); str2[5]=(alt_u8)(hour%10+0x30); str2[6]=':'; str2[7]=(alt_u8)(minute/10+0x30); str2[8]=(alt_u8)(minute%10+0x30); str2[9]=':'; str2[10]=(alt_u8)(second/10+0x30); str2[11]=(alt_u8)(second%10+0x30); str2[12]=' '; str2[13]=' '; str2[14]=' '; str2[15]=' '; str2[16]=' '; LCD_Line2(); LCD_Show_Text(str2); } static void display_time1(){ str2[0]=' '; str2[1]=' '; str2[2]=' '; str2[3]=' '; str2[4]=' '; str2[5]=' '; str2[6]=':'; str2[7]=(alt_u8)(minute/10+0x30); str2[8]=(alt_u8)(minute%10+0x30); str2[9]=':'; str2[10]=(alt_u8)(second/10+0x30); str2[11]=(alt_u8)(second%10+0x30); str2[12]=' '; str2[13]=' '; str2[14]=' '; str2[15]=' '; str2[16]=' '; LCD_Line2(); LCD_Show_Text(str2); } static void display_time2(){ str2[0]=' '; str2[1]=' '; str2[2]=' '; str2[3]=' '; str2[4]=(alt_u8)(hour/10+0x30); str2[5]=(alt_u8)(hour%10+0x30); str2[6]=':'; str2[7]=' '; str2[8]=' '; str2[9]=':'; str2[10]=(alt_u8)(second/10+0x30); str2[11]=(alt_u8)(second%10+0x30); str2[12]=' '; str2[13]=' '; str2[14]=' '; str2[15]=' '; str2[16]=' '; LCD_Line2(); LCD_Show_Text(str2); } static void exit_set(){ flag=0; edge_capture=0; begin=0; } static void set_houri(){ if(hour==23) hour=0; else hour=hour+1; edge_capture=0; } static void set_hourd(){ if(hour==0) hour=23; else hour=hour-1; edge_capture=0; } static void set_minutei(){ if(minute==59) minute=0; else minute=minute+1; edge_capture=0; } static void set_minuted(){ if(minute==0) minute=59; else minute=minute-1; edge_capture=0; } static void set_yeari(){ if(year==9999) year=1; else year=year+1; edge_capture=0; } static void set_yeard(){ if(year==1) year=9999; else year=year-1; edge_capture=0; } static void set_monthi(){ if(month==12) month=1; else month=month+1; edge_capture=0; } static void set_monthd(){ if(month==1) month=12; else month=month-1; edge_capture=0; } static void set_dayi(){ last_day(); if(day==max_day) day=1; else day=day+1; edge_capture=0; } static void set_dayd(){ if(day==1) day=max_day; else day=day-1; edge_capture=0; } 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; } } else if(flag==1){ switch(edge_capture){ case 0x1: timer_set(); display_time2(); usleep(500000); display_time(); break; case 0x2: set_houri(); // if (edge_capture!=0) display_time1(); usleep(500000); display_time(); usleep(500000); break; case 0x4: set_hourd(); // if (edge_capture!=0) display_time1(); usleep(500000); display_time(); usleep(500000); break; // end if; case 0x8: exit_set(); display_time(); default: display_time(); break; } } else if(flag==2){ switch(edge_capture){ case 0x1: timer_set(); display_day1(); usleep(500000); display_day(); break; case 0x2: set_minutei(); // if (edge_capture!=0) display_time2(); usleep(500000); display_time(); usleep(500000); break; //end if; case 0x4: set_minuted(); // if (edge_capture!=0) display_time2(); usleep(500000); display_time(); usleep(500000); break; // end if; case 0x8: exit_set(); display_time(); default: display_time(); break; } } else if(flag==3){ switch(edge_capture){ case 0x1: timer_set(); display_day2(); usleep(500000); display_day(); break; case 0x2: set_yeari(); // if (edge_capture!=0) display_day1(); usleep(500000); display_day(); usleep(500000); break; // end if; case 0x4: set_yeard(); // if (edge_capture!=0) display_day1(); usleep(500000); display_day(); usleep(500000); break; // end if; case 0x8: exit_set(); display_time(); default: display_day(); break; } } else if(flag==4){ switch(edge_capture){ case 0x1: timer_set(); display_day3(); usleep(500000); display_day(); break; case 0x2: set_monthi(); // if (edge_capture!=0) display_day2(); usleep(500000); display_day(); usleep(500000); break; //end if; case 0x4: set_monthd(); // if (edge_capture!=0) display_day2(); usleep(500000); display_day(); usleep(500000); break; // end if; case 0x8: exit_set(); display_time(); default: display_day(); break; } } else if(flag==5){ switch(edge_capture){ case 0x1: timer_set(); display_time1(); usleep(500000); display_time(); break; case 0x2: set_dayi(); // if (edge_capture!=0) display_day3(); usleep(500000); display_day(); usleep(500000); break; // end if; case 0x4: set_dayd(); // if (edge_capture!=0) display_day3(); usleep(500000); display_day(); usleep(500000); break; //end if; case 0x8: exit_set(); display_time(); default: display_day(); 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(); } IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,second); } } |
|
相关推荐 |
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
378 浏览0 评论
求FPGA 驱动控制ltc2271 或者 ltc2180 或者 ltc2190或者 ltc2202 的代码
1601 浏览0 评论
457 浏览0 评论
求助:遇见诡异问题,FPGA模块A输出端口连接模块B输入后,模块A不能正常工作的
1725 浏览1 评论
510 浏览0 评论
4512 浏览100 评论
小黑屋|手机版|Archiver|德赢Vwin官网(湘ICP备2023018690号)
GMT+8, 2024-8-25 08:32, Processed in 0.571305 second(s), Total 67, Slave 51 queries .
Powered by德赢Vwin官网 网
© 2015bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号