微機(jī)原理課程設(shè)計(jì) 電子鐘 匯編語(yǔ)言_第1頁(yè)
微機(jī)原理課程設(shè)計(jì) 電子鐘 匯編語(yǔ)言_第2頁(yè)
微機(jī)原理課程設(shè)計(jì) 電子鐘 匯編語(yǔ)言_第3頁(yè)
微機(jī)原理課程設(shè)計(jì) 電子鐘 匯編語(yǔ)言_第4頁(yè)
微機(jī)原理課程設(shè)計(jì) 電子鐘 匯編語(yǔ)言_第5頁(yè)
已閱讀5頁(yè),還剩7頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、;clock.asm;386以上微機(jī)適用;純dos下才能使用;tasm4.1或以上編譯;*;* clock in 82 55LED *;*;io_plx_device_idio_plx_vendor_idIO_PLX_SUB_ID-8253,8255,LED的端口地址- pa55 equ 218h-200H ;8255端口地址pb55 equ 219h-200Hp55ctl equ 21bh-200HPORTSEG EQU 211H-200HPORTBIT EQU 210H-200HTIM_CTL EQU 203H-200HTIMER0 EQU 200H-200HTIMER1 EQU 201H

2、-200HMODE03 EQU 36HMODE12 EQU 74H-data segmentcsregipreg dw ? dw ? ;舊中斷向量保存空間db 4 DUP(0) ;TPC卡PCI接口芯片I/O基地址暫存空間db 4 DUP(0)db 2 DUP(0) ;TPC卡I/O基地址暫存空間 ;TPC卡中斷號(hào)暫存空間 ;8253端口地址 ;led端口地址 equ 05406h equ 010b5h ;TPC卡設(shè)備ID ;TPC卡廠商ID ;TPC卡子設(shè)備及廠商ID EQU 0905410B5H io_9054base_address io_base_address interrupt_l

3、inepcicardnotfindiobaseaddressintnumberMESS enter_return db 0dh,0ah,'TPC pci card not find or address/interrupt error !',0dh,0ah,'$' db 0dh,0ah,'TPC pci card I/O Base Address : ','$' db 0dh,0ah,'TPC pci card Interrupt Line : ','$' db 0dh,0ah,'$'

4、; io9054baseaddress db 0dh,0ah,'TPC pci card 9054 Chip I/O Base Address : ','$' DB '8253A TIMER0 IN MODE3! COUNT=0200H',0AH,0DHdb 08h,09h,0ah,0bh,0ch,0dh,0eh,0fh,70h,71h,72h,73h,74h,75h,76h,77h ;新的中斷向量,中斷0-7的向量為:08h-0fh,中斷8-15的向量為:70h-77h db 011101111b,011011111b,010111111b,0

5、01111111bdb 011111011b,011111011b,011111011b,011111011bdb 011111011b,011111011b,011111011b,011111011b DB '8253A TIMER1 IN MODE2! COUNT=0aH infact it is better to be 0003h',0AH,0DH,'$' irq_vect irq_mask_0_7_table db 011111110b,011111101b,011111011b,011110111b;新的中斷掩碼,中斷0-7時(shí)從低至高相應(yīng)位為零,中斷

6、8-15時(shí)第2位為零 db 0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh db 011111110b,011111101b,011111011b,011110111b db 011101111b,011011111b,010111111b,001111111b ;新的中斷掩碼,中斷0-7時(shí)全一,中斷8-15時(shí)從低至高相應(yīng)位為零irq_mask_8_15_table ; -與用戶有關(guān)的數(shù)據(jù)寄存區(qū)域-COUNT DB 50 ;jishu50 timesTIME1 DB 00H,00H,00H,00H,00H,00H ; TIMER DATA WAITNG TO B

7、E PRINTEDCHAR1 DB ? ;save the char that u have inputed from the keybordINTMASK DB ?CONST1 DW ?LED DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,40H,79H,00HTABLE1 DW 0101H,0201H,0401H,0801H,1001H,2001H,4001H,8001HDW 0102H,0202H,0402H,0802H,1002H,2002H,4002H,8002HDW 0104H,0204H,0404H,0804H,1004H,2004H,40

