1 / 15

4.10 Timer/Event

4.10 Timer/Event. 利用 Timer/Event Counter 之中斷 及 PFD 控制喇叭 4.9 之 Timer 以 Poling 詢問方式檢查 TF 旗標 是否溢位. 外部中斷 計時 / 計數中斷 AD 轉換中斷 I2C Bus 中斷. INTC0 暫存器. - ADF TF EIF EADI ETI EEI EMI Bit 7 6 5 4 3 2 1 0 Bit 7 未使用 Bit 6 ADF

liuz
Download Presentation

4.10 Timer/Event

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 4.10 Timer/Event

  2. 利用Timer/Event Counter 之中斷 及PFD 控制喇叭 • 4.9之Timer以Poling詢問方式檢查TF旗標 是否溢位

  3. 外部中斷 • 計時/計數中斷 • AD 轉換中斷 • I2C Bus 中斷

  4. INTC0暫存器 - ADF TF EIF EADI ETI EEI EMI Bit 7 6 5 4 3 2 1 0 • Bit 7 未使用 • Bit 6 ADF 1 AD 轉換完成設定此位元告知CPU 0無 AD 轉換完成之中斷要求

  5. Bit 5 TF 1 計時/計數已溢位 0無計時/計數已溢位之中斷要求 • Bit 4 EIF 計數/計時控制位元 1有外部中斷產生 0 無外部中斷產生 • Bit 3 EADI 計數/計時準位控制位元 1致能AD轉換器轉換完成之中斷 0 禁能AD轉換器之中斷

  6. Bit 2 ETI TMR中斷控制位元 1致能計時/計數溢位之中斷 0 禁能計時/計數溢位之中斷 • Bit 1 EEI 外部中斷控制位元 1致能計時/計數溢位之中斷 0 禁能計時/計數溢位之中斷 • Bit 0 EMI 整體中斷控制位元 1致能 0 禁能所有中斷

  7. EMI為中斷控制樞紐 • EMI=0 不接受中斷 • EMI=1 視EHI EADI ETI EEI 而決定

  8. 要產生F Hz方波:需計數時間 T=1/2F • 換成計數脈波=T/((1/fsys) x 計數倍率) • 化簡後= fsys / (F x 2 x 計數倍率) • TMRH, TMRL 之起始值 65536-(fsys / (F x 2 x 計數倍率))

  9. 65280≦{65536-(fsys / (F x 2 x 計數倍率))} ≦ 65535 • TMRH=FFH • 選用預除比率1:16 256-(fsys / (F x 2 x 16))

  10. ;PROGRAM : 4-10.ASM ;FUNCTION: GENERATE TONE DO~DO. BY TMR INTERRUPT SKILL ;NOTE : USING TMR AS A 8-BIT TIMER #INCLUDE HT46R23.INC .CHIP HT46R23 ;------------------------------------------------------------ MY_DATA .SECTION 'DATA' ;== DATA SECTION == DEL1 DB ? ;DELAY LOOP COUNT 1 DEL2 DB ? ;DELAY LOOP COUNT 2 DEL3 DB ? ;DELAY LOOP COUNT 3 COUNT DB ? ;PITCH COUNT STACK_A DB ? ;STACK BUFFER FOR ACC STACK_PSW DB ? ;STACK BUFFER FPR PSW

  11. ;--------------------------------------------------------------------;-------------------------------------------------------------------- OSC EQU 4000000 ;fSYS=4 MHz ;-------------------------------------------------------------------- SPK_PORT EQU PA ;DEFINE SPEAKER PORT SPK_PORTC EQU PAC.0 ;DEFINE SPEAKER PORT CON. REG. MY_CODE .SECTION AT 0 'CODE' ;== PROGRAM SECTION == ORG 00H ;HT-46RXX RESET VECTOR JMP START_ ORG 08H ;HT-46RXX TMR INTERRUPT VECTOR JMP TMR_INT START_: CLR SPK_PORTC ;CONFIG SPK_PORT AS OUTPUT MODE MOV A,00000101B ;ENABLE GLOBAL AND TMR INTERRUPT MOV INTC0,A MOV A,10000100B ;CONFIG TMR 0 IN MODE 2(TIMER MODE) MOV TMRC,A ;fINT=fSYS/16(4MHz/16).

  12. MAIN: MOV A,TAB_PITCH MOV TBLP,A ;INITIAL TABLE POINTER MOV A,15 MOV COUNT,A ;SET COUNTER FOR PITCH TABLE NEXT_PITCH: TABRDL TMRL ;LOAD PITCH TO TMR PE-LOAD REGISTER MOV A,0FFH MOV TMRH,A ;PRELOAD TMRH=FFH FOR 8-BIT TMR SET TON ;START TMR COUNTING MOV A,40 ;DELAY 0.4 SEC FOR EACH TONE MOV DEL1,A CALL DELAY CLR TON ;STOP TMR COUNTING INC TBLP ;UPDATE TABLE POINTER SDZ COUNT ;WERE ALL PITCH PLAYED? JMP NEXT_PITCH ;NO, NEXT PITCH JMP MAIN

  13. ;********************************************************************;******************************************************************** ; TIMER INTERRUPT SERVICE ROUTINE ;******************************************************************** TMR_INT : MOV STACK_A,A ;PUSH A MOV A,STATUS MOV STACK_PSW,A ;PUSH STATUS MOV A,00000001B XORM A,SPK_PORT ;COMPLEMENT PA.0 MOV A,STACK_PSW MOV STATUS,A ;POP STATUS MOV A,STACK_A ;POP A RETI

  14. ;********************************************************************;******************************************************************** ; Delay about DEL1*10mS ;******************************************************************** DELAY PROC MOV A,30 MOV DEL2,A ;SET DEL2 COUNTER DEL_2: MOV A,110 MOV DEL3,A ;SET DEL3 COUNTER DEL_3: SDZ DEL3 ;DEL3 DOWN COUNT JMP DEL_3 SDZ DEL2 ;DEL2 DOWN COUNT JMP DEL_2 SDZ DEL1 ;DEL1 DOWN COUNT JMP DELAY RET DELAY ENDP ORG LASTPAGE

  15. TAB_PITCH: ;PITCH CONSTANT FOR fINT=fSYS/16 DC 256-OSC/(523*2*16) ;DO TONE TIME CONSTANT (LO-BYTE) DC 256-OSC/(587*2*16) ;RE TONE TIME CONSTANT (LO-BYTE) DC 256-OSC/(659*2*16) ;MI TONE TIME CONSTANT (LO-BYTE) DC 256-OSC/(698*2*16) ;FA TONE TIME CONSTANT (LO-BYTE) DC 256-OSC/(785*2*16) ;SO TONE TIME CONSTANT (LO-BYTE) DC 256-OSC/(880*2*16) ;LA TONE TIME CONSTANT (LO-BYTE) DC 256-OSC/(998*2*16) ;TI TONE TIME CONSTANT (LO-BYTE) DC 256-OSC/(523*2*16*2) ;DO. TONE TIME CONSTANT (LO-BYTE) DC 256-OSC/(587*2*16*2) ;RE. TONE TIME CONSTANT (LO-BYTE) DC 256-OSC/(659*2*16*2) ;ME. TONE TIME CONSTANT (LO-BYTE) DC 256-OSC/(698*2*16*2) ;FA. TONE TIME CONSTANT (LO-BYTE) DC 256-OSC/(785*2*16*2) ;SO. TONE TIME CONSTANT (LO-BYTE) DC 256-OSC/(880*2*16*2) ;LA. TONE TIME CONSTANT (LO-BYTE) DC 256-OSC/(998*2*16*2) ;TI. TONE TIME CONSTANT (LO-BYTE) DC 256-OSC/(523*2*16*4) ;DO. TONE TIME CONSTANT (LO-BYTE) END

More Related