新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 實驗九 定時、記數(shù)、顯示(80C51單片機(jī)匯編語言編程)

實驗九 定時、記數(shù)、顯示(80C51單片機(jī)匯編語言編程)

作者: 時間:2016-11-23 來源:網(wǎng)絡(luò) 收藏
設(shè)計一個帶有控制功能的脈沖發(fā)生器/計數(shù)器系統(tǒng),脈沖發(fā)生器發(fā)出周期為2秒的方波(提示:可由P3.0口輸出,用發(fā)光二極管顯示);被計數(shù)脈沖由T0口輸入,所記錄的脈沖數(shù)以十進(jìn)制形式在數(shù)碼管顯示(至少應(yīng)可記錄256個脈沖);設(shè)兩個按鍵,一個啟動脈沖發(fā)生器,一個啟動記數(shù),(按一次啟動,再按一次停止),不啟動時,發(fā)光管滅,數(shù)碼管顯示學(xué)號。
偉福:數(shù)碼管為共陰極;
KEY/LED_CS與CS0連線,則段地址為:8004H,位地址為:8002H
ORG 0000H
AJMP MAIN
ORG 0003H
AJMP INT0
ORG 0013H
AJMP INT1
ORG 001BH
AJMP T1

ORG 0030H
MAIN:MOV TMOD,#16H ;T0計數(shù),T1計時
MOV TH0,#00H
MOV TL0,#00H
MOV TH1,#0EFH
MOV TL1,#0CH
SETB EA
SETB EX0
SETB EX1
SETB ET0
SETB ET1
SETB IT0
SETB IT1
CLR TR0
SETB TR1
;SETB PX0
CLR P3.1
MOV R7,#100
SJMP $

ORG 0100H
INT0:JB P3.1,AA ;脈沖開關(guān)
MOV TH1,#0EFH
MOV TL1,#0CH
MOV R7,#100
SETB P3.1 ;用3.1口作為判斷標(biāo)志
;SETB TR1
RETI
AA:CLR P3.1
RETI

ORG 0150H
INT1:JB TR0,BB ;計數(shù)開關(guān)
MOV TH0,#00H ;開始計數(shù)
MOV TL0,#00H
MOV TH1,#0EFH
MOV TL1,#0CH
SETB TR0
RETI

BB:CLR TR0 ;關(guān)閉計數(shù)器顯示學(xué)號
MOV TH0,#00H
MOV TL0,#00H

T1:MOV TH1,#0EFH
MOV TL1,#0CH

JX:JNB TR0,XH1
DY:ACALL H_BCD
ACALL JISHU
ACALL DISP

DJNZ R7,GORET1
MOV R7,#100
JNB P3.1,DY
CPL P3.0 ;用3.0作為脈沖發(fā)生器
GORET1:RETI

H_BCD:MOV A,TL0
MOV B,#100
DIV AB
MOV 32H,A
MOV A,#10
XCH A,B
DIV AB
MOV 31H,A
MOV 30H,B
RET

JISHU:MOV R2,#3 ;R2計數(shù),讓后三個數(shù)碼管都顯示
MOV R0,#30H
FT:MOV A,@R0 ;將所計數(shù)轉(zhuǎn)換成數(shù)碼管顯示形式
MOV DPTR,#TAB
MOVC A,@A+DPTR
MOV @R0,A
INC R0
DJNZ R2,FT
RET

DISP:MOV DPTR,#8002H
MOV A,#01H
MOVX @DPTR,A
MOV DPTR,#8004H
MOV A,30H
MOVX @DPTR,A
ACALL DLAY
MOV DPTR,#8002H
MOV A,#02H
MOVX @DPTR,A
MOV DPTR,#8004H
MOV A,31H
MOVX @DPTR,A
ACALL DLAY
MOV DPTR,#8002H
MOV A,#04H
MOVX @DPTR,A
MOV DPTR,#8004H
MOV A,32H
MOVX @DPTR,A
ACALL DLAY
RET

XH1:MOV DPTR,#8002H
MOV A,#01H
MOVX @DPTR,A
MOV DPTR,#8004H
MOV A,#06H
MOVX @DPTR,A
ACALL DLAY

XH2:MOV DPTR,#8002H
MOV A,#02H
MOVX @DPTR,A
MOV DPTR,#8004H
MOV A,#66H
MOVX @DPTR,A
ACALL DLAY

XH3:MOV DPTR,#8002H
MOV A,#04H
MOVX @DPTR,A
MOV DPTR,#8004H
MOV A,#5BH
MOVX @DPTR,A
ACALL DLAY

XH4:MOV DPTR,#8002H
MOV A,#08H
MOVX @DPTR,A
MOV DPTR,#8004H
MOV A,#5BH
MOVX @DPTR,A
ACALL DLAY

XH5:MOV DPTR,#8002H
MOV A,#10H
MOVX @DPTR,A
MOV DPTR,#8004H
MOV A,#6FH
MOVX @DPTR,A
ACALL DLAY

XH6:MOV DPTR,#8002H
MOV A,#20H
MOVX @DPTR,A
MOV DPTR,#8004H
MOV A,#3FH
MOVX @DPTR,A
ACALL DLAY

DJNZ R7,GORET2
MOV R7,#100
JNB P3.1,XH1
CPL P3.0 ;用3.0作為脈沖發(fā)生器
GORET2:RETI

RETI

DLAY:MOV R6,#1000;延時子程序
DJNZ R6,$
RET

TAB:DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH


評論


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

關(guān)閉