Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1148776
  • 博文数量: 139
  • 博客积分: 2510
  • 博客等级: 少校
  • 技术积分: 1712
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-13 23:10
个人简介

每天进步一点点。

文章分类

全部博文(139)

文章存档

2015年(3)

2014年(11)

2013年(25)

2011年(1)

2009年(3)

2008年(29)

2007年(45)

2006年(22)

分类: C/C++

2008-10-29 10:06:55

AW32DEMO板的例子:源代码如下:
1.main.c

#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */

#include "SCI.h"

byte sci_data = 0;

void MCU_init(void) /* Device initialization function declaration */
{
  SCI1_Init();
  /* ### Init_GPIO init code */
  /* PTFDD: PTFDD = 0xFF */
  PTFDD = (unsigned char)0xFF;
}

void main(void) {

  /* Uncomment this function call after using Device Initialization
     to use the generated code */

  MCU_init();

  EnableInterrupts; /* enable interrupts */

  /* include your code here */
  printf0("\nhello, MC9S08AW60!\r");
  printf0("\n pls choose number:\r");
  printf0("\n 1. MC9S08AW60 \r");
  printf0("\n 2. MC9S12XD256\r");
  printf0("\n 3. MPC5554 \r");
  

  for(;;)
  {
    __RESET_WATCHDOG(); /* feeds the dog */
    if(sci_data == '1')
    {
      sci_data = 0;
      PTFD = 0x01;
      printf0("\n This is the 8 bit MCU!\n\n\r");
      printf0("\n pls choose number:\r");
      printf0("\n 1. MC9S08AW60 \r");
      printf0("\n 2. MC9S12XD256\r");
      printf0("\n 3. MPC5554 \r");
    }
    if(sci_data == '2')
    {
      sci_data = 0;
      PTFD = 0x02;
      printf0("\n This is the 16 bit MCU!\n\n\r");
      printf0("\n pls choose number:\r");
      printf0("\n 1. MC9S08AW60 \r");
      printf0("\n 2. MC9S12XD256\r");
      printf0("\n 3. MPC5554 \r");
    }
    if(sci_data == '3')
    {
      sci_data = 0;
      PTFD = 0x04;
      printf0("\n This is the 32 bit MCU!\n\n\r");
      printf0("\n pls choose number:\r");
      printf0("\n 1. MC9S08AW60 \r");
      printf0("\n 2. MC9S12XD256\r");
      printf0("\n 3. MPC5554 \r");
    }
  } /* loop forever */
  /* please make sure that you never leave this function */


}


2.sci.c


#include <MC9S08AW60.h>

extern byte sci_data;

void SCI1_Init(void)
{
  /* ### Init_SCI init code */
  /* SCI1BD: SBR12=0,SBR11=0,SBR10=0,SBR9=0,SBR8=0,SBR7=0,SBR6=0,SBR5=0,SBR4=1,SBR3=1,SBR2=0,SBR1=1,SBR0=0 */
  SCI1BD = 0x1A;
  /* SCI1C1: LOOPS=0,SCISWAI=0,RSRC=0,M=0,WAKE=0,ILT=0,PE=0,PT=0 */
  SCI1C1 = 0x00;
  /* SCI1C2: TIE=0,TCIE=0,RIE=1,ILIE=0,TE=1,RE=1,RWU=0,SBK=0 */
  SCI1C2 = 0x2C;
  /* SCI1C3: R8=0,T8=0,TXDIR=0,TXINV=0,ORIE=0,NEIE=0,FEIE=0,PEIE=0 */
  SCI1C3 = 0x00;
  /* SCI1S2: BRK13=0,RAF=0 */
  SCI1S2 = 0x00;
}

void SCI1_ReceiveChar(byte *data)
{
  *data = SCI1D;
}

void SCI1_SendChar(byte data)
{
   while(!SCI1S1_TDRE);
   SCI1D = data;
}


void printf0(char *str)
{    
    while((*str != '\r'))
    {
        SCI1_SendChar(*str);
        if(*str++=='\n')
         SCI1_SendChar('\r');        
    }
    __RESET_WATCHDOG(); /* feeds the dog */
}

interrupt 17 void isrSCI1Receive(void)
{
  byte data;
  SCI1S1_RDRF;
  SCI1_ReceiveChar(&data);
  sci_data = data;
  
}

阅读(1616) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~