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

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

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

  1. I0CR2_RE=(isEnable&0x01);
  2. }
  3. elseif(port==SCI1)
  4. {
  5. SCI1CR2_RE=(isEnable&0x01);
  6. }
  7. else
  8. {
  9. //Ifcoderunhere,somethingmustgowrong.Donothinghere!
  10. }
  11. }

使能SCI模块的发送功能

  1. /**
  2. *Enable/DisableSCITransmitter
  3. *@paramportportcanbeSCI0/SCI1
  4. *@paramisEnable0disable1enable
  5. */
  6. voidSCIEnableTrans(unsignedcharport,unsignedcharisEnable)
  7. {
  8. if(port==SCI0)
  9. {
  10. SCI0CR2_TE=(isEnable&0x01);
  11. }
  12. elseif(port==SCI1)
  13. {
  14. SCI1CR2_TE=(isEnable&0x01);
  15. }
  16. else
  17. {
  18. //Ifcoderunhere,somethingmustgowrong.Donothinghere!
  19. }
  20. }

发送数据

  1. /**
  2. *SendacharthrounghSCImodule.
  3. *@paramportportcanbeSCI0/SCI1
  4. *@paramsthedatatobesent
  5. */
  6. voidSCIPutChar(unsignedcharport,unsignedchars)
  7. {
  8. if(port==SCI0)
  9. {
  10. while(SCI0SR1_TDRE==0);//SCI0SR1_TC是发送完成
  11. SCI0DRL=s;
  12. }
  13. else
  14. {
  15. while(SCI1SR1_TDRE==0);//SCI1SR1_TC
  16. SCI1DRL=s;
  17. }
  18. }
  19. /**
  20. *SendacharstringthrounghSCImodule.
  21. *@paramportportcanbeSCI0/SCI1
  22. *@param*strthestringtobesent
  23. */
  24. voidSCIPutStr(unsignedcharport,unsignedchar*str)
  25. {
  26. while(0!=*str)
  27. {
  28. SCIPutChar(port,*str);
  29. str++;
  30. }
  31. }
  32. /**
  33. *SenddatathrounghSCImodule.
  34. *@paramportportcanbeSCI0/SCI1
  35. *@param*ppointertothedatatobesent
  36. *@paramsizethesize(byte)ofthedata
  37. */
  38. voidSCIWrite(unsignedcharport,void*p,intsize)
  39. {
  40. unsignedchar*str=(unsignedchar*)p;
  41. while(size>0)
  42. {
  43. SCIPutChar(port,*str);
  44. str++;
  45. size--;
  46. }
  47. }
  48. /**
  49. *Sendashortintvalue(BigEndian)throunghSCImodule.
  50. *@paramportportcanbeSCI0/SCI1
  51. *@paramithedatatobesent
  52. */
  53. voidSCIPutShortBigEndian(unsignedcharport,shorti)
  54. {
  55. char*p=(char*)&i;
  56. SCIPutChar(port,p[0]);
  57. SCIPutChar(port,p[1]);
  58. }
  59. /**
  60. *Sendashortintvalue(LittleEndian)throunghSCImodule.
  61. *@paramportportcanbeSCI0/SCI1
  62. *@paramithedatatobesent
  63. */
  64. voidSCIPutShortLittleEndian(unsignedcharport,shorti)
  65. {
  66. char*p=(char*)&i;
  67. SCIPutChar(port,p[1]);
  68. SCIPutChar(port,p[0]);
  69. }
  70. /**
  71. *Sendalongintvalue(BigEndian)throunghSCImodule.
  72. *@paramportportcanbeSCI0/SCI1
  73. *@paramithedatatobesent
  74. */
  75. voidSCIPutLongBigEndian(unsignedcharport,longi)
  76. {
  77. char*p=(char*)&i;
  78. SCIPutChar(port,p[0]);
  79. SCIPutChar(port,p[1]);
  80. SCIPutChar(port,p[2]);
  81. SCIPutChar(port,p[3]);
  82. }
  83. /**
  84. *Sendalongintvalue(LittleEndian)throunghSCImodule.
  85. *@paramportportcanbeSCI0/SCI1
  86. *@paramithedatatobesent
  87. */
  88. voidSCIPutLongLittleEndian(unsignedcharport,longi)
  89. {
  90. char*p=(char*)&i;
  91. SCIPutChar(port,p[3]);
  92. SCIPutChar(port,p[2]);
  93. SCIPutChar(port,p[1]);
  94. SCIPutChar(port,p[0]);
  95. }


接收数据

  1. /**
  2. *ReceiveachardatafromSCImodule,noreply.
  3. *@paramportportcanbeSCI0/SCI1
  4. *@returnthereceivedchar
  5. */
  6. unsignedcharSCIGetChar(unsignedcharport)
  7. {
  8. if(port==SCI0)
  9. {
  10. while(SCI0SR1_RDRF==0);
  11. returnSCI0DRL;
  12. }
  13. else
  14. {
  15. while(SCI1SR1_RDRF==0);
  16. returnSCI1DRL;
  17. }
  18. }

相应的头文件

  1. /**
  2. *\filesci.h
  3. *\authorLiYuan
  4. *platform:mc9s12dp256B
  5. *date:2012-4-16
  6. *version:1.0.0
  7. *description:SCI(SerialCommunicationInterface)SupportCode
  8. */
  9. #ifndef_SCI_H_
  10. #define_SCI_H_
  11. #defineSCI00
  12. #defineSCI11
  13. #defineIDLE_LINE0
  14. #defineADDRESS_MARK1
  15. #defineNORMAL_MODE0
  16. #defineLOOP_MODE1
  17. #defineSING_WIRE_MODE2
  18. #defineRUN_MODE0
  19. #defineWAIT_MODE1
  20. /*FunctionDeclaration*/
  21. /**
  22. *SettheBaudRateoftheSCI.
  23. *@paramport,portcanbeSCI0/SCI1
  24. *@parambaudRate,thewantedbaudrate.
  25. *@parambusClk,TheSCImoduleclock.
  26. */
  27. voidSCISetBaudRate(unsignedcharport,unsignedlongbaudRate,unsignedlongbusClk);
  28. /**
  29. *SettheInterruptEnableBit
  30. *@paramportportcanbeSCI0/SCI1
  31. *@paramtieTransmitterInterruptEnableBIt
  32. *@paramtcieTransmissionCompleteInterruptEnableBIt
  33. *@paramrieReceiverFullInterruptEnableBIt
  34. *@paramilieIdleLineInterruptEnableBIt
  35. *0InterruptrequestsDisabled
  36. *1InterruptrequestsEnabled
  37. */
  38. voidSCISetIEBit(unsignedcharport,unsignedchartie,unsignedchartcie,unsignedcharrie,unsignedcharilie);
  39. /**
  40. *EnableTheTxinterrupt(TransmitterInterruptEnableBIt)
  41. *@paramport,portcanbeSCI0/SCI1
  42. */
  43. voidSCIEnableTxInt(unsignedcharport);
  44. /**
  45. *DisableTheTxinterrupt(TransmitterInterruptEnableBIt)
  46. *@paramport,portcanbeSCI0/SCI1
  47. */
  48. voidSCIDisTxInt(unsignedcharport);
  49. /**
  50. *Enable/DisableSCIReceiver
  51. *@paramportportcanbeSCI0/S

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

网站地图

Top