亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? timer0.c

?? NIOS系統中的定時器編程實現
?? C
字號:
/*************************************************************************
 * Copyright (c) 2006 Altera Corporation, San Jose, California, USA.      *
 * All rights reserved. All use of this software and documentation is     *
 * subject to the License Agreement located at the end of this file below.*
 *************************************************************************/
/******************************************************************************
 *
 * Description
 * ************* 
 * A simple program which, using an 8 bit variable, counts from 0 to ff, 
 * repeatedly.  Output of this variable is displayed on the LEDs, the Seven
 * Segment Display, and the LCD.  The four "buttons" (SW0-SW3) are used
 * to control output to these devices in the following manner:
 *   Button1 (SW0) => LED is "counting"
 *   Button2 (SW1) => Seven Segment is "counting"
 *   Button3 (SW2) => LCD is "counting"
 *   Button4 (SW3) => All of the peripherals are "counting".
 *
 * Upon completion of "counting", there is a short waiting period during 
 * which button/switch presses will be identified on STDOUT.
 * NOTE:  These buttons have not been de-bounced, so one button press may 
 *        cause multiple notifications to STDOUT.
 * 
 * Requirements
 * **************
 * This program requires the following devices to be configured:
 *   an LED PIO named 'led_pio',
 *   a Seven Segment Display PIO named 'seven_seg_pio',
 *   an LCD Display named 'lcd_display',
 *   a Button PIO named 'button_pio',
 *   a UART (JTAG or standard serial)
 *
 * Peripherals Exercised by SW
 * *****************************
 * LEDs
 * Seven Segment Display
 * LCD
 * Buttons (SW0-SW3)
 * UART (JTAG or serial)

 * Software Files
 * ****************
 * count_binary.c ==>  This file.
 *                     main() is contained here, as is the lion's share of the
 *                     functionality.
 * count_binary.h ==>  Contains some very simple VT100 ESC sequence defines
 *                     for formatting text to the LCD Display.
 * 
 *
 * Useful Functions
 * *****************
 * count_binary.c (this file) has the following useful functions.
 *   static void sevenseg_set_hex( int hex )
 *     - Defines a hexadecimal display map for the seven segment display.
 *   static void handle_button_interrupts( void* context, alt_u32 id)
 *   static void init_button_pio()
 *     - These are useful functions because they demonstrate how to write
 *       and register an interrupt handler with the system library.
 *
 * count_binary.h 
 *   The file defines some useful VT100 escape sequences for use on the LCD
 *   Display.
 */

/* Button pio functions */

/*
  Some simple functions to:
  1.  Define an interrupt handler function.
  2.  Register this handler in the system.
*/

/*******************************************************************
 * static void handle_button_interrupts( void* context, alt_u32 id)*
 *                                                                 *  
 * Handle interrupts from the buttons.                             *
 * This interrupt event is triggered by a button/switch press.     *
 * This handler sets *context to the value read from the button    *
 * edge capture register.  The button edge capture register        *
 * is then cleared and normal program execution resumes.           *
 * The value stored in *context is used to control program flow    *
 * in the rest of this program's routines.                         *
 ******************************************************************/


#include "system.h"
#include "alt_types.h"
#include "altera_avalon_pio_regs.h"
#include "sys/alt_irq.h"
#include <stdio.h>
#include <unistd.h>
#include "altera_avalon_timer.h"
#include "altera_avalon_uart.h"
#include "altera_avalon_timer_regs.h"
#include "io.h"
//全局變量
//static np_timer* timer=na_timer1;//定時器指針
const long nTimerPeriod=50000000;//定時周期1s
static int nTimerCount=0;//秒時間計數值,每次定時中斷變化
static int nTimerDir=1;//計時方向,0為暫停,1為正向,-1為反向
//LED分鐘數顯示
void show_led(int secCount)
{
//np_pio *pio=na_led_pio;//得到LED指針
//如果secCount計數值超出范圍,最多顯示8min
if (secCount>=60*9)
    secCount=60*8;
//用LED所亮個數來表示計時分鐘數
IOWR_ALTERA_AVALON_PIO_DATA(LEDPIO_BASE,(1<<(secCount/60))-1);//pio->np_piodata=(1<<(secCount/60))-1;
}


