智能车制作

标题: 请大家帮我看一下这个简单的代码。。感激不尽。。串口通讯的,纠结中。。。 [打印本页]

作者: 风竹夜    时间: 2011-1-15 19:18
标题: 请大家帮我看一下这个简单的代码。。感激不尽。。串口通讯的,纠结中。。。
内容就是通过单片机发送一个“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 */
  }
作者: 风竹夜    时间: 2011-1-15 19:21
自己顶
作者: 风竹夜    时间: 2011-1-16 16:00
自己已解决。。。。




欢迎光临 智能车制作 (http://111.231.132.190/) Powered by Discuz! X3.2