首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

[讨论]ECT无法实现,PWM也出不来,又要请教了。

请看手册23页,PORTP是专门的PWM通道 PORTT是Timer的通道。用PWM通道产生PWM波比较方便。

void PWM_Init(void)
{
  PWMCNT0 = 0;
  PWMDTY0 = 0x6B;             // Store initial value to the duty-compare register
  PWMPER0 = 0xFF;             // and to the period register
  // PWMPRCLK: ??=0,PCKB2=0,PCKB1=0,PCKB0=0,??=0,PCKA2=0,PCKA1=0,PCKA0=0
  PWMPRCLK = 0x00;            // Set prescaler register
  // PWMSCLA: BIT7=0,BIT6=1,BIT5=0,BIT4=0,BIT3=1,BIT2=0,BIT1=1,BIT0=1
  PWMSCLA = 0x4B;             // Set scale register
  PWMCLK_PCLK0 = 1;           // Select clock source
  PWME_PWME0 = 1;             // Run counter
}

 

#pragma CODE_SEG DEFAULT


void TIM_Init(void)
{
  TC0 = 0xC34F;          // Store given value to the compare register
  TC7 = 0xC34F;          // Store given value to the modulo register
  TSCR2_PR = 0X04;       // Store given value to the prescaler
  TFLG1 = 0x01;          // Reset interrupt request flag
  TIE_C0I = 1;           // Enable interrupt
  TIOS_IOS0 = 1;
  TSCR1_TEN = 1;         // Enable Timer
}

#pragma CODE_SEG __NEAR_SEG NON_BANKED

/* Interrupt section for this module. Placement will be in NON_BANKED area.*/
interrupt 8 void TI2_Interrupt(void)
{
  TFLG1 = 0x01;          // Reset interrupt request flag 
  //用户的中断程序

}

#pragma CODE_SEG DEFAULT

[此贴子已经被作者于2005-11-11 10:42:14编辑过]

返回列表