Freescale 9S12 系列单片机应用笔记(SCI)1
时间:11-20
来源:互联网
点击:
- CI1
- *@paramisEnable0disable1enable
- */
- voidSCIEnableRecv(unsignedcharport,unsignedcharisEnable);
- /**
- *Enable/DisableSCITransmitter
- *@paramportportcanbeSCI0/SCI1
- *@paramisEnable0disable1enable
- */
- voidSCIEnableTrans(unsignedcharport,unsignedcharisEnable);
- /**
- *SettheIdleLineType
- *@paramportportcanbeSCI0/SCI1
- *@paramtype0Idlecharbitcountbeginsafterstartbit
- *1Idlecharbitcountbeginsafterstopbit
- */
- voidSCISetIdleLineType(unsignedcharport,unsignedchartype);
- /**
- *SettheWakeupCondition.
- *@paramportportcanbeSCI0/SCI1
- *@paramcondi0forIdlelinewakeup,1foraddressmarkwakeup
- */
- voidSCISetWakeupCondi(unsignedcharport,unsignedcharcondi);
- /**
- *Enable/DisableparityfunctionandsettheParitytype
- *@paramportportcanbeSCI0/SCI1
- *@paramisEnable0fordisableparityfunction,1forenable
- *@paramtype0forEvenParity,1forOddParity
- */
- voidSCISetParity(unsignedcharport,unsignedcharisEnable,unsignedchartype);
- /**
- *SettheDataFormatModeBit
- *@paramportportcanbeSCI0/SCI1
- *@parambitsmustbe8or9
- */
- voidSCISetDataBit(unsignedcharport,unsignedcharbits);
- /**
- *Settheworkmodeofoperation
- *@paramportportcanbeSCI0/SCI1
- *@parammodemodecanbeNORMAL_MODE/LOOP_MODE/SING_WIRE_MODE
- */
- voidSCISetWorkMode(unsignedcharport,unsignedcharmode);
- /**
- *Enable/DisabletheSCIinwaitmode
- *@paramportportcanbeSCI0/SCI1
- *@parammodemodecanbeRUN_MODE/WAIT_MODE
- */
- voidSCISetPowerMode(unsignedcharport,unsignedcharmode);
- /**
- *SettheTXDIR(OnlyforSingleWireMODE)
- *@paramportportcanbeSCI0/SCI1
- *@paramdir0TXDusedasinput,1TXDusedasoutput
- */
- voidSCISetTXDIR(unsignedcharport,unsignedchardir);
- /**
- *SendacharthrounghSCImodule.
- *@paramportportcanbeSCI0/SCI1
- *@paramsthedatatobesent
- */
- voidSCIPutChar(unsignedcharport,unsignedchars);
- /**
- *ReceiveachardatafromSCImodule,noreply.
- *@paramportportcanbeSCI0/SCI1
- *@returnthereceivedchar
- */
- unsignedcharSCIGetChar(unsignedcharport);
- /**
- *Sendashortintvalue(BigEndian)throunghSCImodule.
- *@paramportportcanbeSCI0/SCI1
- *@paramithedatatobesent
- */
- voidSCIPutShortBigEndian(unsignedcharport,shorti);
- /**
- *Sendashortintvalue(LittleEndian)throunghSCImodule.
- *@paramportportcanbeSCI0/SCI1
- *@paramithedatatobesent
- */
- voidSCIPutShortLittleEndian(unsignedcharport,shorti);
- /**
- *Sendalongintvalue(BigEndian)throunghSCImodule.
- *@paramportportcanbeSCI0/SCI1
- *@paramithedatatobesent
- */
- voidSCIPutLongBigEndian(unsignedcharport,longi);
- /**
- *Sendalongintvalue(LittleEndian)throunghSCImodule.
- *@paramportportcanbeSCI0/SCI1
- *@paramithedatatobesent
- */
- voidSCIPutLongLittleEndian(unsignedcharport,longi);
- /**
- *SendacharstringthrounghSCImodule.
- *@paramportportcanbeSCI0/SCI1
- *@param*strthestringtobesent
- */
- voidSCIPutStr(unsignedcharport,unsignedchar*str);
- /**
- *SenddatathrounghSCImodule.
- *@paramportportcanbeSCI0/SCI1
- *@param*ppointertothedatatobesent
- *@paramsizethesize(byte)ofthedata
- */
- voidSCIWrite(unsignedcharport,void*p,intsize);
- #endif
下面给个简单的例子
- #include
/*commondefinesandmacros*/ - #include"derivative.h"/*derivative-specificdefinitions*/
- #include"sci.h"
- voidmain(void)
- {
- charC;
- EnableInterrupts;
- SCISetWorkMode(SCI0,NORMAL_MODE);
- SCISetPowerMode(SCI0,RUN_MODE);
- SCISetBaudRate(SCI0,9600,16384000L);//16MClock
- SCISetDataBit(SCI0,8);
- SCISetParity(SCI0,0,0);
- SCIEnableRecv(SCI0,1);
- SCIEnableTrans(SCI0,1);
- for(;;)
- {
- _FEED_COP();/*feedsthedog*/
- C=SCIGetChar(SCI0);
- SCIPutChar(SCI0,C);
- }/*loopforever*/
- /*pleasemakesurethatyouneverleavemain*/
- }
先写这么多,剩下的明天继续。下一篇笔记中将给出如何利用串口的收发中断和环形缓冲区来实现较为完善的串口驱动。