




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、Freescale Semiconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2005.TMTMFreescale Semiconductor Confidenti
2、al and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2005.HCS12中斷中斷默認(rèn)狀態(tài):默認(rèn)狀態(tài): 在進(jìn)入中斷服務(wù)程序時(shí),在進(jìn)入中斷服務(wù)程序時(shí),I位自動(dòng)置位自動(dòng)置1,禁止其他可屏蔽中斷,禁止其他可屏蔽中斷
3、 即使有優(yōu)先級(jí)更高的中斷請(qǐng)求,也必須等當(dāng)前中斷服務(wù)程序執(zhí)行完即使有優(yōu)先級(jí)更高的中斷請(qǐng)求,也必須等當(dāng)前中斷服務(wù)程序執(zhí)行完以后才能響應(yīng)以后才能響應(yīng) 優(yōu)先級(jí)的作用只有在多個(gè)中斷源同時(shí)請(qǐng)求中斷時(shí)在能體現(xiàn)優(yōu)先級(jí)的作用只有在多個(gè)中斷源同時(shí)請(qǐng)求中斷時(shí)在能體現(xiàn) 無法實(shí)現(xiàn)中斷嵌套無法實(shí)現(xiàn)中斷嵌套如果在進(jìn)入中斷服務(wù)程序時(shí),手動(dòng)對(duì)如果在進(jìn)入中斷服務(wù)程序時(shí),手動(dòng)對(duì)I位清零:位清零: 任何其他可屏蔽中斷都可以被響應(yīng),無論其優(yōu)先級(jí)有多高任何其他可屏蔽中斷都可以被響應(yīng),無論其優(yōu)先級(jí)有多高 中斷響應(yīng)由時(shí)間控制,可以實(shí)現(xiàn)中斷嵌套中斷響應(yīng)由時(shí)間控制,可以實(shí)現(xiàn)中斷嵌套 對(duì)中斷執(zhí)行無法預(yù)測(cè)對(duì)中斷執(zhí)行無法預(yù)測(cè)HPRIO寄存器寄存器 寫
4、入寫入HPRIO中的中斷向量的后八位,可以改變?cè)撝袛嗟膬?yōu)先級(jí)中的中斷向量的后八位,可以改變?cè)撝袛嗟膬?yōu)先級(jí) 同樣,優(yōu)先級(jí)的作用只有在多個(gè)中斷源同時(shí)請(qǐng)求中斷時(shí)在能體現(xiàn)同樣,優(yōu)先級(jí)的作用只有在多個(gè)中斷源同時(shí)請(qǐng)求中斷時(shí)在能體現(xiàn)TMFreescale Semiconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the
5、 property of their respective owners. Freescale Semiconductor, Inc. 2005.在CW4.6環(huán)境下,中斷編程主要有兩種方式:第一種是使用“interrupt”關(guān)鍵字,“interrupt”關(guān)鍵字是一個(gè)非標(biāo)準(zhǔn)ANSI-C的關(guān)鍵字,因此,它不能被所有ANSI-C編譯器廠商所支持。同樣,對(duì)不同的編譯器,interrupt”關(guān)鍵字的用法可能會(huì)改變?!癷nterrupt”關(guān)鍵字同樣會(huì)提示編譯器下面的函數(shù)是一個(gè)中斷服務(wù)例程。例: void interrupt 20 SCI0_ISR(void);其中,interrupt表示該函數(shù)為終端服務(wù)程
6、序,后面的20表示中斷號(hào)20,在這里SCI0的中斷向量號(hào)就是20.這種方法寫起來非常簡單,但是,在S12單片機(jī)實(shí)際使用中,中斷號(hào)并沒有在手冊(cè)中給出,通常需要自己在中斷向量表中從上往下數(shù)出來,或者根據(jù)中斷向量計(jì)算得到,很容易出錯(cuò)。 于是有了第二種方法:在ISR程序之前,使用符號(hào)“#pragma TRAP_PROC”,TRAP_PROC 提示編譯器下面的函數(shù)是中斷服務(wù)例程。編譯器會(huì)用一個(gè)特殊的中斷返回指令來結(jié)束這個(gè)函數(shù)。此時(shí),中斷函數(shù)的書寫如下所示:#pragma TRAP_PROCvoid SCI0_ISR(void) . 這時(shí)候編譯器不知道這個(gè)ISR指向那個(gè)中斷向量,我們需要在鏈接文件即:pr
7、m文件中指定之。使用 VECTOR命令來實(shí)現(xiàn)中斷向量與ISR程序的連接。例:VECTOR 0 _Startup /這是系統(tǒng)默認(rèn)prm文件中自帶的,即復(fù)位后0號(hào)中斷即復(fù)位中斷的ISR為_Startup()我們可以這樣寫:VECTOR 20 SCI0_ISR /指定中斷號(hào)或者VECTOR ADDRESS 0 xFFD6 SCI0_ISR /直接指定中斷向量地址 注:使用#pragma TRAP_PROC與修改prm文件的方法,在中斷服務(wù)子程序的結(jié)尾處必須要手動(dòng)加入返回主程序的指令,包括取出堆棧、中斷返回兩個(gè)步驟。在S12單片機(jī)中,可以寫作asm pula; rti; 尾注:兩種方法所寫的中斷服務(wù)子
8、程序必須被放在非分頁存儲(chǔ)區(qū)內(nèi),即non_blanked code seg.其中一種常用的方法是在服務(wù)子程序前聲明:/下面代碼放在NON_BANKED區(qū)#pragma CODE_SEG NON_BANKED在中斷程序后聲明:/下面內(nèi)容按默認(rèn)放置#pragma CODE_SEG DEFAULT TMFreescale Semiconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All o
9、ther product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2005.HCS12默認(rèn)中斷處理機(jī)制默認(rèn)中斷處理機(jī)制運(yùn)運(yùn) 行行運(yùn)運(yùn) 行行運(yùn)運(yùn) 行行等等 待待運(yùn)運(yùn) 行行等等 待待中斷中斷 A中斷中斷 B程序程序低優(yōu)先級(jí)低優(yōu)先級(jí)高優(yōu)先級(jí)高優(yōu)先級(jí)中斷中斷A請(qǐng)求請(qǐng)求中斷中斷B請(qǐng)求請(qǐng)求等等 待待人人人人平平等等TMFreescale Semiconductor Confidential and Proprietary Information. Freescal
10、e and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2005.在可屏蔽中斷服務(wù)程序中在可屏蔽中斷服務(wù)程序中EnableInterrupts運(yùn)運(yùn) 行行運(yùn)運(yùn) 行行運(yùn)運(yùn) 行行等等 待待運(yùn)運(yùn) 行行運(yùn)運(yùn) 行行等等 待待中斷中斷 A中斷中斷 B程序程序低優(yōu)先級(jí)低優(yōu)先級(jí)高優(yōu)先級(jí)高優(yōu)先級(jí)中斷中斷B請(qǐng)求
11、請(qǐng)求中斷中斷B被掛起被掛起中斷中斷A請(qǐng)求請(qǐng)求長長幼幼不不分分TMFreescale Semiconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2005.采用中斷優(yōu)先
12、處理機(jī)制采用中斷優(yōu)先處理機(jī)制運(yùn)運(yùn) 行行運(yùn)運(yùn) 行行等等 待待運(yùn)運(yùn) 行行運(yùn)運(yùn) 行行等等 待待中斷中斷 A中斷中斷 B程序程序低優(yōu)先級(jí)低優(yōu)先級(jí)高優(yōu)先級(jí)高優(yōu)先級(jí)中斷中斷A請(qǐng)求請(qǐng)求中斷中斷B請(qǐng)求請(qǐng)求中斷中斷B返回返回運(yùn)運(yùn) 行行等等級(jí)級(jí)森森嚴(yán)嚴(yán)TMFreescale Semiconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names
13、are the property of their respective owners. Freescale Semiconductor, Inc. 2005.中斷優(yōu)先處理機(jī)制中斷優(yōu)先處理機(jī)制在中斷服務(wù)程序中,首先對(duì)I為清零,即EnableInterrupts選擇優(yōu)先級(jí)更高的中斷源可以進(jìn)入響應(yīng)中斷設(shè)置優(yōu)先等級(jí)兩級(jí)一個(gè)中斷源為低優(yōu)先級(jí),其他為高優(yōu)先級(jí)在低優(yōu)先級(jí)中斷服務(wù)程序中,對(duì)I位清零在高優(yōu)先級(jí)中斷服務(wù)程序中,不清零多級(jí)利用局部的中斷屏蔽位比如Timer Channel0 的中斷屏蔽位 TIE_C0ITMFreescale Semiconductor Confidential and Propr
14、ietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2005.優(yōu)先機(jī)制優(yōu)先機(jī)制 - 兩級(jí)兩級(jí)例如: 中斷向量地址 $FFF0 FFF1 為低優(yōu)先級(jí) 其他的中斷為高優(yōu)先級(jí) 在$FFF0 FFF1 中斷服務(wù)程序中,EnableInte
15、rrupts(I位清零) 其他的中斷包括自己都可以在中斷服務(wù)程序執(zhí)行時(shí),被響應(yīng) 在其他的中斷服務(wù)程序中,I位不清零(默認(rèn)) 只有當(dāng)前中斷服務(wù)程序執(zhí)行完后,才能響應(yīng)其他的中斷請(qǐng)求當(dāng)同時(shí)有多個(gè)中斷源請(qǐng)求中斷時(shí),中斷向量地址最靠近當(dāng)同時(shí)有多個(gè)中斷源請(qǐng)求中斷時(shí),中斷向量地址最靠近$FFFF的,將會(huì)首先被響應(yīng)的,將會(huì)首先被響應(yīng)TMFreescale Semiconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconducto
16、r, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2005.優(yōu)先機(jī)制優(yōu)先機(jī)制 多級(jí)多級(jí)自定義優(yōu)先級(jí)中斷向量地址中斷源CCR屏蔽位局部屏蔽位HPRIO1中$FFEE, $FFEFECT 通道0ITIE_C0I$EE0低$FFEC, $FFEDECT 通道1ITIE_C1I$EC2高$FFEA, $FFEBECT 通道2ITIE_C2I$EA要求:要求: 在低優(yōu)先級(jí)的中斷服務(wù)程序中,高優(yōu)先級(jí)的中斷請(qǐng)求可以被響應(yīng)在低
17、優(yōu)先級(jí)的中斷服務(wù)程序中,高優(yōu)先級(jí)的中斷請(qǐng)求可以被響應(yīng)HPRIO = 0 xEA: ECT0,1,2同時(shí)請(qǐng)求中斷時(shí),CPU將會(huì)首先響應(yīng)通道2默認(rèn)時(shí), CPU將會(huì)首先響應(yīng)通道0TMFreescale Semiconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their resp
18、ective owners. Freescale Semiconductor, Inc. 2005.優(yōu)先機(jī)制優(yōu)先機(jī)制 多級(jí)多級(jí)情況 1:每個(gè)中斷都單獨(dú)發(fā)生,在一個(gè)中斷程序執(zhí)行時(shí),沒有其他中斷情況 2:在執(zhí)行ECT1的中斷服務(wù)程序時(shí),ECT0請(qǐng)求中斷ECT0中斷服務(wù)程序?qū)⒈粓?zhí)行情況 3:在執(zhí)行ECT2的中斷服務(wù)程序時(shí),ECT0請(qǐng)求中斷ECT2的中斷服務(wù)程序執(zhí)行結(jié)束后,執(zhí)行ECT0的中斷服務(wù)程序情況 4:ECT1,ECT2同時(shí)請(qǐng)求中斷 ECT1的中斷服務(wù)程序先執(zhí)行,當(dāng)EnableInterrupts后執(zhí)行ECT2的中斷服務(wù)程序ECT2的中斷服務(wù)程序執(zhí)行結(jié)束后,返回執(zhí)行ECT1的中斷服務(wù)程序TMFr
19、eescale Semiconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2005.方案:優(yōu)先機(jī)制方案:優(yōu)先機(jī)制 多級(jí)多級(jí)在ECT0中斷服務(wù)程序中:在ECT1中斷服
20、務(wù)程序中(自定義優(yōu)先級(jí)最低):在ECT2中斷服務(wù)程序中(自定義優(yōu)先級(jí)最高):用戶程序TIE_C1I = 0; /關(guān)閉ECT1局部中斷TIE_C2I = 1; /開放ECT2局部中斷EnableInterrupts; /開放全局中斷TIE_C1I = 1; /開放ECT1局部中斷TIE_C2I = 1; /開放ECT2局部中斷TIE_C0I = 1; /開放ECT0局部中斷TIE_C2I = 1; /開放ECT2局部中斷EnableInterrupts; /開放全局中斷TIE_C0I = 1; /開放ECT0局部中斷TIE_C2I = 1; /開放ECT2局部中斷TMFreescale Semi
21、conductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2005.ECT模塊的組成模塊的組成8 個(gè)獨(dú)立的定時(shí)器通道,每個(gè)通道具備輸入捕捉和輸出比較功能4 個(gè)帶有8 位緩存
22、的脈沖累加器,也可以作為2個(gè)16 位的累加器使用 帶有4 位預(yù)分頻因子的16 位模數(shù)遞減計(jì)數(shù)器 用戶可選可抵御噪音的延遲計(jì)數(shù)器TMFreescale Semiconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescal
23、e Semiconductor, Inc. 2005.ECT系統(tǒng)控制寄存器系統(tǒng)控制寄存器1: TSCR1TEN=1:定時(shí)器使能; TEN=0:定時(shí)器禁止,進(jìn)入低功耗狀態(tài)。TSWAI=0:等待模式時(shí)定時(shí)器繼續(xù)工作,方便調(diào)試; 1:禁止定時(shí)器。TSFRZ=0:凍結(jié)模式時(shí)定時(shí)器繼續(xù)工作,方便仿真; 1:禁止定時(shí)器。TFFCA=0:自動(dòng)清除標(biāo)志位; 1:手動(dòng)清除。注:在ECT模塊初始化時(shí)必須設(shè)置TSCR1才可以使定時(shí)器工作。一般設(shè)置TSCR1=0 x80TSCR1TMFreescale Semiconductor Confidential and Proprietary Information. Fr
24、eescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2005.ECT系統(tǒng)控制寄存器系統(tǒng)控制寄存器2: TSCR2TOI=0:禁止定時(shí)器溢出中斷; TOI=1:允許。TCRE=0:定時(shí)器自由運(yùn)行;1=輸出比較7引起復(fù)位。PR2、PR1、PR0:定時(shí)器預(yù)分頻因子TSCR2PR2
25、00001111PR100110011PR001010101預(yù)分頻因子預(yù)分頻因子2021222324252627定時(shí)器時(shí)鐘頻率定時(shí)器時(shí)鐘頻率總線時(shí)鐘頻率總線時(shí)鐘頻率/1總線時(shí)鐘頻率總線時(shí)鐘頻率/2總線時(shí)鐘頻率總線時(shí)鐘頻率/4總線時(shí)鐘頻率總線時(shí)鐘頻率/8總線時(shí)鐘頻率總線時(shí)鐘頻率/16總線時(shí)鐘頻率總線時(shí)鐘頻率/32總線時(shí)鐘頻率總線時(shí)鐘頻率/64總線時(shí)鐘頻率總線時(shí)鐘頻率/128TMFreescale Semiconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademar
26、ks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2005.ECT系統(tǒng)計(jì)數(shù)寄存器:系統(tǒng)計(jì)數(shù)寄存器:TCNTTCNT: 16位的加1自由計(jì)數(shù)器,最大值為65535。一般直接(非中斷)使用的方法: while(TCNT!=0 x0000); /計(jì)算未滿足時(shí),就一直等待 while(TCNT=0 x0000);/計(jì)數(shù)瞬時(shí)滿足TCNTTMFreescale Sem
27、iconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2005.實(shí)驗(yàn)3:內(nèi)容(1) ECT控制流水燈顯示流水燈顯示int counter;void TimerOver
28、flow(void) while (TCNT != 0 x0000); /等待TCNT溢出時(shí)(恢復(fù)0 x0000),就結(jié)束空循環(huán),執(zhí)行下面語句 counter+; if (counter = 8) PORTB = 0 x7e; / 0 x7e=0111 1110 if (counter = 7) PORTB = 0 xbd; / 0 xbd=1011 1101 if (counter = 6) PORTB = 0 xdb; / 0 xdb=1101 1011 if (counter = 5) PORTB = 0 xe7; if (counter = 4) PORTB = 0 xe7; if (
29、counter = 3) PORTB = 0 xdb; if (counter = 2) PORTB = 0 xbd; if (counter = 1) PORTB = 0 x7e; void main(void) TSCR1 = 0 x80; / TSCR1.7=TEN位(Timer Enable位,0=Disables,1=enable) TSCR2 = 0 x03; / 預(yù)分頻器設(shè)置 TSCR2.2-0:0=1,1=2,2=4,3=8,4=16,5=32,6=64,7=128 /預(yù)置分頻系數(shù)控制著每個(gè)自由運(yùn)行計(jì)數(shù)時(shí)間,它需要216個(gè)定時(shí)器時(shí)鐘時(shí)間才溢出一次. counter = 0; D
30、DRB=0 xff; / 設(shè)置端口B為輸出方式 PORTB=0 xff; / LEDs off for (;) TimerOverflow(); if (counter = 8) counter = 0; TSCR2 = 0 x05; /調(diào)整定時(shí)器的預(yù)分頻器值 本例是否使用中斷TMFreescale Semiconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other pr
31、oduct or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2005.主要主要用途用途: 測(cè)量事件發(fā)生的間隔時(shí)間測(cè)量事件發(fā)生的間隔時(shí)間輸入捕捉能感應(yīng)到引腳上的電平的變化輸入捕捉能感應(yīng)到引腳上的電平的變化如果發(fā)現(xiàn)電平變化,則:如果發(fā)現(xiàn)電平變化,則:1、計(jì)數(shù)器的值被保存到到輸入捕捉寄存器中,狀態(tài)標(biāo)志位被、計(jì)數(shù)器的值被保存到到輸入捕捉寄存器中,狀態(tài)標(biāo)志位被置置12、如果中斷允許,則向、如果中斷允許,則向CPU發(fā)出中斷請(qǐng)求發(fā)出中斷請(qǐng)求定時(shí)器模塊輸入捕捉功能定時(shí)器模塊輸
32、入捕捉功能定時(shí)器模塊定時(shí)器模塊IC0-IC7: 既可以用于輸入捕捉、也可以用于輸出比較既可以用于輸入捕捉、也可以用于輸出比較功能功能TMFreescale Semiconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Frees
33、cale Semiconductor, Inc. 2005.定時(shí)器模塊輸入捕捉定時(shí)器模塊輸入捕捉IOSx: 0=通道x為輸入捕捉獲; 1=通道x為輸出比較。輸入捕捉輸入捕捉/輸出比較選擇寄存器輸出比較選擇寄存器TIOS8個(gè)個(gè)16位的定時(shí)器通道寄存器位的定時(shí)器通道寄存器TC0,TC1,TC7當(dāng)檢測(cè)到IOSx選擇位對(duì)應(yīng)的輸入捕捉沿跳變、或觸發(fā)輸出比較的輸出動(dòng)作時(shí),鎖存自由運(yùn)行計(jì)數(shù)器的計(jì)數(shù)值。B2B1B0 C7F C6F C5F C4F C3F C2F C1F C0FB6B5B4B3B7B2B1B0RST: 0 0 0 0 0 0 0 0捕捉/比較通道x的中斷標(biāo)志位,寫 1清除中斷狀態(tài)標(biāo)志位。定時(shí)器
34、中斷標(biāo)志寄存器定時(shí)器中斷標(biāo)志寄存器1: TFLG1CxI:1=第x個(gè)通道中斷允許; 0=第x個(gè)通道中斷禁止。定時(shí)器中斷使能寄存器定時(shí)器中斷使能寄存器: TIETMFreescale Semiconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective
35、owners. Freescale Semiconductor, Inc. 2005.定時(shí)器模塊輸入捕捉定時(shí)器模塊輸入捕捉EDGnA/B:輸入捕捉邊沿控制,n代表通道序號(hào)。控制寄存器控制寄存器3/4: TCTL3、TCTL4TMFreescale Semiconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are
36、the property of their respective owners. Freescale Semiconductor, Inc. 2005.定時(shí)器模塊輸入捕捉定時(shí)器模塊輸入捕捉SHxy=0:正常操作。1=通道x在通道y上產(chǎn)生同樣的動(dòng)作。TFMOD=0:只要產(chǎn)生正確的輸入捕獲事件,TFLG1中的CxF位就置一。1=隊(duì)列模式時(shí)才使用。PACMX=0:8位脈沖累加器溢出后自動(dòng)回0。1=不自動(dòng)回0,停留在0XFF。脈沖累加器對(duì)IC通道捕獲的有效邊沿?cái)?shù)量進(jìn)行計(jì)數(shù)。BUFEN=1:使用輸入捕獲緩沖區(qū)。0=不使用。LATQ=0:輸入捕獲隊(duì)列模式使能。產(chǎn)生一次成功的輸入捕獲時(shí),IC通道寄存器中保留
37、的計(jì)數(shù)值會(huì)被送到保持器中,然后IC寄存器會(huì)接收新的計(jì)數(shù)值。1=鎖存模式使能。輸入控制系統(tǒng)控制寄存器:輸入控制系統(tǒng)控制寄存器:ICSYSTMFreescale Semiconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Free
38、scale Semiconductor, Inc. 2005.實(shí)驗(yàn)3:內(nèi)容(2) ECT輸入捕捉控制LED燈顯示顯示要求:利用輸入捕捉0通道,對(duì)外來的信號(hào)進(jìn)行下降沿捕捉,并觸發(fā)中斷。中斷發(fā)生后用LED燈指示中斷成功。void main(void) EnableInterrupts; sysInit(); /包含ECTInit(void) DDRB = 0 xFF; / PTB as output 設(shè)置端口B為輸出方式 PORTB = 0 x00;/ LEDs on for(;) void ECTInit(void) TIOS_IOS0 = 0; / Put the PT0 as the Inp
39、ut Capture Pin /設(shè)置PT0為輸入捕捉(IC) TSCR1 = 0 x90; /0 x90=1001 0000 Enable the Clock定時(shí)器使能, 自動(dòng)清除相應(yīng)寄存器 TCTL4_EDG0B = 1, TCTL4_EDG0A = 0; /下降沿捕捉 TSCR2_PR0 = 1; /預(yù)分頻系數(shù)Prescale = 32 TSCR2_PR1 = 0; TSCR2_PR2 = 1; TIE_C0I = 1; /定時(shí)器中斷使能寄存器TIE,COI=1中斷使能,=0中斷屏蔽interrupt void Enhanced_Capture_Timer_channel_0(void)
40、PORTB = PORTB; / PORTB燈取反TMFreescale Semiconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2005.實(shí)驗(yàn)3:內(nèi)容(2) E
41、CT輸入捕捉控制LED燈顯示顯示/以下是在main函數(shù)中,如何使用PORTA_BIT6來產(chǎn)生一個(gè)方波信號(hào)。DDRA=0 xff;/設(shè)置PORTA的方向寄存器,為輸出PORTA=0 x00;/PORTA的輸出初始化為低電平DDRB=0 xff;/PORTB設(shè)置為LED燈的控制信號(hào)PORTB=0 xff;/LED全滅for(;)for(i=0;i6000;i+) PORTA_BIT6=1;/循環(huán)中設(shè)置信號(hào)為高電平 for(i=0;i6000;i+) PORTA_BIT6=0; /循環(huán)中設(shè)置信號(hào)為低電平,產(chǎn)生方波void ic_init(void) /IC0的初始化:TSCR1= 0 x90; /主
42、定時(shí)器使能 TSCR2=0 x07; /分頻因子=128 ICSYS=0 x02;/IC緩沖使能 TIOS=0; /通道設(shè)置為輸入捕獲 TCTL4=0 xff;/采用上升、下降沿觸發(fā) TIE=0 x01; /通道0開中斷/方波信號(hào)已經(jīng)成功得產(chǎn)生了,中斷服務(wù)程序:void interrupt 8 ic0_int(void) TFLG1_C0F=1;/中斷標(biāo)志清除 ic4=TC0;/通過讀TC0寄存器來響應(yīng)中斷,ic4為用戶設(shè)置的變量PORTB=0 x55; /用LED燈來指示已經(jīng)進(jìn)入了中斷實(shí)驗(yàn)要求:利用輸入捕捉0通道,對(duì)外來的信號(hào)進(jìn)行雙沿捕捉,并觸發(fā)中斷,中斷發(fā)生后,讀取捕捉后的計(jì)數(shù)值。方波信號(hào)
43、由PORTA_BIT6產(chǎn)生,PORTA_BIT6和IOC0硬件連接。TMFreescale Semiconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2005. 最
44、簡單最常用的功能就是:產(chǎn)生一定間隔的脈沖, 其非常精確的時(shí)間間隔的電平輸出,比使用延時(shí)要準(zhǔn)確的多。 通過定時(shí)器通道寄存器TC0TC7的預(yù)設(shè)值與自由計(jì)數(shù)器TCNT比較,當(dāng)兩者相等時(shí)觸發(fā)中斷,并按照預(yù)設(shè)的輸出方式輸出電平。定時(shí)器模塊輸出比較定時(shí)器模塊輸出比較TMFreescale Semiconductor Confidential and Proprietary Information. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2005.定時(shí)器模塊輸出比較定時(shí)器模塊輸出比較OMn:輸出模式選擇位; OLn:輸出電平選擇位這8
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 綠色能源技術(shù)研發(fā)合作合同
- 醫(yī)療器械代理注冊(cè)合同書
- 正式借款合同
- 城市綠化項(xiàng)目實(shí)施與驗(yàn)收合同
- 節(jié)電小貼士(教學(xué)設(shè)計(jì))-2023-2024學(xué)年四年級(jí)下冊(cè)綜合實(shí)踐活動(dòng)滬科黔科版
- 第21課《莊子二則-北冥有魚》教學(xué)設(shè)計(jì) 2023-2024學(xué)年統(tǒng)編版語文八年級(jí)下冊(cè)
- 社區(qū)團(tuán)購倉儲(chǔ)租賃協(xié)議
- 第5課計(jì)算機(jī)的資源管理 教學(xué)設(shè)計(jì)
- 律師事務(wù)所勞動(dòng)仲裁合同8篇
- 無產(chǎn)權(quán)房屋買賣合同范本5篇
- 工程結(jié)構(gòu)質(zhì)量特色介紹
- 超全六年級(jí)陰影部分的面積(詳細(xì)答案)
- 提高護(hù)士對(duì)搶救藥品知曉率PDCA案例精編版
- 八字萬能速查表(有圖)
- 清華大學(xué)MBA課程——運(yùn)籌學(xué)
- 架橋機(jī)安全教育培訓(xùn)試卷及答案(共3頁)
- 濕法冶金浸出凈化和沉積PPT課件
- 通信桿路工程施工
- 初中物理光學(xué)經(jīng)典題(共23頁)
- 化學(xué)反應(yīng)工程流固相非催化反應(yīng)PPT課件
- 二次回路和電纜編號(hào)原則
評(píng)論
0/150
提交評(píng)論