九齐单片机 NY8B062D 之TIM0的使用

1:基础知识。 (官方都提供了 整理一下是为了方便以后开发的时候查看)
在这里插入图片描述
在这里插入图片描述
2:寄存器的了解
2.1 TOMD
在这里插入图片描述

  2.2 对于 TOMD寄存器的配置
//;------------------------------------------------------------	
//; P_TMR0_Ctrl (xxH)		--------- T0MD Register
//;------------------------------------------------------------
//;		C_TMR0_Clk		C_TMR0_LowClk	|	Timer 0 Clock Source
//;------------------------------------------------------------
//;		0				x				|	From Instruction Clock
//;		1				0				|	From External Pin
//;		1				1				|	From Low Oscillator Frency (I_LRC or E_LXT)
//;------------------------------------------------------------
//;Bit[7,5:4] : Timer0 Clock Source Selection
#define		C_TMR0_LowClk				0x80			//; Same as LCKTM0	
#define		C_TMR0_Clk					0x20			//; Same as T0CS
#define		C_TMR0_ExtClk_Edge			0x10			//; Timer0 External Clock Edge Select --- 1:Falling Edge, 0:Rising Edge
//;Bit[6] : Reserved
//;Bit[3] : Watchdog Interrupt Source Selection / Timer0 Prescaler0 Selection
#define		C_PS0_WDT					0x08			//; Prescaler0 is assigned to WDT
#define		C_PS0_TMR0					0x00			//; Prescaler0 is assigned to TMR0
//;Bit[2:0] : Prescaler0 Dividing Rate Selection
#define		C_PS0_Div					0x07			//; Prescaler0 Dividing Rate Selection
#define		C_PS0_Div2					0x00
#define		C_PS0_Div4					0x01
#define		C_PS0_Div8					0x02
#define		C_PS0_Div16					0x03
#define		C_PS0_Div32					0x04
#define		C_PS0_Div64					0x05
#define		C_PS0_Div128				0x06
#define		C_PS0_Div256				0x07
//

测试代码

=========================================================================*/
#include <ny8.h>
#include "ny8_constant.h"
#define UPDATE_REG(x)	__asm__("MOVR _" #x ",F")

void main(void)
{
// Initialize System
	DISI();											// Disable global interrupt
	PCON = C_WDT_En | C_LVR_En;						// Enable WDT, Enable LVR

// Initialize GPIO
	IOSTB = 0xF8;									// PB0.PB1.PB2: output mode, others: input mode
	PORTB = 0x07;									// PB0、PB1 & PB2 are output high
// Initialize Timer0
	PCON1 = C_TMR0_En;								// Enable Timer0
	TMR0 = 0x00;									// TMR0[7:0] = 0x00
	T0MD = C_PS0_TMR0 | C_PS0_Div8;					// Prescaler0 is assigned to Timer0, Prescaler0 dividing rate = 1:8, Timer0 clock source is instruction clock

// Initialize Interrupt
	INTE =  C_INT_TMR0;		// Enable Timer0、Timer1、WDT overflow interrupt
	ENI();											// Enable global interrupt
	while(1);
}

// Interrupt Service Routine
void isr(void) __interrupt(0)
{
	if(INTFbits.T0IF)
	{
		PORTBbits.PB0 ^=1;							// PB0 Toggle
		INTF= (unsigned char)~(C_INT_TMR0);			// Clear T0IF
	}
}
  • 7
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七 六 伍

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值