[资料分享与下载] 飞思卡尔单片机DZ60---SCI(中断发送)

[复制链接]
niuyaliang 发表于 2015-2-27 20:08 | 显示全部楼层 |阅读模式
  1. [cpp] view plaincopy
  2. #include <hidef.h> /* for EnableInterrupts macro */  
  3. #include "derivative.h" /* include peripheral declarations */  
  4.   
  5.   
  6. #define LED_D1      PTDD_PTDD0  
  7. #define LED_D1_DIR  PTDDD_PTDDD0  
  8.   
  9. #define LED_ON      0  
  10. #define LED_OFF     1  
  11.   
  12. unsigned char SCANF_SEND_STRINGS[] = "HELLO MCU WORLD";  
  13. unsigned char *pSendString = SCANF_SEND_STRINGS;  
  14.   
  15. /*************************************************************/  
  16. /*                  初始化总线时钟PEE模式                    */  
  17. /*              外部晶振频率为4MHz,总线频率16MHz            */  
  18. /*************************************************************/  
  19. void INIT_MCG(void)   
  20. {  
  21.   MCGC2=0x36;         
  22.   while(!MCGSC_OSCINIT);      
  23.   MCGC1=0xb8;  
  24.   while(MCGSC_IREFST);  
  25.   while(MCGSC_CLKST!=0b10);  
  26.   MCGC2_LP = 1;  
  27.   MCGC1 = 0x90;  
  28.   MCGC3 = 0x48;      
  29.   MCGC2_LP = 0;  
  30.   while(!MCGSC_PLLST);  
  31.   while(!MCGSC_LOCK);  
  32.   MCGC1 = 0x10;  
  33.   while(MCGSC_CLKST!=0b11);  
  34. }   
  35.   
  36.   
  37.   
  38.   
  39.   
  40. void delay(void)   
  41. {  
  42.   unsigned int i;  
  43.   unsigned int j;  
  44.      
  45.      
  46.   for(i = 0; i < 100; i++)  
  47.      for(j = 0; j < 4000; j++);  
  48.    
  49. }  
  50.   
  51.   
  52. void main(void) {  
  53.   
  54.   DisableInterrupts;  
  55.   SOPT1 = 0;  
  56.   INIT_MCG();  
  57.   EnableInterrupts; /* enable interrupts */  
  58.   /* include your code here */  
  59.    
  60.   LED_D1_DIR = 1;  
  61.   LED_D1     = LED_OFF;  
  62.    
  63.    
  64.    
  65. //以下为设置波特率,以及初始化SCI1控制寄存器   
  66.   SCI1BDH = 0X00;  
  67.   SCI1BDL = 0X68;//波特率设置为9600  
  68.   SCI1C1 = 0x00; //设置SCI1为正常模式,八位数据位,无奇偶校验  
  69.   SCI1C2 = 0x88; //TIE = 1(bit7) 启动TDRE中断,发送中断使能  
  70.                  //手册指出,如果设置了发送中断使能TIE位,每当TDRE = 1时都请求硬件中断  
  71.                  //TE  = 1(bit3) 发送器打开  
  72.   while(1);  
  73.   
  74.   for(;;) {  
  75.     __RESET_WATCHDOG(); /* feeds the dog */  
  76.   } /* loop forever */  
  77.   /* please make sure that you never leave main */  
  78. }  
  79.   
  80.   
  81. /*************************************************************/  
  82. /*                SCI1中断向量函数                           */  
  83. /*                向量编号为18,中断来源TDRE,TC              */  
  84. /*************************************************************/  
  85. interrupt 18 void SCI1_SEND(void)  
  86. {  
  87.   while(*pSendString != '\0')   
  88.   {  
  89.     while(!SCI1S1_TDRE);  
  90.     SCI1D = *pSendString;  
  91.     pSendString++;  
  92.     LED_D1 = ~ LED_D1;  
  93. //    delay();  
  94.   }  
  95.       
  96. }                           


quray1985 发表于 2015-2-28 10:32 来自手机 | 显示全部楼层
谢谢分享
powerful1 发表于 2015-2-28 13:49 | 显示全部楼层
恩,谢谢楼主分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则

212

主题

2427

帖子

7

粉丝
快速回复 在线客服 返回列表 返回顶部

212

主题

2427

帖子

7

粉丝
快速回复 在线客服 返回列表 返回顶部