微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > Freescale 9S12 系列单片机应用笔记(SCI)1

Freescale 9S12 系列单片机应用笔记(SCI)1

时间:11-20 来源:互联网 点击:

  1. CI1
  2. *@paramisEnable0disable1enable
  3. */
  4. voidSCIEnableRecv(unsignedcharport,unsignedcharisEnable);
  5. /**
  6. *Enable/DisableSCITransmitter
  7. *@paramportportcanbeSCI0/SCI1
  8. *@paramisEnable0disable1enable
  9. */
  10. voidSCIEnableTrans(unsignedcharport,unsignedcharisEnable);
  11. /**
  12. *SettheIdleLineType
  13. *@paramportportcanbeSCI0/SCI1
  14. *@paramtype0Idlecharbitcountbeginsafterstartbit
  15. *1Idlecharbitcountbeginsafterstopbit
  16. */
  17. voidSCISetIdleLineType(unsignedcharport,unsignedchartype);
  18. /**
  19. *SettheWakeupCondition.
  20. *@paramportportcanbeSCI0/SCI1
  21. *@paramcondi0forIdlelinewakeup,1foraddressmarkwakeup
  22. */
  23. voidSCISetWakeupCondi(unsignedcharport,unsignedcharcondi);
  24. /**
  25. *Enable/DisableparityfunctionandsettheParitytype
  26. *@paramportportcanbeSCI0/SCI1
  27. *@paramisEnable0fordisableparityfunction,1forenable
  28. *@paramtype0forEvenParity,1forOddParity
  29. */
  30. voidSCISetParity(unsignedcharport,unsignedcharisEnable,unsignedchartype);
  31. /**
  32. *SettheDataFormatModeBit
  33. *@paramportportcanbeSCI0/SCI1
  34. *@parambitsmustbe8or9
  35. */
  36. voidSCISetDataBit(unsignedcharport,unsignedcharbits);
  37. /**
  38. *Settheworkmodeofoperation
  39. *@paramportportcanbeSCI0/SCI1
  40. *@parammodemodecanbeNORMAL_MODE/LOOP_MODE/SING_WIRE_MODE
  41. */
  42. voidSCISetWorkMode(unsignedcharport,unsignedcharmode);
  43. /**
  44. *Enable/DisabletheSCIinwaitmode
  45. *@paramportportcanbeSCI0/SCI1
  46. *@parammodemodecanbeRUN_MODE/WAIT_MODE
  47. */
  48. voidSCISetPowerMode(unsignedcharport,unsignedcharmode);
  49. /**
  50. *SettheTXDIR(OnlyforSingleWireMODE)
  51. *@paramportportcanbeSCI0/SCI1
  52. *@paramdir0TXDusedasinput,1TXDusedasoutput
  53. */
  54. voidSCISetTXDIR(unsignedcharport,unsignedchardir);
  55. /**
  56. *SendacharthrounghSCImodule.
  57. *@paramportportcanbeSCI0/SCI1
  58. *@paramsthedatatobesent
  59. */
  60. voidSCIPutChar(unsignedcharport,unsignedchars);
  61. /**
  62. *ReceiveachardatafromSCImodule,noreply.
  63. *@paramportportcanbeSCI0/SCI1
  64. *@returnthereceivedchar
  65. */
  66. unsignedcharSCIGetChar(unsignedcharport);
  67. /**
  68. *Sendashortintvalue(BigEndian)throunghSCImodule.
  69. *@paramportportcanbeSCI0/SCI1
  70. *@paramithedatatobesent
  71. */
  72. voidSCIPutShortBigEndian(unsignedcharport,shorti);
  73. /**
  74. *Sendashortintvalue(LittleEndian)throunghSCImodule.
  75. *@paramportportcanbeSCI0/SCI1
  76. *@paramithedatatobesent
  77. */
  78. voidSCIPutShortLittleEndian(unsignedcharport,shorti);
  79. /**
  80. *Sendalongintvalue(BigEndian)throunghSCImodule.
  81. *@paramportportcanbeSCI0/SCI1
  82. *@paramithedatatobesent
  83. */
  84. voidSCIPutLongBigEndian(unsignedcharport,longi);
  85. /**
  86. *Sendalongintvalue(LittleEndian)throunghSCImodule.
  87. *@paramportportcanbeSCI0/SCI1
  88. *@paramithedatatobesent
  89. */
  90. voidSCIPutLongLittleEndian(unsignedcharport,longi);
  91. /**
  92. *SendacharstringthrounghSCImodule.
  93. *@paramportportcanbeSCI0/SCI1
  94. *@param*strthestringtobesent
  95. */
  96. voidSCIPutStr(unsignedcharport,unsignedchar*str);
  97. /**
  98. *SenddatathrounghSCImodule.
  99. *@paramportportcanbeSCI0/SCI1
  100. *@param*ppointertothedatatobesent
  101. *@paramsizethesize(byte)ofthedata
  102. */
  103. voidSCIWrite(unsignedcharport,void*p,intsize);
  104. #endif

下面给个简单的例子

  1. #include/*commondefinesandmacros*/
  2. #include"derivative.h"/*derivative-specificdefinitions*/
  3. #include"sci.h"
  4. voidmain(void)
  5. {
  6. charC;
  7. EnableInterrupts;
  8. SCISetWorkMode(SCI0,NORMAL_MODE);
  9. SCISetPowerMode(SCI0,RUN_MODE);
  10. SCISetBaudRate(SCI0,9600,16384000L);//16MClock
  11. SCISetDataBit(SCI0,8);
  12. SCISetParity(SCI0,0,0);
  13. SCIEnableRecv(SCI0,1);
  14. SCIEnableTrans(SCI0,1);
  15. for(;;)
  16. {
  17. _FEED_COP();/*feedsthedog*/
  18. C=SCIGetChar(SCI0);
  19. SCIPutChar(SCI0,C);
  20. }/*loopforever*/
  21. /*pleasemakesurethatyouneverleavemain*/
  22. }

先写这么多,剩下的明天继续。下一篇笔记中将给出如何利用串口的收发中断和环形缓冲区来实现较为完善的串口驱动。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top