//數碼管BCD碼顯示
void show_seg_bcd(int code)
{
//np_pio* seg_pio=na_seven_seg_pio;//得到數碼管指針
//將顯示數據轉為BCD碼顯示
if (code>=0 && code<10000)
{
IOWR_ALTERA_AVALON_PIO_DATA(SEVENSEGPIO_BASE,(((code/1000)%10)<<12)+(((code/100)%10)<<8)+(((code/10)%10)<<4)+(code%10));//seg_pio->np_piodata=
     
}
}


//數碼管秒鐘數顯示
void show_decimal(int secCount)
{
//如果secCount計數已滿9min,顯示60s
if (secCount==60*9)
   show_seg_bcd(60);
else
{secCount %=60;//取計時數值的秒鐘數
 show_seg_bcd(secCount);
}
}
//啟動定時器
void start_timer(void)
{
//定時器控制寄存器stop位清零,start位寫1
IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER1_BASE,~ ALTERA_AVALON_TIMER_CONTROL_STOP_MSK);
IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER1_BASE,ALTERA_AVALON_TIMER_CONTROL_START_MSK);
}
//暫停定時器
void pause_timer(void)
{
//定時器控制寄存器start位清零,stop位寫1
IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER1_BASE,~ALTERA_AVALON_TIMER_CONTROL_START_MSK);
IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER1_BASE,ALTERA_AVALON_TIMER_CONTROL_STOP_MSK);
}
//定時器中斷服務子程序
void my_timer_isr(int context)
{
//np_timer *timerT=(np_timer *)context;//得到定時器指針
//根據計時方向(正向計時或倒計時),計時數值加1或減1
if (nTimerDir==-1&&nTimerCount>0)
   nTimerCount--;
 else if (nTimerDir>0&&nTimerCount<60*9)
   nTimerCount++;
//判斷計時是否完成
if ((nTimerDir>0&&nTimerCount==60*9)||(nTimerDir<0 && nTimerCount==0))
{nTimerDir=0;//暫停計時
//計時完成,停止計時
pause_timer();
}
//在串口終端上顯示計時時間
printf("%d'%d\"\t",nTimerCount/60,nTimerCount%60);
if (nTimerCount%10==0)
   printf("\n");
//LED分鐘數顯示
show_led(nTimerCount);
//數碼管秒鐘數顯示
show_decimal(nTimerCount);
//清除定時器中斷狀態
IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER1_BASE,0x0);
}


//定時器初始化
void init_timer(void)
{
//設置定時周期1s
IOWR_ALTERA_AVALON_TIMER_PERIODL(TIMER1_BASE,(short)(nTimerPeriod&0x0000ffff));
IOWR_ALTERA_AVALON_TIMER_PERIODH(TIMER1_BASE,(short)((nTimerPeriod>>16)&0x0000ffff));
//安裝定時器中斷服務子程序
alt_irq_register(TIMER1_IRQ,0, my_timer_isr); //nr_installuserisr(na_timer1_irq,my_timer_isr,(long)timer);
//設置定時器循環工作,定時器允許中斷
IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER1_BASE,ALTERA_AVALON_TIMER_CONTROL_CONT_MSK+ALTERA_AVALON_TIMER_CONTROL_ITO_MSK);

}