8、04H,8004HCHAR DB 'CDEFBA9845673210 RPMG'MES DB '-IN SMALL KEYBORD-',0AH,0DHDB 'C-DISPLAY 00,00,00 ; G-GO ON SHOW THE TIME ',0AH,0DH DB 'D-STOP TO DISPLAY ; E-EXIT TO DOS',0AH,0DH;DB 'P-POSITION THE THE RIGHT TIME',0AH,0DH,'$'DB 'P-POSITION THE THE

9、RIGHT TIME',0AH,0DHDB '-JUST HAVE A TRY-',0AH,0DH,'$'data endsstacks segmentdb 100 dup (?)STA DW 512 DUP (?)TOP EQU LENGTH STAstacks endscode segmentassume cs:code,ds:data,ss:stacks,es:datastart:;Enable Local Interrupt Input.386climov ax,datamov ds,axmov es,axmov ax,stacksmov ss,

10、ax;-主程序開(kāi)始時(shí)的初始化工作-mov dx,word ptr io_9054base_address add dx,68h ;設(shè)置 tpc 卡中9054芯片io口,使能中斷 MOV DX,word ptr io_base_address ;初始化8253 add dx,TIM_CTL MOV AL,MODE03 ;計(jì)數(shù)器0工作在模式三 00 11 011 0; OUT DX,AL MOV DX,word ptr io_base_address add dx,TIMER0 MOV AL,00h OUT DX,AL OUT DX,AL MOV DX,word ptr io_base_addre

11、ss add dx,TIM_CTL MOV AL,MODE12 OUT DX,AL MOV DX,word ptr io_base_address add dx,TIMER1 OUT DX,AL OUT DX,AL MOV DX,OFFSET MES MOV AH,09 INT 21H call findtpc ;查找TPC卡資源并顯示 MOV AL,02H MOV AL,03H ;本來(lái)是000ah 但程序中有很多延時(shí)。 MOV AL,00h in ax,dxor ax,0900hout dx,axmov bx,word ptr interrupt_linemov al,byte ptr ir

12、q_vect+bx mov ah,35h mov ax,es mov csreg,ax ;保存原中斷向量 int 21hmov ipreg,bx;設(shè)置新中斷向量 mov bx,word ptr interrupt_linemov al,byte ptr irq_vect+bxmov cx,csmov ds,cxmov ax,data mov ds,ax mov es,ax mov dx,offset int_proc mov ah,25h int 21hin al, 21h ;設(shè)置中斷掩碼 mov bx,word ptr interrupt_linemov ah,byte ptr irq_ma

13、sk_0_7_table+bx and al,ahout 21h, alin al, 0a1hmov bx,word ptr interrupt_lineLKEY: CALL KEYMOV DL,CHAR1CMP DL,'C'JNZ LGYCALL CPROJMP LKEYLGY: CMP DL,'G'JNZ LDYCALL GPROJMP LKEYLDY: CMP DL,'D'JNZ LPYCALL DPROJMP LKEYLPY: CMP DL,'P'JNZ LEYCALL PPROJMP LKEY sti ;開(kāi)中斷 mov

14、ah,byte ptr irq_mask_8_15_table+bx and al,ah out 0a1h, alLEY: CMP DL,'E'JNZ LKEYexit: climov bx,word ptr interrupt_linemov bx,word ptr interrupt_linemov ax,4c00h int 21h ;退出 mov ax,data ;設(shè)置 tpc 卡中9054芯片io口,關(guān)閉中斷 mov ds,ax mov dx,word ptr io_9054base_address add dx,68h in ax,dx out dx,ax mov a

15、l,byte ptr irq_vect+bx mov cx,csreg mov ds,cx mov ah,25h mov dx,ipreg ;恢復(fù)原中斷向量 not ah in or al, 21h al, ah ;恢復(fù)中斷掩碼 mov ah,byte ptr irq_mask_0_7_table+bx out 21h, al mov ah,byte ptr irq_mask_8_15_table+bx not ah in or al, 0a1h al, ah mov bx,word ptr interrupt_line out 0a1h, al int 21h and ax,0f7ffh;-

