解:T1方式0作計數器,計數預裝值X = 2^13 - 1000 =7192D =1C18HTH1←1CH, TL1←18H 機器週期 T = 12/Fosc = 12/(6x10^6) = 2x10^-6s =2μ s10ms週期對應的計數滿值 = 10000μ s/2μ s = 5000T1方式0作10ms定時器,計數初值 = 2^13 -5000 =3192D = 0C78HTH1←0CH, TL1←78H ORG 0000H AJMP MAIN ORG 0100H MAIN: MOV SP, #60H ;;堆疊指標初值LP0: MOV TMOD, #40H ;;T1方式0作計數器 MOV TH1, #1CH ;;T1計數預裝值高8位 MOV TL1, #18H ;;T1計數預裝值低8位 SETB TR1 ;;啟動T1計數LP1: JBC TF1, DLAY ;;若T計數溢位,轉DLAY延時10ms SJMP LP1 ;;若T1計數未溢位,繼續查詢DLAY: CLR TR1 ;;關閉T1 MOV TMOD, #00H ;;T1改作方式0作定時器 MOV TH1, #0CH ;;T1定時計數預裝值高8位 MOV TL1, #78H ;;T1定時計數預裝值低8位 SETB TR1 ;;啟動T1計數延時LP2: JBC TF1, LP3 ;;若T1計數延時至10ms,轉LP3 SJMP LP2 ;;若T1計數延時未達10ms,繼續查詢LP3: CLR TR1 ;;關閉T1 AJMP LP0 ;;轉LP0,使T1重新作定時器 END
解:T1方式0作計數器,計數預裝值X = 2^13 - 1000 =7192D =1C18HTH1←1CH, TL1←18H 機器週期 T = 12/Fosc = 12/(6x10^6) = 2x10^-6s =2μ s10ms週期對應的計數滿值 = 10000μ s/2μ s = 5000T1方式0作10ms定時器,計數初值 = 2^13 -5000 =3192D = 0C78HTH1←0CH, TL1←78H ORG 0000H AJMP MAIN ORG 0100H MAIN: MOV SP, #60H ;;堆疊指標初值LP0: MOV TMOD, #40H ;;T1方式0作計數器 MOV TH1, #1CH ;;T1計數預裝值高8位 MOV TL1, #18H ;;T1計數預裝值低8位 SETB TR1 ;;啟動T1計數LP1: JBC TF1, DLAY ;;若T計數溢位,轉DLAY延時10ms SJMP LP1 ;;若T1計數未溢位,繼續查詢DLAY: CLR TR1 ;;關閉T1 MOV TMOD, #00H ;;T1改作方式0作定時器 MOV TH1, #0CH ;;T1定時計數預裝值高8位 MOV TL1, #78H ;;T1定時計數預裝值低8位 SETB TR1 ;;啟動T1計數延時LP2: JBC TF1, LP3 ;;若T1計數延時至10ms,轉LP3 SJMP LP2 ;;若T1計數延時未達10ms,繼續查詢LP3: CLR TR1 ;;關閉T1 AJMP LP0 ;;轉LP0,使T1重新作定時器 END