找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 8085|回復: 0
打印 上一主題 下一主題
收起左側(cè)

NEC 78K0/KE2 間隔定時器 使用例程 (16位定時器/計數(shù)器00)

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:11255 發(fā)表于 2009-4-15 14:34 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式

NEC 78K0/KE2 間隔定時器 使用例程 (16位定時器/計數(shù)器00)
程序功能:
采用TM00產(chǎn)生1s中斷。
程序運行現(xiàn)象:
板上共8個發(fā)光二極管(LED0 ~ LED7),每次中斷(1s),LED循環(huán)依次亮滅。
初始化步驟:
1.關(guān)定時器:
TMC00 = 0x0;
2.設(shè)置定時器的需要時鐘,預分頻器設(shè)置:
SetBit(PRM00, 0x02);
3.設(shè)置比較值:
CR000 = 0x7A11.
4.清中斷標志,開中斷。
TMIF000 = 0;
TMMK000 = 0;
5.開定時器,開始計數(shù)。
SetBit(TMC00, 0x0C);
例程如下:
*使用此程序前請先設(shè)置選項字節(jié)及仿真代碼(minicube2硬件仿真)。
*使用PM編譯環(huán)境的請先去掉程序中中文注釋部分。

/*********************** (C) COPYRIGHT 2008 GETSOON*************************
* File Name   : main.c
* Author    : Tsinming
* Date First Issued  : 08/08/2008
* Description   : Main program body
**************************************************************************
* History:
* 08/08/2008: V0.1
**************************************************************************/
#include "ke2demo.h"

/* Variable defintion----------------------------------------------------*/
sreg u8 LedLData;

/* Functions defintion--------------------------------------------------*/
void init_cpu(void);
void init_para(void);
void ledflash(void);

/*----------------------------------------------------------------------------*/
void main(void)
{
 IMS = 0xCC;
 IXS = 0x00;
 DI();
 init_cpu();
 EI();
 init_para();
 
 while(1)
 {
  ledflash();
 }
}

/*************************************************************************
* Function Name : ledflash
* Description  : LED driver function.
* Input   : None
* Output   : None
* Return   : None
*************************************************************************/
void ledflash(void)
{
 P2.3 = LedLData.7;
 P2.2 = LedLData.6;
 P2.5 = LedLData.5;
 P2.4 = LedLData.4;
 P4.3 = LedLData.3;
 P4.2 = LedLData.2;
 P4.1 = LedLData.1;
 P4.0 = LedLData.0;
}
/*************************************************************************
* Function Name : init_cpu
* Description  : initialization .
* Input   : None
* Output   : None
* Return   : None
**************************************************************************/
void init_cpu(void)
{
 ClrBit(PCC, 0xFF);   // CPU Clock = Fxp
 
 CR000 = 0x7A11;   //設(shè)置比較值
 SetBit(PRM00, 0x02);  //設(shè)置定時器的需要時鐘,預分頻器設(shè)置Fprs/256
 TMIF000 = 0;    //清中斷標志
 TMMK000 = 0;    //開中斷
 SetBit(TMC00, 0x0C);  //開定時器,開始計數(shù)
 
 //Port Initialization, PMX(X=1~7,12,14) after reset: 0xFF
 ClrBit(PM2, 0x3C);   // P22~P25 is output for LED
 ClrBit(P2, 0x3C);
 ClrBit(PM4, 0x0F);   // P40~P43 is output for LED
 ClrBit(P4, 0x0F);
 ADPC=0x08;
}

/**************************************************************************
* Function Name : init_para
* Description  : initialization the Variable.
* Input   : None
* Output   : None
* Return   : None
**************************************************************************/
void init_para(void)
{
 LedLData = 0xFE;
}

/*********************** (C) COPYRIGHT 2008 GETSOON*************************/
上海格州電子提供NEC全系列8位,16位,32位,高性價比,ALL FLASH單片機,同時提供解決方案.
公司網(wǎng)址:                  http://www.getsoon.com.cn
聯(lián)系電話:                  021-66303207-6041
專業(yè)的NEC單片機技術(shù)社區(qū):   http://www.getsoon.com.cn/bbs/

/************************** (C) COPYRIGHT 2008 GETSOON**************************
* File Name   : int.c
* Author    : Tsinming
* Date First Issued  : 08/08/2008
* Description   : interrupt program body
*******************************************************************************
* History:
* 08/08/2008: V0.1
******************************************************************************/
#pragma interrupt  INTTM000  timer16int
#include "ke2demo.h"

/* Variable defintion---------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/******************************************************************************
* Function Name : timer16int
* Description  : interrupt of 16-bit Timer.
* Input   : None
* Output   : None
* Return   : None
******************************************************************************/
void timer16int(void)
{
 LedLData = (LedLData >> 7) | (LedLData << 1);
}

/************************* (C) COPYRIGHT 2008 GETSOON**************************/

/************************** (C) COPYRIGHT 2008 GETSOON**************************
* File Name   : ke2demo.h
* Author    : Tsinming
* Date First Issued  : 08/08/2008
* Description   : Header file for all files
*******************************************************************************
* History:
* 08/08/2008: V0.1
******************************************************************************/
#ifndef _KE2DEMO_H
#define _KE2DEMO_H

#pragma sfr
#pragma di
#pragma ei
#pragma NOP
#pragma HALT
#pragma STOP
#pragma asm

/* Exported types ------------------------------------------------------------*/
typedef unsigned long  u32;
typedef unsigned int  u16;
typedef unsigned char  u8;

/* Exported macro ------------------------------------------------------------*/
/* clear IO register bit and set IO register bit */
#define ClrBit(Para, ClrBitMap) Para &= ~ClrBitMap
#define SetBit(Para, SetBitMap) Para |= SetBitMap
 
/* Exported Variable defintion------------------------------------------------*/
extern sreg u8 LedLData;
 
/* Exported functions ------------------------------------------------------- */
#endif
/************************* (C) COPYRIGHT 2008 GETSOON**************************/


上海格州電子提供NEC全系列8位,16位,32位,高性價比,ALL FLASH單片機,同時提供解決方案.
公司網(wǎng)址:                  http://www.getsoon.com.cn
聯(lián)系電話:                  021-66303207-6041
專業(yè)的NEC單片機技術(shù)社區(qū):   http://www.getsoon.com.cn/bbs/

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表