<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > Freescale 9S12 系列單片機應(yīng)用筆記(SCI)3

          Freescale 9S12 系列單片機應(yīng)用筆記(SCI)3

          作者: 時間:2016-11-20 來源:網(wǎng)絡(luò) 收藏
          這次介紹如何在 uC/OS-II 上實現(xiàn)串口驅(qū)動。


          本文引用地址:http://www.ex-cimer.com/article/201611/318825.htm
          1. /*sci_ucos.h*/
          2. #ifndef_SCI_RTOS_H_

          3. #define_SCI_RTOS_H_

            #defineSCI_RX_BUF_SIZE64/*NumberofcharactersinRxringbuffer*/

          4. #defineSCI_TX_BUF_SIZE64/*NumberofcharactersinTxringbuffer*/

            /*

          5. *********************************************************************************************************
          6. *CONSTANTS
          7. *********************************************************************************************************
          8. */

            #ifndefNUL

          9. #defineNUL0x00
          10. #endif

            /*ERRORCODES*/

          11. #defineSCI_NO_ERR0/*Functioncallwassuccessful*/
          12. #defineSCI_BAD_CH1/*Invalidcommunicationsportchannel*/
          13. #defineSCI_RX_EMPTY2/*Rxbufferisempty,nocharacteravailable*/
          14. #defineSCI_TX_FULL3/*Txbufferisfull,couldnotdepositcharacter*/
          15. #defineSCI_TX_EMPTY4/*IftheTxbufferisempty.*/
          16. #defineSCI_RX_TIMEOUT5/*Ifatimeoutoccurredwhilewaitingforacharacter*/
          17. #defineSCI_TX_TIMEOUT6/*Ifatimeoutoccurredwhilewaitingtosendachar.*/

          18. #defineSCI_PARITY_NONE0/*Definesforsettingparity*/
          19. #defineSCI_PARITY_ODD1
          20. #defineSCI_PARITY_EVEN2

          21. /*
          22. *********************************************************************************************************
          23. *DATATYPES
          24. *********************************************************************************************************
          25. */
          26. typedefstruct{
          27. shortRingBufRxCtr;/*NumberofcharactersintheRxringbuffer*/
          28. OS_EVENT*RingBufRxSem;/*PointertoRxsemaphore*/
          29. unsignedchar*RingBufRxInPtr;/*Pointertowherenextcharacterwillbeinserted*/
          30. unsignedchar*RingBufRxOutPtr;/*Pointerfromwherenextcharacterwillbeextracted*/
          31. unsignedcharRingBufRx[SCI_RX_BUF_SIZE];/*Ringbuffercharacterstorage(Rx)*/
          32. shortRingBufTxCtr;/*NumberofcharactersintheTxringbuffer*/
          33. OS_EVENT*RingBufTxSem;/*PointertoTxsemaphore*/
          34. unsignedchar*RingBufTxInPtr;/*Pointertowherenextcharacterwillbeinserted*/
          35. unsignedchar*RingBufTxOutPtr;/*Pointerfromwherenextcharacterwillbeextracted*/
          36. unsignedcharRingBufTx[SCI_TX_BUF_SIZE];/*Ringbuffercharacterstorage(Tx)*/
          37. }SCI_RING_BUF;

          38. /**
          39. *Toobtainacharacterfromthecommunicationschannel.
          40. *@paramport,portcanbeSCI0/SCI1
          41. *@paramto,istheamountoftime(inclockticks)thatthecallingfunctioniswillingto
          42. *waitforacharactertoarrive.Ifyouspecifyatimeoutof0,thefunctionwill
          43. *waitforeverforacharactertoarrive.
          44. *@paramerr,isapointertowhereanerrorcodewillbeplaced:
          45. **errissettoSCI_NO_ERRifacharacterhasbeenreceived
          46. **errissettoSCI_RX_TIMEOUTifatimeoutoccurred
          47. **errissettoSCI_BAD_CHifyouspecifyaninvalidchannelnumber
          48. *@returnThecharacterinthebuffer(orNULifatimeoutoccurred)
          49. */
          50. unsignedcharSCIGetCharB(unsignedcharch,unsignedshortto,unsignedchar*err);

            /**

          51. *Thisfunctioniscalledbyyourapplicationtosendacharacteronthecommunications
          52. *channel.Thefunctionwillwaitforthebuffertoemptyoutifthebufferisfull.
          53. *Thefunctionreturnstoyourapplicationifthebufferdoesntemptywithinthespecified
          54. *timeout.Atimeoutvalueof0meansthatthecallingfunctionwillwaitforeverforthe
          55. *buffertoemptyout.ThecharactertosendisfirstinsertedintotheTxbufferandwill
          56. *besentbytheTxISR.Ifthisisthefirstcharacterplacedintothebuffer,theTxISR
          57. *willbeenabled.
          58. *
          59. *@paramport,portcanbeSCI0/SCI1
          60. *@paramcisthecharactertosend.
          61. *@paramtoisthetimeout(inclockticks)towaitincasethebufferisfull.Ifyou
          62. *specifyatimeoutof0,thefunctionwillwaitforeverforthebuffertoempty.
          63. *@returnSCI_NO_ERRifthecharacterwasplacedintheTxbuffer
          64. *SCI_TX_TIMEOUTifthebufferdidntemptywithinthespecifiedtimeoutperiod
          65. *SCI_BAD_CHifyouspecifyaninvalidchannelnumber
          66. */
          67. unsignedcharSCIPutCharB(unsignedcharport,unsignedcharc,unsignedshortto);

            /**

          68. *Toinitializethecommunicationsmodule.
          69. *Youmustcallthisfunctionbeforecallinganyotherfunctions.
          70. */
          71. voidSCIBufferInit(void);

            /**

          72. *Toseeifanycharacterisavailablefromthecommunicationschannel.
          73. *
          74. *@paramport,portcanbeSCI0/SCI1
          75. *@returnIfatleastonecharacterisavailable,thefunctionreturns
          76. *FALSE(0)otherwise,thefunctionreturnsTRUE(1).
          77. */
          78. unsignedcharSCIBufferIsEmpty(unsignedcharport);

          79. /**
          80. *ToseeifanymorecharacterscanbeplacedintheTxbuffer.
          81. *Inotherwords,thisfunctionchecktoseeiftheTxbufferisfull.
          82. *
          83. *@paramport,portcanbeSCI0/SCI1
          84. *@returnIfthebufferisfull,thefunctionreturnsTRUE
          85. *otherwise,thefunctionreturnsFALSE.
          86. */
          87. unsignedcharSCIBufferIsFull(unsignedcharport);

            #endif


          1. /**

          2. *SCI(SerialCommunicationInterface)BufferedSerialI/O
          3. *@filesci_ucos.c
          4. *@authorLiYuan
          5. *@platformmc9s12XX
          6. *@date2012-7-22
          7. *@version1.0.1
          8. */

          9. #include"derivative.h"/*derivative-specificdefinitions*/
          10. #include
          11. #include"includes.H"
          12. #include"sci.h"
          13. #include"sci_rtos.h"

            /**

          14. *GLOBALVARIABLES
          15. */
          16. SCI_RING_BUFSCI0Buf;
          17. SCI_RING_BUFSCI1Buf;

          18. /**
          19. *Toobtainacharacterfromthecommunicationschannel.
          20. *@paramport,portcanbeSCI0/SCI1
          21. *@paramto,istheamountoftime(inclockticks)thatthecallingfunctioniswillingto
          22. *waitforacharactertoarrive.Ifyouspecifyatimeoutof0,thefunctionwill
          23. *waitforeverforacharactertoarrive.
          24. *@paramerr,isapointertowhereanerrorcodewillbeplaced:
          25. **errissettoSCI_NO_ERRifacharacterhasbeenreceived
          26. **errissettoSCI_RX_TIMEOUTifatimeoutoccurred
          27. **errissettoSCI_BAD_CHifyouspecifyaninvalidchannelnumber
          28. *@returnThecharacterinthebuffer(orNULifatimeoutoccurred)
          29. */
          30. unsignedcharSCIGetCharB(unsignedcharport,unsignedshortto,INT8U*err)
          31. {
          32. #ifOS_CRITICAL_METHOD==3u/*AllocatestorageforCPUstatusregister*/
          33. OS_CPU_SRcpu_sr=0u;
          34. #endif
          35. unsignedcharc;
          36. unsignedcharoserr;
          37. SCI_RING_BUF*pbuf;

            switch(port)

          38. {/*Obtainpointertocommunicationschannel*/
          39. caseSCI0:
          40. pbuf=&SCI0Buf;
          41. break;

            caseSCI1:

          42. pbuf=&SCI1Buf;
          43. break;

            default:

          44. *err=SCI_BAD_CH;
          45. return(0);
          46. }
          47. OSSemPend(pbuf->RingBufRxSem,to,&oserr);/*Waitforcharactertoarrive*/
          48. if(oserr==OS_TIMEOUT)
          49. {/*Seeifcharactersreceivedwithintimeout*/
          50. *err=SCI_RX_TIMEOUT;/*No,returnerrorcode*/
          51. return(NUL);
          52. }
          53. else
          54. {
          55. OS_ENTER_CRITICAL();
          56. pbuf->RingBufRxCtr--;/*Yes,decrementcharactercount*/
          57. c=*pbuf->RingBufRxOutPtr++;/*Getcharacterfrombuffer*/
          58. if(pbuf->RingBufRxOutPtr==&pbuf->RingBufRx[SCI_RX_BUF_SIZE]){/*WrapOUTpointer*/
          59. pbuf->RingBufRxOutPtr=&pbuf->RingBufRx[0];
          60. }
          61. OS_EXIT_CRITICAL();
          62. *err=SCI_NO_ERR;
          63. return(c);
          64. }
          65. }

            /**

          66. *Thisfunctioniscalledbyyourapplicationtosendacharacteronthecommunications
          67. *channel.Thefunctionwillwaitforthebuffertoemptyoutifthebufferisfull.
          68. *Thefunctionreturnstoyourapplicationifthebufferdoesntemptywithinthespecified
          69. *timeout.Atimeoutvalueof0meansthatthecallingfunctionwillwaitforeverforthe
          70. *buffertoemptyout.ThecharactertosendisfirstinsertedintotheTxbufferandwill
          71. *besentbytheTxISR.Ifthisisthefirstcharacterplacedintothebuffer,theTxISR
          72. *willbeenabled.
          73. *
          74. *@paramport,portcanbeSCI0/SCI1
          75. *@paramcisthecharactertosend.
          76. *@paramtoisthetimeout(inclockticks)towaitincasethebufferisfull.Ifyou
          77. *specifyatimeoutof0,thefunctionwillwaitforeverforthebuffertoempty.
          78. *@returnSCI_NO_ERRifthecharacterwasplacedintheTxbuffer
          79. *SCI_TX_TIMEOUTifthebufferdidntemptywithinthespecifiedtimeoutperiod
          80. *SCI_BAD_CHifyouspecifyaninvalidchannelnumber
          81. */
          82. unsignedcharSCIPutCharB(unsignedcharport,unsignedcharc,unsignedshortto)
          83. {
          84. #ifOS_CRITICAL_METHOD==3u/*AllocatestorageforCPUstatusregister*/
          85. OS_CPU_SRcpu_sr=0u;
          86. #endif

            SCI_RING_BUF*pbuf;

          87. unsignedcharoserr;
          88. switch(port)
          89. {/*Obtainpointertocommunicationschannel*/
          90. caseSCI0:
          91. pbuf=&SCI0Buf;
          92. break;

            caseSCI1:

          93. pbuf=&SCI1Buf;
          94. break;

            default:

          95. return(SCI_BAD_CH);
          96. }

            OSSemPend(pbuf->RingBufTxSem,to,&oserr);/*WaitforspaceinTxbuffer*/

          97. if(oserr==OS_TIMEOUT)
          98. {
          99. return(SCI_TX_TIMEOUT);/*Timedout,returnerrorcode*/
          100. }
          101. OS_ENTER_CRITICAL();
          102. pbuf->RingBufTxCtr++;/*No,incrementcharactercount*/
          103. *pbuf->RingBufTxInPtr++=c;/*Putcharacterintobuffer*/
          104. if(pbuf->RingBufTxInPtr==&pbuf->RingBufTx[SCI_TX_BUF_SIZE])
          105. {
          106. pbuf->RingBufTxInPtr=&pbuf->RingBufTx[0];/*WrapINpointer*/
          107. }
          108. if(pbuf->RingBufTxCtr==1)/*Seeifthisisthefirstcharacter*/
          109. {
          110. SCIEnableTxInt(port);/*Yes,EnableTxinterrupts*/
          111. }
          112. OS_EXIT_CRITICAL();
          113. return(SCI_NO_ERR);
          114. }

            /**

          115. *Toinitializethecommunicationsmodule.
          116. *Youmustcallthisfunctionbeforecallinganyotherfunctions.
          117. */
          118. voidSCIBufferInit(void)
          119. {
          120. SCI_RING_BUF*pbuf;

            pbuf=&SCI0Buf;/*InitializetheringbufferforSCI0*/

          121. pbuf->RingBufRxCtr=0;
          122. pbuf->RingBufRxInPtr=&pbuf->RingBufRx[0];
          123. pbuf->RingBufRxOutPtr=&pbuf->RingBufRx[0];
          124. pbuf->RingBufRxSem=OSSemCreate(0);
          125. pbuf->RingBufTxCtr=0;
          126. pbuf->RingBufTxInPtr=&pbuf->RingBufTx[0];
          127. pbuf->RingBufTxOutPtr=&pbuf->RingBufTx[0];
          128. pbuf->RingBufTxSem=OSSemCreate(SCI_TX_BUF_SIZE);

            pbuf=&SCI1Buf;/*InitializetheringbufferforSCI1*/

          129. pbuf->RingBufRxCtr=0;
          130. pbuf->RingBufRxInPtr=&pbuf->RingBufRx[0];
          131. pbuf->RingBufRxOutPtr=&pbuf->RingBufRx[0];
          132. pbuf->RingBufRxSem=OSSemCreate(0);
          133. pbuf->RingBufTxCtr=0;
          134. pbuf->RingBufTxInPtr=&pbuf->RingBufTx[0];
          135. pbuf->RingBufTxOutPtr=&pbuf->RingBufTx[0];
          136. pbuf->RingBufTxSem=OSSemCreate(SCI_TX_BUF_SIZE);
          137. }

            /**

          138. *Toseeifanycharacterisavailablefromthecommunicationschannel.
          139. *
          140. *@paramport,portcanbeSCI0/SCI1
          141. *@returnIfatleastonecharacterisavailable,thefunctionreturns
          142. *FALSE(0)otherwise,thefunctionreturnsTRUE(1).
          143. */
          144. unsignedcharSCIBufferIsEmpty(unsignedcharport)
          145. {

            #ifOS_CRITICAL_METHOD==3u/*AllocatestorageforCPUstatusregister*/

          146. OS_CPU_SRcpu_sr=0u;
          147. #endif
          148. unsignedcharempty;
          149. SCI_RING_BUF*pbuf;
          150. switch(port)
          151. {/*Obtainpointertocommunicationschannel*/
          152. caseSCI0:
          153. pbuf=&SCI0Buf;
          154. break;

            caseSCI1:

          155. pbuf=&SCI1Buf;
          156. break;
          157. default:
          158. return(0xff);
          159. break;
          160. }
          161. OS_ENTER_CRITICAL();
          162. if(pbuf->RingBufRxCtr>0)
          163. {/*Seeifbufferisempty*/
          164. empty=0;/*BufferisNOTempty*/
          165. }
          166. else
          167. {
          168. empty=1;/*Bufferisempty*/
          169. }
          170. OS_EXIT_CRITICAL();
          171. return(empty);

            }

            /**

          172. *ToseeifanymorecharacterscanbeplacedintheTxbuffer.
          173. *Inotherwords,thisfunctionchecktoseeiftheTxbufferisfull.
          174. *
          175. *@paramport,portcanbeSCI0/SCI1
          176. *@returnIfthebufferisfull,thefunctionreturnsTRUE
          177. *otherwise,thefunctionreturnsFALSE.
          178. */
          179. unsignedcharSCIBufferIsFull(unsignedcharport)
          180. {
          181. #ifOS_CRITICAL_METHOD==3u/*AllocatestorageforCPUstatusregister*/
          182. OS_CPU_SRcpu_sr=0u;
          183. #endif
          184. charfull;
          185. SCI_RING_BUF*pbuf;
          186. switch(port)
          187. {/*Obtainpointertocommunicationschannel*/
          188. caseSCI0:
          189. pbuf=&SCI0Buf;
          190. break;

            caseSCI1:

          191. pbuf=&SCI1Buf;
          192. break;

            default:

          193. return(255);
          194. }
          195. OS_ENTER_CRITICAL();
          196. if(pbuf->RingBufTxCtr
          197. full=0;/*BufferisNOTfull*/
          198. }else{
          199. full=1;/*Bufferisfull*/
          200. }
          201. OS_EXIT_CRITICAL();
          202. return(full);
          203. }

          204. //ThisfunctioniscalledbytheRxISRtoinsertacharacterintothereceiveringbuffer.
          205. staticvoidSCIPutRxChar(unsignedcharport,unsignedcharc)
          206. {

            SCI_RING_BUF*pbuf;

            switch(port)

          207. {/*Obtainpointertocommunicationschannel*/
          208. caseSCI0:
          209. pbuf=&SCI0Buf;
          210. break;

            caseSCI1:

          211. pbuf=&SCI1Buf;
          212. break;

            default:

          213. return;
          214. }
          215. if(pbuf->RingBufRxCtr
          216. pbuf->RingBufRxCtr++;/*No,incrementcharactercount*/
          217. *pbuf->RingBufRxInPtr++=c;/*Putcharacterintobuffer*/
          218. if(pbuf->RingBufRxInPtr==&pbuf->RingBufRx[SCI_RX_BUF_SIZE]){/*WrapINpointer*/
          219. pbuf->RingBufRxInPtr=&pbuf->RingBufRx[0];
          220. }
          221. (void)OSSemPost(pbuf->RingBufRxSem);/*Indicatethatcharacterwasreceived*/
          222. }
          223. }

          224. //ThisfunctioniscalledbytheTxISRtoextractthenextcharacterfromtheTxbuffer.
          225. //ThefunctionreturnsFALSEifthebufferisemptyafterthecharacterisextractedfrom
          226. //thebuffer.ThisisdonetosignaltheTxISRtodisableinterruptsbecausethisisthe
          227. //lastcharactertosend.
          228. staticunsignedcharSCIGetTxChar(unsignedcharport,unsignedchar*err)
          229. {
          230. unsignedcharc;
          231. SCI_RING_BUF*pbuf;

            switch(port)

          232. {/*Obtainpointertocommunicationschannel*/
          233. caseSCI0:
          234. pbuf=&SCI0Buf;
          235. break;

            caseSCI1:

          236. pbuf=&SCI1Buf;
          237. break;

            default:

          238. *err=SCI_BAD_CH;
          239. return(0);
          240. }
          241. if(pbuf->RingBufTxCtr>0){/*Seeifbufferisempty*/
          242. pbuf->RingBufTxCtr--;/*No,decrementcharactercount*/
          243. c=*pbuf->RingBufTxOutPtr++;/*Getcharacterfrombuffer*/
          244. if(pbuf->RingBufTxOutPtr==&pbuf->RingBufTx[SCI_TX_BUF_SIZE]){/*WrapOUTpointer*/
          245. pbuf->RingBufTxOutPtr=&pbuf->RingBufTx[0];
          246. }
          247. (void)OSSemPost(pbuf->RingBufTxSem);/*Indicatethatcharacterwillbesent*/
          248. *err=SCI_NO_ERR;
          249. return(c);/*Charactersarestillavailable*/
          250. }else{
          251. *err=SCI_TX_EMPTY;
          252. return(NUL);/*Bufferisempty*/
          253. }
          254. }

          255. voidSCI0_ISR_Handler(void)
          256. {
          257. charstatus;
          258. chardata;
          259. unsignedcharerr;
          260. status=SCI0SR1;

            if(status&0x0F)//0x1F=00011111,ifstatusisnotReceiveDataRegFullFlag

          261. {
          262. //Seeifwehavesomekindoferror
          263. //Clearinterrupt(donothingaboutit!)
          264. data=SCI0DRL;
          265. }
          266. elseif(status&0x20)//ReceiveDataRegFullFlag
          267. {
          268. data=SCI0DRL;
          269. SCIPutRxChar(SCI0,data);//Insertreceivedcharacterintobuffer
          270. }
          271. elseif(status&0x80)
          272. {
          273. data=SCIGetTxChar(SCI0,&err);//Getnextcharactertosend.
          274. if(err==SCI_TX_EMPTY)
          275. {//Dowehaveanymorecharacterstosend?
          276. //No,DisableTxinterrupts
          277. SCIDisTxInt(SCI0);
          278. }
          279. else
          280. {
          281. SCI0DRL=data;//Yes,Sendcharacter
          282. }
          283. }
          284. }

          285. voidSCI1_ISR_Handler(void)
          286. {
          287. charstatus;
          288. chardata;
          289. unsignedcharerr;
          290. status=SCI1SR1;

            if(status&0x0F)//0x1F=00011111,ifstatusisnotReceiveDataRegFullFlag

          291. {
          292. //Seeifwehavesomekindoferror
          293. //Clearinterrupt(donothingaboutit!)
          294. data=SCI1DRL;
          295. }
          296. elseif(status&0x20)//ReceiveDataRegFullFlag
          297. {
          298. data=SCI1DRL;
          299. SCIPutRxChar(SCI1,data);//Insertreceivedcharacterintobuffer
          300. }
          301. elseif(status&0x80)
          302. {
          303. data=SCIGetTxChar(SCI1,&err);//Getnextcharactertosend.
          304. if(err==SCI_TX_EMPTY)
          305. {//Dowehaveanymorecharacterstosend?
          306. //No,DisableTxinterrupts
          307. SCIDisTxInt(SCI1);
          308. }
          309. else
          310. {
          311. SCI1DRL=data;//Yes,Sendcharacter
          312. }
          313. }
          314. }

            #pragmaCODE_SEGNON_BANKED

          315. interruptVectorNumber_Vsci0voidSCI0_ISR(void)
          316. {

            #ifdefined(__BANKED__)||defined(__LARGE__)||defined(__PPAGE__)

          317. __asmldaaPPAGE;//3~,GetcurrentvalueofPPAGEregister
          318. __asmpsha;//2~,PushPPAGEregisterontocurrenttasksstack
          319. #endif
          320. __asmincOSIntNesting;//OSIntNesting++;

            //if(OSIntNesting==1)

          321. //{
          322. //OSTCBCur->OSTCBStkPtr=StackPointer;
          323. //}
          324. __asm
          325. {
          326. ldabOSIntNesting
          327. cmpb#$01
          328. bneSCI0ISR1

            ldxOSTCBCur

          329. sts0,x
          330. SCI0ISR1:
          331. }

            #ifdefined(__BANKED__)||defined(__LARGE__)||defined(__PPAGE__)

          332. __asmcallSCI0_ISR_Handler;
          333. __asmcallOSIntExit;
          334. #else
          335. __asmjsrSCI0_ISR_Handler;
          336. __asmjsrOSIntExit;
          337. #endif

            #ifdefined(__BANKED__)||defined(__LARGE__)||defined(__PPAGE__)

          338. __asmpula;//3~,GetvalueofPPAGEregister
          339. __asmstaaPPAGE;//3~,StoreintoCPUsPPAGEregister
          340. #endif

            }

            interruptVectorNumber_Vsci1voidSCI1_ISR(void)

          341. {

            #ifdefined(__BANKED__)||defined(__LARGE__)||defined(__PPAGE__)

          342. __asmldaaPPAGE;//3~,GetcurrentvalueofPPAGEregister
          343. __asmpsha;//2~,PushPPAGEregisterontocurrenttasksstack
          344. #endif
          345. __asmincOSIntNesting;//OSIntNesting++;

            //if(OSIntNesting==1)

          346. //{
          347. //OSTCBCur->OSTCBStkPtr=StackPointer;
          348. //}
          349. __asm
          350. {
          351. ldabOSIntNesting
          352. cmpb#$01
          353. bneSCI1ISR1

            ldxOSTCBCur

          354. sts0,x
          355. SCI1ISR1:
          356. }

            #ifdefined(__BANKED__)||defined(__LARGE__)||defined(__PPAGE__)

          357. __asmcallSCI1_ISR_Handler;
          358. __asmcallOSIntExit;
          359. #else
          360. __asmjsrSCI1_ISR_Handler;
          361. __asmjsrOSIntExit;
          362. #endif

            #ifdefined(__BANKED__)||defined(__LARGE__)||defined(__PPAGE__)

          363. __asmpula;//3~,GetvalueofPPAGEregister
          364. __asmstaaPPAGE;//3~,StoreintoCPUsPPAGEregister
          365. #endif

            }

          下面給個簡單的例子:

          1. #include/*commondefinesandmacros*/

          2. #include"derivative.h"/*derivative-specificdefinitions*/

            #include"INCLUDES.H"

          3. #include"crg.h"
          4. #include"sci.h"
          5. #include"sci_rtos.h"

            OS_STKAppStartTaskStk[64];

            staticvoidAppStartTask(void*pdata);

            voidmain(void)

          6. {
          7. /*putyourowncodehere*/
          8. OS_CPU_SRcpu_sr;

            CRGInit();

          9. CRGSetRTIFreqency(0x54);//200Hz

            EnableInterrupts;

          10. OS_ENTER_CRITICAL();
          11. SCIInit(SCI0);
          12. SCIInit(SCI1);
          13. OS_EXIT_CRITICAL();
          14. OSInit();
          15. SCISetIEBit(SCI0,SCI_RIE);
          16. SCISetIEBit(SCI1,SCI_RIE);
          17. SCIBufferInit();
          18. (void)OSTaskCreate(AppStartTask,(void*)0x4321,(void*)&AppStartTaskStk[63],0);
          19. (void)OSStart();
          20. for(;;)
          21. {
          22. _FEED_COP();/*feedsthedog*/
          23. }/*loopforever*/
          24. /*pleasemakesurethatyouneverleavemain*/
          25. }

            staticvoidAppStartTask(void*pdata)

          26. {
          27. INT8Uerr;
          28. charC;
          29. (void)pdata;
          30. for(;;)
          31. {
          32. C=SCIGetCharB(SCI1,0,&err);
          33. if(err==SCI_NO_ERR)
          34. (void)SCIPutCharB(SCI1,C,0);
          35. }
          36. }




          關(guān)鍵詞: Freescale9S12系列單片

          評論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();