智能车制作

标题: 串口通信代码(总线时钟40M,9600) [打印本页]

作者: 仁者    时间: 2010-2-6 12:15
标题: 串口通信代码(总线时钟40M,9600)
  1. #include <hidef.h> /* common defines and macros */
  2. #include "derivative.h" /* derivative-specific definitions */
  3. void SetBusCLK_40M(void)
  4. {
  5. CLKSEL=0X00; //disengage PLL to system
  6. PLLCTL_PLLON=1; //turn on PLL
  7. SYNR =0x04; // 0xc0 |
  8. REFDV=0x01; //0x80 |
  9. POSTDIV=0x00; //pllclock=2*osc*(1+SYNR)/(1+REFDV)=80MHz;
  10. _asm(nop); //BUS CLOCK=40M
  11. _asm(nop);
  12. while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
  13. CLKSEL_PLLSEL =1; //engage PLL to system;
  14. }

  15. void uart_init (void)
  16. {
  17. SCI0CR2 = 0x0c; //允许SCI0发送⑺?查询方式
  18. SCI0BDH = 0x01; //注意:一定要先给高八位赋值 &&&我就错在这里了
  19. SCI0BDL = 0x04; //再给低8位赋值

  20. //SCI0CR1 = 0x00; //设置允许SCI,正常码输出,8位数据,无校验
  21. }
  22. void SCISend1(unsigned char o)
  23. {
  24. //判断ReStatusR的第SendTestBit位是否为1,是1可以发送

  25. while (1)
  26. if ((SCI0SR1 & (1<<7)) != 0)
  27. {
  28. SCI0DRL =o;
  29. break;
  30. }
  31. }



  32. void main(void) {
  33. /* put your own code here */

  34. SetBusCLK_40M();
  35. uart_init();
  36. EnableInterrupts;
  37. SCISend1('Z');

  38. for(;;) {
  39. _FEED_COP(); /* feeds the dog */
  40. } /* loop forever */
  41. /* please make sure that you never leave main */
  42. }
复制代码

作者: qicai    时间: 2010-2-7 18:18
谢谢了  太感谢
作者: 仁者    时间: 2010-2-8 12:57
回复 2# qicai


    大家多交流,我也是借鉴别人的弄的,呵呵
作者: 710603117    时间: 2010-2-8 13:20
多多交流才有进步
作者: sunnylee    时间: 2010-4-21 13:11
谢了,哥们
作者: fenkella    时间: 2010-4-22 23:33
thank you!!
作者: huachou    时间: 2010-4-23 12:53
看一下
作者: botewin    时间: 2010-4-30 16:30
3q
作者: fengnan    时间: 2010-4-30 19:15
谢谢  好好学习一下
作者: young_angel_123    时间: 2010-6-13 13:45
谢了
作者: lantian    时间: 2010-10-12 17:19
3q
作者: JINLIANG    时间: 2010-12-1 18:17
太感谢你了
作者: mysky_1234    时间: 2011-1-11 19:19
很受用!!!
作者: LYL0707    时间: 2011-1-14 08:59
好标准的程序
作者: gao0708    时间: 2011-1-14 19:07
多谢
作者: xujiahua1231    时间: 2011-2-25 23:26
楼主好人啊
作者: 仁者    时间: 2011-2-26 10:17
回复 16# xujiahua1231


    客气
作者: DONT    时间: 2011-2-27 16:49
用串口调试工具 看不到结果啊
作者: tsacy    时间: 2011-3-16 01:17

作者: wanghuabin    时间: 2011-5-30 22:14
这个程序 没用啊,发上来干嘛啊
作者: jeefcd    时间: 2011-12-20 19:12
怎么只能发字母,数字怎么发呢?
作者: sunabeng    时间: 2011-12-25 19:15
看着都难受
作者: xiayayun    时间: 2012-1-8 15:13
还可以
作者: 宋洁文    时间: 2012-1-12 12:03
谢了
作者: gzhcontent    时间: 2012-1-15 17:11
谢了啊,呵呵
作者: 鱼小闲    时间: 2012-2-17 10:02
学习一下
作者: 157688    时间: 2012-2-25 18:12

作者: oooooo    时间: 2012-5-14 12:46
好好学学
作者: happy★熊    时间: 2012-5-20 20:58
学习
作者: 封号式寂寞    时间: 2012-5-22 18:17

作者: 87外泄    时间: 2012-5-26 15:57





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