//main主程序
int main(void)
{
//按鍵變量
int buttons,buttonsLast=0x000F;
IOWR_ALTERA_AVALON_PIO_DATA(BUTTONPIO_BASE,0X0);
//按鍵指針
//np_pio *pio=buttonpio;
//設置按鍵端口全為輸入端口
//pio->np_piodirection=0;
//初始化定時器設置
init_timer();
//開啟定時器
start_timer();
//循環檢測串口輸入是否位Esc鍵的鍵值
while (1)
{
 //讀取按鍵數據端口輸入碼
buttons=IORD_ALTERA_AVALON_PIO_DATA(BUTTONPIO_BASE);//buttons=pio->np_piodata;
  //判斷是否有按鍵按下
if (buttons!=buttonsLast&&buttonsLast==0x000F)
{
switch(buttons&0x000F)
{
case 0x000E://SW0,定時器清零或置數
     pause_timer();//暫停
     //按一次清零,再按則置數
     if (nTimerCount>0)
         nTimerCount=0;
     else
         nTimerCount=60*9;
     //刷新LED和數碼管顯示內容
     show_led(nTimerCount);
     show_decimal(nTimerCount);
     break;
case 0x000D://SW1,置數
    //每按一次SW1置數時間加60s,超出則清零
     if (nTimerCount==60*9)
        nTimerCount=0;
     else if(nTimerCount>60*8)
        nTimerCount=60*9;
     //刷新LED和數碼管顯示內容
     show_led(nTimerCount);
     show_decimal(nTimerCount);
     break;
case 0x000B://SW2,向上計時或暫停
     if(nTimerDir!=0)
     {
      pause_timer();//暫停
      nTimerDir=0;
     }
     else
     {
     //向上計時開始
     start_timer();
     nTimerDir=1;
     }
     break;
case 0x0007://SW3,倒計時或暫停
     if (nTimerDir!=0)
     {
        pause_timer();//暫停
        nTimerDir=0;
     }
     else
      {
       //倒計時開始
       start_timer();
       nTimerDir=-1;
      }
     break;
case 0x000F://沒有按鍵按下
     buttons=buttonsLast=0x000F;
     break;
default:
     break;
   }
}
//保存當前按鍵鍵值到buttonLast變量
buttonsLast=buttons;
}
//卸載定時器中斷服務子程序,關閉定時器中斷
alt_irq_register(TIMER1_IRQ,0,0);
IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER1_BASE,~ALTERA_AVALON_TIMER_CONTROL_ITO_MSK);
//顯示程序退出信息,\004即Ctrl-D,表示程序已結束
printf("\nExit mytimer.\n\004");
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美性生交片4| 亚洲成人免费观看| 视频一区免费在线观看| 成人中文字幕电影| 欧美精三区欧美精三区 | 丁香激情综合五月| 欧美日韩大陆在线| 亚洲黄色小视频| 国产成人综合在线播放| 日韩一区二区在线播放| 亚洲靠逼com| 波多野结衣中文一区| 日韩欧美的一区| 亚洲一卡二卡三卡四卡| 99精品国产一区二区三区不卡| 久久久www成人免费无遮挡大片| 日韩精品国产欧美| 欧美男女性生活在线直播观看| 亚洲丝袜另类动漫二区| 成人精品鲁一区一区二区| 久久一日本道色综合| 免播放器亚洲一区| 69堂亚洲精品首页| 天堂影院一区二区| 7777精品伊人久久久大香线蕉超级流畅 | 色婷婷久久久综合中文字幕| 国产精品女同一区二区三区| 国产精品羞羞答答xxdd| 久久亚洲精华国产精华液 | 亚洲国产成人av网| 色八戒一区二区三区| 亚洲日本韩国一区| 色呦呦一区二区三区| 亚洲图片你懂的| 99久久婷婷国产综合精品| 中文字幕不卡在线播放| 高清不卡一区二区在线| 国产欧美日韩一区二区三区在线观看| 国产一区二区免费看| 国产日产欧美一区| 波多野结衣中文字幕一区二区三区| 亚洲国产精品成人综合 | 91精品国模一区二区三区| 日韩成人午夜精品| 欧美电影免费提供在线观看| 韩国av一区二区三区四区| 国产亚洲欧美日韩日本| 成人av电影观看| 亚洲国产精品影院| 日韩女优毛片在线| 国产成人精品影院| 一区二区视频在线| 欧美电影在哪看比较好| 国产制服丝袜一区| 亚洲欧美激情插| 日韩一级二级三级精品视频| 国产成人精品亚洲777人妖| 亚洲乱码精品一二三四区日韩在线| 欧美日韩一区成人| 国产精品中文字幕日韩精品 | 久久综合九色综合欧美98| av网站免费线看精品| 午夜久久电影网| 国产性色一区二区| 色婷婷一区二区三区四区| 美女视频网站久久| 中文字幕五月欧美| 日韩欧美不卡在线观看视频| 成人av高清在线| 美女免费视频一区| 日韩美女久久久| 亚洲精品一区二区三区在线观看 | 亚洲一二三四区不卡| 精品不卡在线视频| 欧美体内she精视频| 国内精品国产三级国产a久久| 亚洲码国产岛国毛片在线| 欧美mv日韩mv| 欧美日韩成人一区| 91丝袜高跟美女视频| 久草精品在线观看| 亚洲综合丝袜美腿| 欧美国产视频在线| 欧美电视剧在线观看完整版| 在线看国产日韩| 国产精品一区在线| 青青国产91久久久久久 | 欧美日韩成人一区| 99久久综合色| 国产精品夜夜爽| 久久激情五月激情| 视频一区二区国产| 一区二区三区四区亚洲| 国产精品久久久久精k8| 久久免费的精品国产v∧| 这里只有精品电影| 精品污污网站免费看| 91免费在线播放| 成人国产精品免费| 国产精选一区二区三区| 另类小说欧美激情| 日本中文在线一区| 亚洲第一二三四区| 亚洲国产美国国产综合一区二区| 亚洲人吸女人奶水| 亚洲色图欧洲色图| 中文字幕色av一区二区三区| 国产精品人成在线观看免费| 久久久久久久久久久久久女国产乱 | 在线播放视频一区| 4438x亚洲最大成人网| 欧美日韩二区三区| 欧美电影在哪看比较好| 9191精品国产综合久久久久久 | 久久看人人爽人人| 精品国精品国产| 精品国产髙清在线看国产毛片| 日韩欧美一区二区视频| 日韩三级伦理片妻子的秘密按摩| 欧美精品一级二级三级| 欧美狂野另类xxxxoooo| 91精品国产综合久久福利软件| 欧美一级免费大片| 欧美一区二区三区视频免费| 91精品国产综合久久精品图片| 日韩欧美一二三四区| 久久嫩草精品久久久精品一| 国产精品网站在线播放| 国产精品污网站| 亚洲一区二区免费视频| 日本系列欧美系列| 日韩av一区二区三区| 美腿丝袜在线亚洲一区| 国产精品系列在线观看| 北条麻妃一区二区三区| 在线观看av一区二区| 91精品欧美福利在线观看| 精品国产免费一区二区三区香蕉| 国产欧美日韩在线看| 亚洲黄色小说网站| 免播放器亚洲一区| 高清成人免费视频| 欧美日韩国产在线播放网站| 欧美精品一区二区三区四区| 国产精品系列在线| 亚洲福利视频一区二区| 国产综合久久久久久鬼色| 99久久国产综合精品女不卡| 欧美巨大另类极品videosbest | 亚洲精品国产品国语在线app| 日一区二区三区| 成人精品国产一区二区4080| 欧美酷刑日本凌虐凌虐| 国产欧美日韩视频在线观看| 亚洲电影一区二区三区| 国产精品亚洲一区二区三区妖精 | 成人av在线一区二区三区| 欧洲一区二区三区在线| 久久一夜天堂av一区二区三区| 一区二区三区中文免费| 国产一区福利在线| 欧美疯狂性受xxxxx喷水图片| 国产欧美一区二区精品性 | 亚洲一区二区精品久久av| 黑人巨大精品欧美一区| 在线亚洲人成电影网站色www| 精品国产乱码久久| 午夜精品视频在线观看| 不卡欧美aaaaa| 久久夜色精品一区| 视频一区二区三区在线| 波多野结衣91| 欧美韩日一区二区三区| 久久99久久久久| 欧美日韩国产一区| 一区二区三区蜜桃| 成人一区二区三区中文字幕| 欧美成人性战久久| 日韩国产欧美三级| 欧美吞精做爰啪啪高潮| 亚洲精品v日韩精品| 成人h动漫精品一区二区| 国产午夜一区二区三区| 精品制服美女丁香| 91麻豆精品91久久久久久清纯| 夜夜精品视频一区二区| 色94色欧美sute亚洲线路二| 中文字幕一区二区三区四区不卡| 国产成人综合网| 久久久久99精品国产片| 国内外成人在线视频| 精品国产三级a在线观看| 奇米精品一区二区三区四区| 欧美美女喷水视频| 亚洲国产精品久久久久婷婷884 | 91蜜桃婷婷狠狠久久综合9色| 亚洲国产精品黑人久久久| 国产成人高清在线| 国产精品私人自拍| 波多野结衣亚洲一区|