1 / 6

基本程式範例

基本程式範例. 延遲程式 f osc =12MHz. * * 延遲時間的計算** 時間的單位為 機械週期 (Tm) 外接的震盪頻率決定一個機械週期的時間 假設 fosc=12MHz Tm= 12 *(1/fosc) =12/12M=1 u S 8051 執行指令所需的時間 Ti, 可由查表得知 (M 個 機械週期 ) Ti=M*Tm. MOV R0, #05 CALL DELAY DELAY : MOV R1, #200 ;

harmon
Download Presentation

基本程式範例

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. 基本程式範例

  2. 延遲程式 fosc=12MHz **延遲時間的計算** • 時間的單位為機械週期(Tm) • 外接的震盪頻率決定一個機械週期的時間 • 假設 fosc=12MHz Tm= 12 *(1/fosc) =12/12M=1uS • 8051執行指令所需的時間Ti,可由查表得知(M個 機械週期) Ti=M*Tm

  3. MOV R0, #05 CALL DELAY DELAY: MOV R1, #200; D2:MOV R2, #200; (T) D1:DJNZ R2, D1; (T1) DJNZ R1, D2; (T2) DJNZ R0, DELAY (T) RET • 由指令表得知:MOV Rn, #direct需 1個機械週期 • DJNZ Rn, rel需2個機械週期 • 選用外接震盪頻率為12 MHZ所以1個機械週期為1uS; • 延遲時間為: T1=200×1uS=200uS ;T2=(1+T1+2)×200×1uS=40.6mS ;T=(1+T2+2)×5×1 uS=203.015 ms ; • 因R0=5DEALY TIME=5*203.015mS=1sec備註:若使用16進位MSB為A~F記得在前面加0,LSB後若沒有加H組譯器將視為10進位。

  4. 查表法 MOV DPTR, #HI_LIST MOVC A, @A+DPTR MOV HI, A MOV DPTR, #LO_LIST MOVC A, @A+DPTR MOV LO, A ... HI_LIST: DB 0,226,229,232,233,236,238,240 DB 241,242,244,244,246,247,248 LO_LIST: DB 0,4,13,10,20,3,8,6 DB 2,23,5,26,1,4,3

  5. 中斷 ;主程式開始 ORG PROG+0030h START: MOV A, #0FEH ;將FEH寫入累加器 LOOP: MOV P1, A ;將FEH送到port1 點量1個led RR A ;累加器值右旋 MOV R0, #05H ;設定延遲 ACALL DELAY ;呼叫延遲副程式 AJMP LOOP ;回到LOOP無窮迴圈 ;副程式開始DELAY DELAY: MOV R1, #200 ;時間延遲 203.015 ms D2: MOV  R2, #200 D1: DJNZ    R2, D1 DJNZ    R1, D2 DJNZ    R0, DELAY RET PROG EQU0000h ORG PROG+0000h JMP START ;中斷向量表 ORG PROG+0003h LCALL INT0_ISR RETI ORG PROG+000Bh LCALL T0_ISRRETI ORG PROG+0013h LCALL INT1_ISR RETI ORG PROG+001Bh LCALLT1_ISR RETI ORG PROG+0023h LCALLUART_ISR RETI

  6. 中斷服務副程式 ;中斷服務副程式 INT0_ISR: … RETI T0_ISR: … RETI INT1_ISR: … RETI T1_ISR: … RETI UART_ISR: … RETI END

More Related