按鍵控制數碼管顯示
阿新 • • 發佈:2019-02-01
/*
* ====================================================
* Filename: main.c
* Description:
* Version:
* Created:
* Revision: none
* Compiler: Nios II IDE
* Author: lasers
* Company: 441lab
* =====================================================
*/
#include "../inc/sopc.h"//包含nios系統資訊#include " altera_avalon_pio_regs.h"//PIO核心資訊描述#include "sys/alt_irq.h"//中斷訪問檔案
#include "stdio.h"//輸出檔案
//volatile alt_u32 edge_capture;void display(); //顯示函式宣告
alt_u32 btd_cnt =0; //定義全域性變數,作為SEG顯示的引數void key_irq(void*context, alt_u32 id) //按鍵中斷函式{
// volatile alt_u32 * edge_capture_ptr = (volatile alt_u32 *) context;
//// *edge_capture_ptr = KEY->EDGE_CAPTURE;if(btd_cnt <9)
{
btd_cnt++;
}
else
{
btd_cnt =0;
}
display(btd_cnt);
KEY->EDGE_CAPTURE =0; //邊沿捕獲暫存器清零}
int init_key() //按鍵中斷初始化函式{
// void * edge_capture_ptr = (void *) &edge_capture;
KEY->INTERRUPT_MASK =1; //開按鍵中斷
KEY->EDGE_CAPTURE =0; //邊沿捕獲暫存器清零return alt_irq_register(KEY_PIO_IRQ,NULL,key_irq); //註冊中斷服務函式,成功則返回0}
void display(num) //數碼管顯示函式{
alt_u8 segtab[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x18};
SEG0->DATA = segtab[num];
}
int main()
{
if(!init_key()) //判斷初始化是否成功,成功返回0 {
printf("Key irq success!\n");
}
else
{
printf("Error irq!\n");
}
while(1)
{
display(btd_cnt);
}
}
* ====================================================
* Filename: main.c
* Description:
* Version:
* Created:
* Revision: none
* Compiler: Nios II IDE
* Author: lasers
* Company: 441lab
* =====================================================
*/
#include "../inc/sopc.h"//包含nios系統資訊#include "
#include "stdio.h"//輸出檔案
//volatile alt_u32 edge_capture;void display(); //顯示函式宣告
alt_u32 btd_cnt =0; //定義全域性變數,作為SEG顯示的引數void key_irq(void*context, alt_u32 id) //按鍵中斷函式{
// volatile alt_u32 * edge_capture_ptr = (volatile alt_u32 *) context;
{
btd_cnt++;
}
else
{
btd_cnt =0;
}
display(btd_cnt);
KEY->EDGE_CAPTURE =0; //邊沿捕獲暫存器清零}
int init_key() //按鍵中斷初始化函式{
// void * edge_capture_ptr = (void *) &edge_capture;
KEY->INTERRUPT_MASK =1; //開按鍵中斷
KEY->EDGE_CAPTURE =0; //邊沿捕獲暫存器清零return alt_irq_register(KEY_PIO_IRQ,NULL,key_irq); //註冊中斷服務函式,成功則返回0}
void display(num) //數碼管顯示函式{
alt_u8 segtab[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x18};
SEG0->DATA = segtab[num];
}
int main()
{
if(!init_key()) //判斷初始化是否成功,成功返回0 {
printf("Key irq success!\n");
}
else
{
printf("Error irq!\n");
}
while(1)
{
display(btd_cnt);
}
}