金牌会员
- 积分
- 2535
- 威望
- 888
- 贡献
- 1261
- 兑换币
- 10
- 注册时间
- 2011-8-31
- 在线时间
- 193 小时
|
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include<MC9S12XS128.h>
//该程序统计5秒内转了多少圈
word num;
uchar flag,ch;
void pll_init() //超频24MHz F_bus=12Mhz
{
REFDV=3;
SYNR=2;
while(CRGFLG_LOCK==0);
CLKSEL=0x80;
}
void PIT_init() {
PITCFLMT=0X81;
PITFLT=0X01;
PITCE=0X01;
PITMUX=0X0E;
PITINTE=0X01;
PITMTLD0=239; //100ms定时
PITLD0=0X1388;
}
void PA_init() {
PACTL=0X50;//开启脉冲累加功能,上升沿计数,输入时钟为PA预分频时钟脉冲累加溢出中断使能,输入中断使能
PACNT=0x0000;//清零
TCTL3=0X40;
TIE=0X00;
TIOS=0X00;
}
void sci_init() {
SCI0BDH=0X00;
SCI0BDL=0X9c; //波特率4800
SCI0CR1=0X00; //8位模式无奇偶校验
SCI0CR2=0X2C; // 发送允许,接受中断
}
//接收函数
unsigned char SCI_READ() {
if(SCI0SR1_RDRF==1) {
SCI0SR1_RDRF=1;
return (SCI0DRL);
}
}
//发送函数
unsigned char SCI_WRITE(unsigned char n) {
while(!(SCI0SR1_TDRE));
SCI0DRH=0;
SCI0DRL=n;
}
void main(void) {
pll_init();
PIT_init();
PA_init();
sci_init();
EnableInterrupts;
for(;;) {
} /* loop forever */
/* please make sure that you never leave main */
}
#pragma CODE_SEG NON_BANKED
void interrupt 66 PIT0() {
flag++;
if(flag==50) {
flag=0;
num=PACNT;
ch=num/200;
SCI_WRITE(ch);
PACNT=0X0000;
}
PITTF=0X01;
} |
|