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

[复制链接]
niuyaliang 发表于 2015-2-27 20:06 | 显示全部楼层 |阅读模式
  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.   
  53.   
  54.   
  55.   
  56. void main(void) {  
  57.   
  58.   DisableInterrupts;  
  59.   SOPT1 = 0;  
  60.   INIT_MCG();  
  61.   EnableInterrupts; /* enable interrupts */  
  62.   /* include your code here */  
  63.    
  64.   LED_D1_DIR = 1;  
  65.   LED_D1     = LED_OFF;  
  66.    
  67.    
  68.    
  69.    
  70. //以下为设置波特率,以及初始化SCI1控制寄存器   
  71.   SCI1BDH = 0X00;  
  72.   SCI1BDL = 0X68;//波特率设置为9600  
  73.   SCI1C1 = 0x00; //设置SCI1为正常模式,八位数据位,无奇偶校验  
  74.   SCI1C2 = 0x08; //允许发送数据,禁止中断功能   
  75.    
  76.    
  77.      
  78.    
  79.   while(1)   
  80.   {  
  81.         
  82.         
  83.       while((*pSendString) != '\0')   
  84.       {  
  85.         while(!SCI1S1_TDRE);//SCI1S1_TDRE 为1表示发送数据缓冲器为空   
  86.         SCI1D = *pSendString;  
  87.         pSendString++;  
  88.         LED_D1 = ~LED_D1;;//每发送一个字节,闪烁一次LED灯  
  89.         delay();  
  90.       }  
  91.    
  92.   }  
  93.   
  94.   
  95.   
  96.   for(;;) {  
  97.     __RESET_WATCHDOG(); /* feeds the dog */  
  98.   } /* loop forever */  
  99.   /* please make sure that you never leave main */  
  100. }  


您需要登录后才可以回帖 登录 | 注册

本版积分规则

212

主题

2427

帖子

7

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