SKhởi tạo giây =

Một phần của tài liệu vi dieu khien (Trang 30 - 34)

IV. Bài tập mẫu:

SKhởi tạo giây =

Khởi tạo giây =00

Giây = 60 Tăng giây lên 1 đơn vị

end Begin

2. Kết nối mạch theo trình tự :

- Dùng bus dây kết nối port 0 đến pinhd điều khiển các đoạn a,b,c,d,e,f,g,dp và kết nối port 2 đến pinhd điều khiển quét hàng.

- Gắn vi điều khiển vào đế nạp 40 pin ( socket ) ở modul nạp của hệ thống 2.

3. Khởi động phần mềm, mở File mới và đặt tên file. 4. Viết chương trình với tên file vừa đặt:

;

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx

;chuong trinh dem len tu 00 den 60 hien thi tren 2 led cua 8 led quet ;

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx

giay equ r2 ;gan bien dem giay la R2

org 200h ;dia chi khai bao ma 7 doan tu so '0' den so '9' ma7doan: db 0C0h,0F9h,0A4h,0B0h,99h,92h,82h,0F8h,80h,90h

org 0000h ;bat dau chuong trinh mov tmod,#01h ;timer0: mod 1 - dem 16 bit mov dptr,#0200h ;dptr quan ly vung ma 7 doan main: mov giay,#00h ;giay=00

main1: lcall gma

lcall delay_hthi ;goi chtr con delay co hien thi mov a,giay ;chuyen giay sang A

add a,#1 ;tang giay len 1

da a ;hieu chinh so BCD trong A mov giay,a ;tra lai cho giay

cjne giay,#60h,main1 ;ss giay voi 60 sjmp main ;lam lai tu dau ;

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx

; chuong trinh con giai ma ;

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx

anl a,#0fh ;xoa 4 bit cao hang chuc giay movc a,@a+dptr ;lay ma 7 doan

mov 27h,a ;cat ma vao o nho 20h mov a,giay

anl a,#0f0h ;xoa 4 bit thap hang dvi

swap a ;chuyen 4 bit cao xuong vi tri thap movc a,@a+dptr ;lay ma 7 doan hang chuc

mov 26h,a ret

;

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx

;chuong trinh delay co goi chuong trinh hien thi ; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx delay_hthi: mov 7fh,#10h del2: clr tr0 mov th0,#00 mov tl0,#00 setb tr0 clr tf0 del1: lcall hthi

jnb tf0,del1 djnz 7fh,del2 ret ; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx (adsbygoogle = window.adsbygoogle || []).push({});

;

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx

hthi: mov a,#01111111b ;ma quet mov r0,#27h ht1: mov p0,@r0 mov p2,a lcall delay1 mov p2,#0ffh dec r0

rr a ;chuyen sang led ke cjne r0,#25h,ht1

ret

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh con delay1

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx delay1: mov r7,#0fh

del11: djnz r7,del11 ret

end

5. Thực hiện các bước giống như các bài chuẩn cho đến khi mạch đếm đúng từ 00 đến 59.

Một phần của tài liệu vi dieu khien (Trang 30 - 34)