16、中斷服務(wù)程序;每秒鐘將會(huì)進(jìn)入50次- int_proc proc farclipush axPUSH BX PUSH CX PUSH SI PUSH DI push dxpush dsmov ax,data ;Interrupt to domov ds,axDEC COUNTJNZ DDD ; SMALLER THAN 50 JUMP TO NEXT GENERATION MOV COUNT,50 ;NEW INTRRUPT IS BEGINDDD:mov al,20h ;Send EOIout 0a0h,alout 20h,almov cx,0ffffhloopx:noploop loopx

17、 ;延時(shí) MOV DI,OFFSET TIME1 CMP BYTE PTR DI+5,09H JE DDD1 ;先進(jìn)性比較 如果是9則跳到ddd1產(chǎn)生進(jìn)位 否則加一 INC BYTE PTR DI+5 ;50 TIMES TO MAKE AN INC OF second high JMP DDD INC BYTE PTR DI+4 ; 產(chǎn)生進(jìn)位: CMP DI+4,06H JNZ DDD mov byte ptr DI+4,00H INC BYTE PTR DI+3 ; 產(chǎn)生進(jìn)位: CMP DI+3,0AH JNZ DDD mov byte ptr DI+3,00H INC BYTE PTR

18、DI+2 ; 產(chǎn)生進(jìn)位: CMP DI+2,06h JNZ DDD mov byte ptr DI+2,00H INC BYTE PTR DI+1 ; 產(chǎn)生進(jìn)位: CMP DI+1,04h JNZ DDD mov byte ptr DI+1,00H INC BYTE PTR DI ; 產(chǎn)生進(jìn)位: CMP DI,03h JNZ DDD mov byte ptr DI,00H DDD1: mov byte ptr DI+5,00Hpop dsPOP DI POP SI POP CX POP BX pop dxpop axstiiretint_proc endp;-鍵盤(pán)掃描的程序 主程序中被調(diào)用-

19、KEY PROC NEARPUSH CXKST: MOV AL,82HMOV DX,word ptr io_base_address add dx,P55CTLOUT DX,ALMOV AL,00HMOV DX,word ptr io_base_address add dx,PA55 MOV DX,word ptr io_base_address add dx,PB55 OUT DX,ALIN AL,DXOR AL,0F8HCMP AL,0FFHJZ DELAYPUSH AXMOV CX,0a00HDLY: MOV AX,word ptr CONST1DLY1: DEC AXJNZ DLY1D

20、EC CXJNZ DLYPOP AXMOV CL,08HMOV AH,0FEHSCAN1:MOV DX,word ptr io_base_address add dx,PA55MOV AL,AHOUT DX,ALMOV DX,word ptr io_base_addressadd dx,PB55IN AL,DXOR AL,0F8HCMP AL,0FFHJNZ KEYNROL AH,1DEC CLJNZ SCAN1JMP KSTKEYN: PUSH AXMOV DX,word ptr io_base_address add dx,PB55RELEA: IN AL,DXOR AL,0F8HCMP

21、AL,0FFHJNZ RELEAPOP AXNOT AXMOV SI,OFFSET TABLE1MOV DI,OFFSET CHARMOV CX,24TT: CMP AX,SIJZ NNDEC CXJZ KSTADD SI,02INC DIJMP TTNN: MOV DL,DIMOV CHAR1,DLMOV AH,02HINT 21HPOP CXJMP YANGDELAY: CALL DISPLYJMP KSTYANG: RETKEY ENDP;-LED數(shù)碼管顯示- DISPLY PROC NEARPUSH CXMOV BX,OFFSET LEDMOV CX,0006 ;STANDS FOR

22、6 LEDSMOV SI,OFFSET TIME1MOV AH,01HDISPLY1: CLD ;LED DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,40H,79H,00HLODSB ;AL=BX+ALXLAT ;AL=MOV DX,word ptr io_base_address add dx,PORTSEGOUT DX,ALMOV AL,AHMOV DX,word ptr io_base_address add dx,PORTBITOUT DX,ALSHL AH,1 ;ZUOYIMOV AL,00 ;EVERY TIME WE INISIAT IT

