智能车制作
标题:
求教一个128小程序
[打印本页]
作者:
戥家三少
时间:
2014-2-25 18:47
标题:
求教一个128小程序
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include <MC9S12XS128.h>
void SetBusCLK_32M(void)
{
CLKSEL=0X00; //不是能锁相环时钟
PLLCTL_PLLON=1; //锁相环电路允许
SYNR =0x00|0x03; //fpllclock=2*osc*(1+SYNR)/(1+REFDV)=160MHz;
REFDV=0x80|0x01; //fbus=pllclock/2;
POSTDIV=0x00; //fpllclock=fvco/(2*POSTDIV)
_asm(nop);
_asm(nop);
while(!CRGFLG_LOCK); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;
}
void Init_SCI(){
SCI0BD = 208; //设置波特率为9600 208 BUS32M
SCI0CR1 = 0X00; //正常的8位数据传送,无奇偶校验
SCI0CR2 = 0X2C; //发送允许,中断发送允许
}
void Init_PJ() {
DDRJ = 0X00;//设为输入口
PIEJ = 0Xc0;//开中断
PPSJ = 0X00;//7口下降沿6口上升沿
}
void uart_putchar ( unsigned char c)
{
while(!(SCI0SR1&0x80)) ; //keep waiting when not empty
SCI0DRL=c;
}
void main(void) {
/* put your own code here */
SetBusCLK_32M();
Init_SCI();
Init_PJ();
uart_putchar(0x60);
EnableInterrupts;
while(1);
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 24 J_Inter(){
if(PIFJ_PIFJ7 == 1) {
uart_putchar(0XFF);
PIFJ_PIFJ7 = 1;
}
else if(PIFJ_PIFJ6 == 1){
uart_putchar(0x00);
PIFJ_PIFJ6 = 1;
}
}
#pragma CODE_SEG DEFAULT
我这个程序是想测试J口的中断捕捉功能,都是捕捉下降沿,但为什么有的时候能发开头的标志0X60,有时不能发,而且有时能捕捉,有时不能捕捉呢?
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2