📄 pio_sample.c
字号:
/*************************************************************************************/
/* */
/* Copyright (C) 2003 Oki Electric Industry Co., LTD. */
/* */
/* System Name : ML675001 series */
/* Module Name : Parallel Functions */
/* File Name : pio_sample.c */
/* Revision : 1.00 */
/* Date : 2003/03/09 */
/* Initial version */
/* */
/*************************************************************************************/
#include "ML675001.h"
#include "common.h"
#include "irq.h"
#include "cache.h"
/* constants */
#define MHz (1000000L)
#define TMRCYC (10) /* interval of timer interrupt (ms) */
#define CCLK (60*MHz) /* CCLK (Hz) */
#define CLKGEAR (1) /* clock gear */
#define CLKTMR (CCLK/CLKGEAR) /* frequency of CLKTMR terminal (Hz) */
#define VALUE_OF_TMRLR /* reload value of timer */\
((0x10000L*(16*1000)-(TMRCYC*CLKTMR))/(16*1000))
#if ((VALUE_OF_TMRLR) < 0 || 0x10000 <= (VALUE_OF_TMRLR))
#error "Invalid value : VALUE_OF_TMRLR"
#endif
/* functions */
int main(void); /* main routine */
static void reg_irq_handler(void); /* registration of IRQ handler */
static void set_timer(void); /* setup of timer */
static void timer_handler(void); /* timer handler */
void led_on(UHWORD); /* light LED */
/* global variables */
static volatile int counter;
static volatile unsigned int led_count;
/* LED lighting pattern table */
UHWORD LED_TABLE [18] = {LED_0,LED_1,LED_2,LED_3, /* "0","1","2","3" */
LED_4,LED_5,LED_6,LED_7, /* "4","5","6","7" */
LED_8,LED_9,LED_A,LED_b, /* "8","9","A","b" */
LED_C,LED_d,LED_E,LED_F, /* "C","d","E","F" */
LED_all,LED_off}; /* all on ,all off */
/****************************************************************************/
/* Entry point */
/* Function : main */
/* Parameters */
/* Input : Nothing */
/* Output : 0 */
/****************************************************************************/
int main(void)
{
init_cache(); /* Initialize CACHE memory */
cache_on(CACHE_BANK0); /* Bank0 : Cache enable */
/* initialize IRQ */
init_irq();
/* registration of IRQ handler */
reg_irq_handler();
/* setup of timer */
set_timer();
/* initialize LED */
init_led(); /* set output mode */
/* light LED start pattern */
led_on(LED_START_PATTERN);
/* initialize variable */
led_count = 0;
counter = 0;
/* enable IRQ */
irq_en();
/* timer start */
put_hvalue(TMEN, 0x01); /* enable timer (write '1' in TMEN[0]) */
/* 10ms * 50 = 500ms */
while(1){
if(counter >= 50){ /* timer interrupt occur? */
counter = 0;
/* light LED */
led_on(LED_TABLE[led_count]);
/* update led_count */
led_count++;
if(led_count >= 18)
led_count = 0;
}
}
return(0);
}
/****************************************************************************/
/* Registration of IRQ Handler */
/* Function : reg_irq_handler */
/* Parameters */
/* Input : Nothing */
/* Output : Nothing */
/* Note : Initialize of IRQ needs to be performed before this process. */
/****************************************************************************/
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, ILC0_ILR0 & ILC0_INT_LV1); /* system timer(nIRQ[0]) -> level1 */
return;
}
/****************************************************************************/
/* Setup of timer */
/* Function : set_timer */
/* Parameters */
/* Input : Nothing */
/* Output : Nothing */
/****************************************************************************/
void set_timer(void)
{
put_hvalue(TMEN, 0x0); /* disable timer (write '0' in TMEN[0])*/
put_hvalue(TMOVF, 0x01); /* clear overflow register (write '1' in TMOVF[0])*/
put_hvalue(TMRLR, VALUE_OF_TMRLR); /* set TMRLR */
return;
}
/*****************************************************************************/
/* System Timer handler */
/* Function : timer_handler */
/* Parameters */
/* Input : Nothing */
/* Output : Nothing */
/*****************************************************************************/
void timer_handler(void)
{
counter++;
put_hvalue(TMOVF, 0x01); /* clear TMOVF register (write '1' in TMOVF[0]) */
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -