利用定时器2产生3MHz脉冲,程序如下,但是用示波器测试频率是600khz,不知什么问题,请高手指教!!
#include<c8051f410.h>
#define uchar unsigned char
#define uint unsigned int
sbit pwm=P0^6;
sbit en1=P0^0;
sbit en2=P0^1;
void sysclock_init()
{
OSCICN = 0x87;
}
void gpio_init()
{
P1MDIN = 0xB7;
P0MDOUT = 0xFF;
P1SKIP = 0x48;
XBR1 = 0x40;
}
//-----------------------------------------------------------------------------
// 定时器2产生3mkhz的方波
//-----------------------------------------------------------------------------
void C8051F410_Timer2_Init (void)
{
CKCON = 0x10;
TMR2RLL = 0xC3;
TMR2RLH = 0xFF;
TMR2L = 0xC3;
TMR2H = 0xFF;
}
//-----------------------------------------------------------------------------
// 定时器2中断程序,每次产生方波翻转
//-----------------------------------------------------------------------------
void C8051F410_Timer2_ISR(void) interrupt 5
{
pwm=~pwm; //翻转输出方波200khz
}
void main()
{
PCA0MD&=0xBF;//关看门狗
sysclock_init();
gpio_init();
C8051F410_Timer2_Init ();
EA=1;
TR2=1;// //开定时器2
ET2=1;
while(1);
} |