#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include <stdio.h>
void setbusclock(void)
{
CLKSEL="0X00"; // disengage PLL to system
PLLCTL_PLLON=1; // turn on PLL
SYNR="0x00" | 0x01;
_asm(nop); // BUS CLOCK="16M"
_asm(nop);
while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;
}
//-----------------------------------------------------
void SCI_Init(void)
{
SCI0CR2=0x2c; //enable Receive Full Interrupt,RX enable,Tx enable
SCI0BDH=0x00; //busclk 8MHz,19200bps,SCI0BDL=0x1a
SCI0BDL=0x68; //SCI0BDL=busclk/(16*SCI0BDL)
//busclk 16MHz, 9600bps,SCI0BDL=0x68
}
void uart_putchar(unsigned char ch)
{
if (ch == '\n')
{
while(!(SCI0SR1&0x80)) ;
SCI0DRL= 0x0d; //output'CR'
return;
}
while(!(SCI0SR1&0x80)) ; //keep waiting when not empty
SCI0DRL=ch;
}
void putstr(char ch[])
{
unsigned char ptr="0";
while(ch[ptr]){
uart_putchar((unsigned char)ch[ptr++]);
}
}
//-----------------------------------------------------
static void IOC_Init(void)
{
TSCR1=0x80;//时钟允许
TSCR2=0x04;//div by 16
TCNT =0x00;
// TSCR2_PR
// PACTL="0x73";// INTERRUPT, 门控时间累加器模型,上升沿检测,不分频
TIOS =0x7E;//每一位对应通道的: 0输入捕捉,1输出比较 通道7输入比较
TCTL3=0xc0;//c-输入捕捉7任何沿有效,
TCTL4=0x0B;//0表示ICx禁止, 1表示上升沿, 2表示下降沿, 3表示任何沿
TIE =0x00;//每一位对应相应通道中断允许,0表示禁止中断 ;通道7
}
//-----------------------------------------------------
/* void ECT_Init(void)
{
TSCR2_PR = 7; //prescale factor is 8, bus clock/128=16Mhz/8
TSCR2_TOI = 1; //timer overflow interrupt enable
TSCR1_TEN = 1; //timer enable
}
#pragma CODE_SEG NON_BANKED
#pragma TRAP_PROC
void Int_TimerOverFlow(void)
{
TFLG2_TOF = 1; //clear timer overflow flag
TCNT="0";
DDRA="0XFF";
PORTA_PA0=~PORTA_PA0;
}
#pragma CODE_SEG DEFAULT
*/
void Dly_ms(int ms)
{
int ii,jj;
if (ms<1) ms="1";
for(ii=0;ii<ms;ii++)
for(jj=0;jj<2670;jj++); //busclk:16MHz--1ms
}
void main(void)
{
char mystr[20]="";
unsigned char LedCnt="0";
unsigned int IOCcnt;
setbusclock();
SCI_Init();
IOC_Init();
DDRA="0XFF";
PUCR_PUPBE=1;
putstr("\n debug of input caputer by cch");
EnableInterrupts;
// DisableInterrupts;
for(;;)
{
Dly_ms(1000); //修改延时以修改数据发送频率
IOCcnt="PACNT";
if(IOCcnt>999) PACNT="0";
sprintf(mystr,"\n\nIOC pulses:%d",IOCcnt);
putstr(mystr);
sprintf(mystr,"\nTC7; pulses:%d",TC7L);
putstr(mystr);
sprintf(mystr,"\nTC1 pulses:%d",TC1L);
putstr(mystr);
PORTA_PA0=~PORTA_PA0;
}
}
/*#pragma CODE_SEG NON_BANKED
#pragma TRAP_PROC
void Int_TimerOverFlow(void)
{
TFLG2_TOF = 1; //clear timer overflow flag
PAFLG_PAOVF=1;
PAFLG_PAIF=1;
PACNT="0";
DDRA="0XFF";
PORTA_PA0=~PORTA_PA0;
}
#pragma CODE_SEG DEFAULT
*/
//
用户426650 2012-8-13 18:03