23、 WITH 00 WHEN FINISHEDOUT DX,ALLOOP DISPLY1POP CXRETDISPLY ENDP;-按下各種鍵盤(pán)時(shí)相應(yīng)的操作-CPRO PROC NEARCLIMOV WORD PTR WORD PTR TIME1,0000H ;PRINT LED 00:00:00MOV WORD PTR TIME1+2,0000HMOV WORD PTR TIME1+4,0000HRETCPRO ENDP;-GPRO PROC NEAR ;START THE CLOCK;STIRETGPRO ENDP;-DPRO PROC NEAR ;STOP TO DISPLAYCLIRET

24、DPRO ENDP;-PPRO PROC NEARCLIPUSH AXPUSH BXMOV WORD PTR TIME1,0C0CH ;led offMOV WORD PTR TIME1+2,0C0CHMOV WORD PTR TIME1+4,0C0CHCALL DISPLYCALL KEYMOV DL,CHAR1CMP DL,'2'JNG NEXT1 ;SMALLER THAN 9 hh<=2JMP ERR1NEXT1: SUB DL,30H;MOV YEAR1,DLMOV TIME1,DLCALL DISPLYCALL KEYMOV DL,CHAR1CMP DL,&#

25、39;3'JNG NEXT2 ;not greater than to ->exit2 SMALLER THAN 9 hh<=4JMP ERR1NEXT2: SUB DL,30H;MOV YEAR1+1,DLMOV TIME1+1,DLCALL DISPLYCALL KEYMOV DL,CHAR1CMP DL,'6'JNG NEXT3 ; SMALLER THAN 9 mh<=6JMP ERR1NEXT3: SUB DL,30HMOV TIME1+2,DLCALL DISPLYCALL KEYMOV DL,CHAR1CMP DL,'9'

26、JNG NEXT4 ; SMALLER THAN 9 ml<=9JMP ERR1NEXT4: SUB DL,30Hmov TIME1+3,DLCALL DISPLYCALL KEYMOV DL,CHAR1CMP DL,'6'JNG NEXT5 ; SMALLER THAN 9 ml<=9 SH<=5JMP ERR1NEXT5: SUB DL,30HMOV TIME1+4,DLCALL DISPLYCALL KEYMOV DL,CHAR1CMP DL,'9'JG ERR1SUB DL,30HMOV TIME1+5,DLCALL DISPLYJMP

27、 WWERR1:MOV WORD PTR TIME1,0A0BH MOV WORD PTR TIME1+2,0A0AH MOV WORD PTR TIME1+4,0A0AHCALL DISPLYWW: POP BXPOP AXRETPPRO ENDP;-tpc card-findtpc proc nearMOV AX,0B102H MOV CX,io_plx_device_id MOV DX,io_plx_vendor_id MOV SI,0 INT 1AH pushad pushfd MOV AX,0B101H INT 1AH JC findtpc_notfind ;檢查PCI BIOS是否

28、存在 ;查找TPC卡資源并顯示JC findtpc_notfind ;檢查T(mén)PC卡是否安裝,設(shè)備號(hào)、廠商號(hào) MOV AX,0B10AH MOV DI,02CH INT 1AH JC findtpc_notfind ;檢查T(mén)PC卡是否安裝,子設(shè)備號(hào)、廠商號(hào) CMP ECX,IO_PLX_SUB_ID JNZ findtpc_notfind MOV AX,0B10AH MOV DI,14H INT 1AH JC findtpc_notfind ;讀TPC卡9054芯片I/O基址信息 mov dword ptr io_9054base_address,ecx and ecx,1 jz findtpc

29、_notfind ;檢查是否為i/o基址信息 mov ecx,dword ptr io_9054base_address and ecx,0fffffffeh mov dword ptr io_9054base_address,ecx ;去除i/o指示位并保存 MOV AX,0B10AH MOV DI,18H INT 1AH JC findtpc_notfind ;讀TPC卡I/O基址信息 mov dword ptr io_base_address,ecx and ecx,1 jz findtpc_notfind ;檢查是否為i/o基址信息 mov ecx,dword ptr io_base_address and ecx,0fffffffeh mov dword ptr io_base_address,ecx ;去除i/o指示位并保存 MOV AX,0B10AH MOV DI,3CH INT 1AH JC findtpc_notfind ;讀TPC卡中斷信息 and cx,0ffh mov word ptr interrupt_line,cx ;去除interrupt

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論