#include <hidef.h> /* common defines and macros */
#include <mc9s12c32.h> /* derivative information */
#include "main_asm.h" /* interface to the assembly module */
#pragma LINK_INFO DERIVATIVE "mc9s12c32"
unsigned char a,b,c;
unsigned char pwm0,pwm1,pwm2,pwm3,pwm4,pwm5,pwm6,pwm7;
volatile void RTI_Init(void)
{
CRGINT_RTIE=1;
CRGFLG_RTIF=0;
RTICTL=0b01000000;
}
volatile void ECT_Init(void)
{
TSCR2=0b10001011;
TSCR1_TEN=1;
}
volatile void PWM_Init(void);
void main(void)
{
/* put your own code here */
DDRA=0b00111111;
DDRB=0b00111111;
DDRT=0b00011111;
/* RTI_Init();*/
ECT_Init();
ATD_Init();
pwm0=0;
pwm1=2;
pwm2=4;
pwm3=8;
pwm4=10;
PWM_Init();
PORTA=0;
PORTB=0;
EnableInterrupts;
for(;;)
{
if(b<127)
{
PORTA_BIT0=0;
PORTB_BIT4=1;
}else
{
PORTA_BIT0=1;
PORTB_BIT4=0;
}
} /* wait forever */
}
/*volatile void interrupt 7 RTI_Int(void)
{
CRGFLG_RTIF=1;
b++;
}*/
volatile void interrupt 16 ECT_Int(void)
{
TFLG2_TOF=1;
b++;
}
volatile void PWM_Init(void)
{
PWME=0b00000000;
PWMPRCLK=0b00110011;
PWMSCLA=0b00001111;
PWMSCLB=0b00001111;
PWMCLK=0b00000001;
PWMPOL=0b00000111;
PWMCAE=0b00000000;
PWMPER0=250WMDTY0=0;
PWMPER1=250WMDTY0=0;
PWMPER2=250WMDTY0=0;
PWMDTY0=62;
PWMDTY1=125;
PWMDTY2=187;
PWME=0b00000111;
}
代码如上,想试验ECT的时间中断和PWM输出,都无法实现。RTI倒实现的比较方便(暂时先屏蔽了),麻烦大侠帮我看看,奇怪死了。
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编辑过]
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |