⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pwm.c

📁 2410一些基本试验的源码
💻 C
字号:
#include "2410addr.h"
#include "2410lib.h"
#include "timer.h"

int l=0;

void timer0pwm_int()
{
	ClearPending(BIT_TIMER0);
	Uart_Printf("The timer_int is beginning\n");
	
	rTCFG0=100;//prescaler=100
	rTCFG1=(1<<0);//1/4*PCLK,pclk=50MH
	//t=101*4/50000000=0.00000808s
	
	
	rTCNTB0=600;//T=24752*0.00000808s=0.2s
	rTCMPB0=rTCNTB0>>2;
	
	rTCON =(11<<0);
	//rTCON &= ~(1<<1);
	rTCON=(9<<0);
	EnableIrq(BIT_TIMER0);
/*	
	Uart_Printf("The timer_int is beginning\n");
	rGPBCON = rGPBCON & ~(3<<0)|(1<<1);//set GPB0 as tout0, pwm output
	
    rTCFG0 = rTCFG0 & ~0xff|15; //prescaler = 15
    rTCFG1 = rTCFG1 & ~0xf|2;//divider = 1/8
    
    rTCNTB0 = (PCLK>>7)/6;//rTCNTB0=PCLK/{(prescaler+1) * divider *freq}
    rTCMPB0 = rTCNTB0>>1; //占空比50%
    
    //disable deadzone, auto-reload, inv-off, update TCNTB0&TCMPB0, start timer 0
    rTCON = rTCON & ~0x1f|(0<<4)|(1<<3)|(0<<2)|(1<<1)|(1);
    rTCON &= ~(1<<1); //clear manual update bit
    
	EnableIrq(BIT_TIMER0);
	*/	
}

void __irq pwm_hander()
{
	l++;
	ClearPending(BIT_TIMER0);
	//rTCON = rTCON & ~0x1f|(0<<4)|(1<<3)|(0<<2)|(1<<1)|(1);
    rTCON &= ~(1<<1); //clear manual update bit
	Uart_Printf("The timer0hander is beginning\n");
	Uart_Printf("%d \n",l);
}

int Main()
{
	SetClockDivider(1, 1);
	SetSysFclk(DFT_FCLK_VAL);
	Port_Init();
		
	Uart_Select(0);
	Uart_Init(0, UART_BAUD);
	
	
	rGPFCON|=0x55ff;
	rGPFUP=0;
	rGPFDAT&=0x00ff;
	
	rGPBCON = rGPBCON & ~(3<<0)|(1<<1);//set GPB0 as tout0, pwm output
	
	pISR_TIMER0=(unsigned)pwm_hander;
	
	timer0pwm_int();
	
	while(1)
	{
	if(l==500)
		{
			rGPFDAT=~rGPFDAT;
			l=0;
			Uart_Printf("The main is beginning\n");
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -