中级会员
- 积分
- 381
- 威望
- 291
- 贡献
- 52
- 兑换币
- 0
- 注册时间
- 2010-11-28
- 在线时间
- 19 小时
|
内容就是通过单片机发送一个“hello”,通过串口调试工具显示在电脑上
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include<mc9s12xs128.h>
#define unsigned char uchar
void sysclock_init(void)
{
CLKSEL=0x00;
PLLCTL=0xel;
SYNR=2;
REFDV=1;
PLLCTL=0x60;
asm NOP;
asm NOP;
asm NOP;
while((CRGFLG&0x08)==0);
CLKSEL=0x80; //设置总线频率为24M
}
void usart_init()
{
SCI0CR2=0x04; //接受适鼓?
SCI0BDH=0x00; //设置波特率为9600
SCI0BDL=0x9c;
}
void uart_putchar(uchar ch)
{
while(!(SCI0SR1&0x08)) //如果不是噪声...
{
SCI0DRL=ch;
}
}
void main(void)
{
uchar i=0;
uchar str[] ={'h','e','l','l','o'} ;
sysclock_init();
DDRB=0xff;
EnableInterrupts;
usart_init();
for(;i<5;i++)
{
PORTB=0x00;
uart_putchar(str[i]);
}
for(;;) {
} /* loop forever */
/* please make sure that you never leave main */
} |
|