您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 项目/工程管理 > Quartus-ii-11.0-Qsys实现7段数码管实验
Quartusii11.0Qsys实现7段数码管实验目的:用定时器控制数码管分秒计时,4个数码管,有两位小数。环境:QuartusII11.0+NiosII11.0+DE0DE0开发板上的数码管是共阳极的,且已经接在了3.3V电源上。低电平点亮,高电平熄灭。存储器还是片上的。Qsys中:原理图:Nios代码:/********************************Includes********************************/#includesystem.h#includealtera_avalon_pio_regs.h#includealtera_avalon_timer_regs.h#includealt_types.h#includesys/alt_irq.h#includestdio.h#includeunistd.h#includeio.h#includestring.h/********************************Variables********************************///数码管显示字符对应的16进制数alt_u8segtab[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//0-Fstaticalt_u8cnt[4]={0};/********************************Functions********************************/voidinit_timer(void);/**================================functions================================Name:mainDescription:*=========================================================================*/intmain(void){init_timer();//初始化定时器//两位小数IOWR_ALTERA_AVALON_PIO_DATA(SEG1_DP_BASE,0x1);IOWR_ALTERA_AVALON_PIO_DATA(SEG2_DP_BASE,0x1);IOWR_ALTERA_AVALON_PIO_DATA(SEG3_DP_BASE,0x0);IOWR_ALTERA_AVALON_PIO_DATA(SEG4_DP_BASE,0x1);while(1){}return0;}/**================================functions================================Name:ISR_handle_time1Description:定时器中断服务程序*=========================================================================*/voidISR_handle_timer(void*context){//初始状态下4个数码管全部显示0IOWR_ALTERA_AVALON_PIO_DATA(SEG1_DAT_BASE,segtab[cnt[0]]);IOWR_ALTERA_AVALON_PIO_DATA(SEG2_DAT_BASE,segtab[cnt[1]]);IOWR_ALTERA_AVALON_PIO_DATA(SEG3_DAT_BASE,segtab[cnt[2]]);IOWR_ALTERA_AVALON_PIO_DATA(SEG4_DAT_BASE,segtab[cnt[3]]);cnt[0]++;//10进制if(10==cnt[0]){cnt[0]=0;cnt[1]++;}if(6==cnt[1]){cnt[1]=0;cnt[2]++;}if(10==cnt[2]){cnt[2]=0;cnt[3]++;}if(6==cnt[3]){cnt[3]=0;}//清除中断标志寄存器IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_BASE,0x00);}/**================================functions================================Name:init_timerDescription:定时器初始化*=========================================================================*/voidinit_timer(void){IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_BASE,0x00);//清除中断标志寄存器IOWR_ALTERA_AVALON_TIMER_PERIODL(TIMER_BASE,50000000);//设置定时周期1sIOWR_ALTERA_AVALON_TIMER_PERIODH(TIMER_BASE,5000000016);IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_BASE,0x07);//使能中断alt_ic_isr_register(TIMER_IRQ_INTERRUPT_CONTROLLER_ID,TIMER_IRQ,ISR_handle_timer,NULL,0x0);//注册中断}
本文标题:Quartus-ii-11.0-Qsys实现7段数码管实验
链接地址:https://www.777doc.com/doc-7249159 .html