timer_pio_sample.c
来自「最新版IAR FOR ARM(EWARM)5.11中的代码例子」· C语言 代码 · 共 139 行
C
139 行
/*************************************************************************************************/
/* */
/* Copyright (C) 2003 Oki Electric Industry Co., LTD. */
/* */
/* System Name : uPLAT-946 Prototyping Board */
/* Module Name : TIMER and PIO sample */
/* File Name : timer_pio_sample.c */
/* Revision : 1.00 */
/* Date : 2003/09/09 */
/* */
/*************************************************************************************************/
#include "ml69q6203.h"
#include "common.h"
#include "irq.h"
#include <intrinsics.h>
/* constants */
#define TMRCYC (10) /* interval of timer interrupt (ms) */
#define CLKTMRI (7500000L) /* clktmri (Hz) */
#define VALUE_OF_TMRLR /* reload value of timer */\
((0x10000L * (16 * 1000) - ((TMRCYC * CLKTMRI))) / (16 * 1000))
/* functions */
int main(void); /* main routine */
void reg_irq_handler(void); /* registration of IRQ handler */
void set_timer(void); /* setup of timer */
void timer_handler(void); /* timer handler */
/* global variables */
volatile int counter;
volatile UHWORD led_count;
/* LED lighting pattern table */ /* DPGFE_DCBA */
const UHWORD led_table[19] = { 0x003F, /* 0 0011_1111 */
0x0006, /* 1 0000_0110 */
0x005B, /* 2 0101_1011 */
0x004F, /* 3 0100_1111 */
0x0066, /* 4 0110_0110 */
0x006D, /* 5 0110_1101 */
0x007D, /* 6 0111_1101 */
0x0007, /* 7 0000_0111 */
0x007F, /* 8 0111_1111 */
0x006F, /* 9 0110_1111 */
0x0077, /* A 0111_0111 */
0x007C, /* B 0111_1100 */
0x0039, /* C 0011_1001 */
0x005E, /* D 0101_1110 */
0x0079, /* E 0111_1001 */
0x0071, /* F 0111_0001 */
0x00FF, /* 8. 1111_1111 */
0x0000 };/* 0000_0000 */
/*************************************************************************************************/
/* Entry point */
/* Function : main */
/* Parameters */
/* Input : Nothing */
/* Output : 0 */
/*************************************************************************************************/
int main(void)
{
init_led(); /* initialize LED */
init_irq(); /* initialize IRQ */
reg_irq_handler(); /* registration of IRQ handler */
set_timer(); /* setup of timer */
led_on(LED_START_PATTERN); /* light LED start pattern */
/* initialize variable */
led_count = 0;
counter = 0;
__enable_interrupt(); /* enable IRQ */
put_wvalue(TMEN, 0x01); /* timer start */
while(1){
if(counter >= 50){ /* timer interrupt occur? */
counter = 0;
led_on(led_table[led_count]); /* light LED */
/* update led_count */
led_count++;
if(led_count >= 18) {
led_count = 0;
}
}
}
}
/*************************************************************************************************/
/* Registration of IRQ Handler */
/* Function : reg_irq_handler */
/* Parameters */
/* Input : Nothing */
/* Output : Nothing */
/*************************************************************************************************/
void reg_irq_handler(void)
{
/* register IRQ handlers into handler table */
IRQ_HANDLER_TABLE[INT_SYSTEM_TIMER] = timer_handler;
/* setup interrupt level */
set_wbit(ILC0, 0x00000007); /* system timer(nIRQ[0]) -> level7 */
return;
}
/*************************************************************************************************/
/* Setup of timer */
/* Function : set_timer */
/* Parameters */
/* Input : Nothing */
/* Output : Nothing */
/*************************************************************************************************/
void set_timer(void)
{
put_wvalue(TMEN, 0x00000000); /* disable timer (write '0' in TMEN[0])*/
put_wvalue(TMOVF, 0x00000001); /* clear overflow register (write '1' in TMOVF[0])*/
put_wvalue(TMRLR, VALUE_OF_TMRLR); /* set TMRLR */
return;
}
/*************************************************************************************************/
/* System Timer handler */
/* Function : timer_handler */
/* Parameters */
/* Input : Nothing */
/* Output : Nothing */
/*************************************************************************************************/
void timer_handler(void)
{
counter++;
put_wvalue(TMOVF, 0x00000001); /* clear TMOVF register (write '1' in TMOVF[0]) */
return;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?