1. Trang chủ
  2. » Luận Văn - Báo Cáo

ĐỒNG HỒ SỐ HIỆN THỊ TRÊN LCD BÁO GIỜ BẰNG CHUÔNG VI XỬ LÝ 1

8 585 1

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 8
Dung lượng 64,5 KB

Nội dung

cjne a,#0ffh,ghidata11 mov a,#59 jmp ghidata11 ss56: mov r0,#0h movx a,@r0 dec a cjne a,#0ffh,ghidata11 mov a,#59 jmp ghidata11 ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Trang 1

; DONG HO SO HIEN THI TREN LCD BAO GIO BANG CHUONG

;**********************************************************************

rs bit p3.2 ; chon thanh ghi cua LCD

rw bit p3.1 ; dieu khien doc hoac ghi cua LCD

enb bit p3.0 ; cho phep doc ghi cua LCD

mode bit p2.0 ; chon che do chinh gio

up bit p2.1 ; chinh theo chieu tang

dwn bit p2.2 ; chinh theo chieu giam

bmode equ r5 ; bien mode de chon che do chinh

buzzer bit p2.4

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

org 000h jmp main org 00bh jmp ngat_t0 ;nhay toi chuong trinh ngat timer0 main: lcall khoitao_lcd ;goi chuong trinh khoi tao LCD

lcall khoitaodalass ;goi chuong trinh khoi tao Dallas mov tmod,#01 ;timer0 : mod 1- dem 16bit mov th0,#3ch ;khoi tao timer delay 50ms mov tl0,#0b0h

clr tf0 ;xoa co tran time0

mov ie,#82h ;cho phep ngat timer0 mov bmode,#0 ;dat bien chon dieu chinh =0 setb buzzer ;tat chuong

mov r2,#0 ;nap 0 vao r2 tu_dau: lcall doc_gpg ;goi chuong trinh doc gio-phut-giay tu dallas

lcall hex_bcd ;giai ma gpg sang bcd lcall giaima_lcd ;giai ma tu bcd sang ma lcd lcall hien_thi_lcd ;goi hien_thi_lcd

jnb mode,adj ;nhay den adj neu MODE = 0 cjne r2,#0,tu_dau ;so sanh neu r2 = 0 nhay toi tu_dau

cjne a,#0,tu_dau ;neu ≠ 0 thi nhay lai tu_dau

cjne a,#0,tu_dau ; neu ≠ 0 thi nhay lai tu_dau

mov r3,#10 ;nap 10 vao r3 setb tr0 ;cho phep timer0 hoat dong mov a,14h ;chuyen gio vao a

cjne a,#0,khac24 ;so sang xem co = 0, neu ≠ nhay toi khac24 mov a,#48 ;nap 48 vao a

mov r2,a ;nap a vao thanh ghi a jmp tu_dau ;nhay toi tu_dau

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Trang 2

inc bmode ;tang bmode len 1 don vi cjne bmode,#08,lb1 ;so sanh neu bmode = 8 thi nhay toi lb1 mov bmode,#0 ;nhan du 8 lan thi tra ve 0

ljmp tu_dau ;nhay lai tu_dau

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

lb3: mov 66h,#0ffh ;nap 0ffh vao 66h

lb2: lcall doc_gpg ;goi ctrinh doc_ gpg

lcall hex_bcd ;goi ctrinh hex_bcd lcall giaima_lcd ;goi ctrinh giaima_lcd lcall hien_thi_lcd ;goi ctrinh hien_thi_lcd jnb up,tang_lcd ;nhay toi tang_lcd neu UP = 0 jnb dwn,giam_lcd11 ; nhay toi giam_lcd neu DWN = 0 jnb mode,adj ;kien tra MODE

djnz 66h,lb2 ;nhay neu 66h = 0 mov 66h,#0ffh ;dat lai 0ffh vao 66h cjne bmode,#1,tat_ngay ;so sanh neu =1thi nhay toi tat_ngay mov 3bh,#' ' ;thu nhap nhay

sjmp tat_lcd ;nhay toi tat_lcd tat_ngay: cjne bmode,#2,tat_thang ;so sanh neu = 2 thi nhay toi tat_thang

mov 39h,#' ' ;ngay nhap nhay mov 38h,#' '

sjmp tat_lcd tat_thang: cjne bmode,#3,tat_nam

mov 36h,#' ' jmp tat_lcd tat_nam: cjne bmode,#4,tat_gio

mov 31h,#' ' jmp tat_lcd tat_gio: cjne bmode,#5,tat_phut

mov 58h,#' ' jmp tat_lcd tat_phut: cjne bmode,#6,tat_giay

mov 55h,#' ' jmp tat_lcd tat_giay: mov 53h,#' ' ;giay

mov 52h,#' ' tat_lcd: lcall hien_thi_lcd

jnb up,tang_lcd jnb dwn,giam_lcd jnb mode,adj1 djnz 66h,tat_lcd djnz 67h,lb3 mov bmode,#0 ;dat lai bmode ljmp tu_dau

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Trang 3

adj1: jmp adj

giam_lcd11: jmp giam_lcd

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

tang_lcd: mov 78h,#180

tang_lcd1: lcall hien_thi_lcd

djnz 78h,tang_lcd1 cjne bmode,#01h,ss41 mov r0,#06h

movx a,@r0 inc a cjne a,#9,ghidata1 mov a,#1

ghidata1: movx @r0,a

jmp lb1 ss41: cjne bmode,#02h,ss42

mov r0,#07h movx a,@r0 inc a cjne a,#32,ghidata1 mov a,#1

jmp ghidata1 ss42: cjne bmode,#03h,ss43

mov r0,#08h movx a,@r0 inc a cjne a,#13,ghidata1 mov a,#1

jmp ghidata1 ss43: cjne bmode,#4,ss44

mov r0,#09h movx a,@r0 inc a cjne a,#100,ghidata1 mov a,#0

jmp ghidata1 ss44: cjne bmode,#5,ss45

mov r0,#04h movx a,@r0 inc a cjne a,#24,ghidata1 mov a,#0

jmp ghidata1 ss45: cjne bmode,#6,ss46

mov r0,#02h movx a,@r0 inc a cjne a,#60,ghidata1 mov a,#0

jmp ghidata1 ss46: mov r0,#0h

Trang 4

movx a,@r0 inc a cjne a,#60,ghidata1 mov a,#0

jmp ghidata1

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

giam_lcd: mov 78h,#180

giam_lcd1: lcall hien_thi_lcd

djnz 78h,giam_lcd1 cjne bmode,#01h,ss51 mov r0,#06h

movx a,@r0 dec a cjne a,#0,ghidata11 mov a,#8

ghidata11: movx @r0,a

jmp lb1 ss51: cjne bmode,#02h,ss52

mov r0,#07h movx a,@r0 dec a cjne a,#0,ghidata11 mov a,#31

jmp ghidata11 ss52: cjne bmode,#03h,ss53

mov r0,#08h movx a,@r0 dec a cjne a,#0,ghidata11 mov a,#12

jmp ghidata11 ss53: cjne bmode,#4,ss54

mov r0,#09h movx a,@r0 dec a cjne a,#0ffh,ghidata11 mov a,#099

jmp ghidata11 ss54: cjne bmode,#5,ss55

mov r0,#04h movx a,@r0 dec a cjne a,#0ffh,ghidata11 mov a,#23

jmp ghidata11 ss55: cjne bmode,#6,ss56

mov r0,#02h movx a,@r0 dec a

Trang 5

cjne a,#0ffh,ghidata11 mov a,#59

jmp ghidata11 ss56: mov r0,#0h

movx a,@r0 dec a cjne a,#0ffh,ghidata11 mov a,#59

jmp ghidata11

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

khoitaodalass: mov r0,#0bh ;nap dia chi thanh ghi b cua dallas

mov a,#06h ;nap gtri 06h cho thanh ghi b movx @r0,a

mov r0,#0ah ; nap dia chi thanh ghi a cua dallas mov a,#020h ; nap gtri 20h cho thanh ghi b movx @r0,a

ret

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

khoitao_lcd: mov a,#38h ;chon lcd 2x16 ma chu la mtrix 5x7

lcall ghimadk ;goi ctrinh ghi lenh lcall delay41ms ;delay chong lem cua lcd mov a,#38h ;khoi taofunction (chuc nang) lcall ghimadk

lcall delay41ms mov a,#0ch ;set ddram(080) lcall ghimadk

lcall delay41ms mov a,#01h ;xoa man hinh lcd lcall ghimadk

lcall delay41ms ret

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

ghidata: mov p1,a ; xuat thanh ghi a ra port P1

setb rs ;RS cao dữ liệu cho một byte

clr enb ret

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

ghimadk: mov p1,a ;xuat thanh ghi a ra port P1

clr rs ;RS thấp cho một lệnh byte

clr enb ret

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

doc_gpg: mov r0,#6 ;lay noi dung ngay

movx a,@r0 cjne a,#1,tt mov a,#8 ;neu ngay la 1 thi gan ngay =8

Trang 6

tt: mov 10h,a ;ngay trong tuan luu o o nho 10h

mov r0,#07 ;07 tuc la ngay trong dallas mov r1,#11h

x1: movx a,@r0 ;lay ngay,trong thang, thang nam nap vao

mov @r1,a ;vung dchi bat dau tu 11h-13h inc r0

inc r1 cjne r0,#0ah,x1 mov r0,#04 ;lay gio phut giay nap vao tu mov r1,#14h ;vung nho 14h-16h

mov @r1,a dec r0 dec r0 inc r1 cjne r0,#0feh,x2 ;neu bang 0feh thi thoat ret

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

hex_bcd: mov r0,#10h

mov r1,#1fh ;vung nho de luu du lieu sau khi gma

mov b,#10 div ab mov @r1,a ;phan nguyen nap vao vung nho luu sau gma inc r1

mov @r1,b ;nap phan du vao o nho ke inc r0 ;tien hang gma thang nam inc r1

cjne r0,#14h,hb ;kt neu = 14h thoat (het dong 1 lcd) mov r0,#14h

mov r1,#27h ;gpg tt nhu ngay thang nam hb1: mov a,@r0 ;luu vao vung nho tu 27h – 2bh

mov b,#10 div ab mov @r1,a inc r1 mov @r1,b inc r0 inc r1 cjne r0,#17h,hb1 ; kt neu = 17h thoat (het dong 2 lcd) ret

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

giaima_lcd: mov 3fh,#'T' ;nap ma chu va cac gia tri dong 1 lcd

mov 3eh,#'h' ;vao vung nho mov 3dh,#'u'

mov 3ch,#':' mov dptr,#900h

movc a,@a+dptr mov 3bh,a ;luu lai vao vung nho (tt)

Trang 7

mov 3ah,#' '

movc a,@a+dptr mov 39h,a

movc a,@a+dptr mov 38h,a mov 37h,#'-'

movc a,@a+dptr mov 36h,a

movc a,@a+dptr mov 35h,a mov 34h,#'-' mov 33h,#'2' mov 32h,#'0'

movc a,@a+dptr mov 31h,a

movc a,@a+dptr mov 30h,a

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

mov 5fh,#'G' ; nap ma chu va cac gia tri dong 2 lcd mov 5eh,#'i'

mov 5dh,#'o' mov 5ch,#' ' mov 5bh,#':' mov 5ah,#' ' mov dptr,#900h

movc a,@a+dptr mov 59h,a

movc a,@a+dptr mov 58h,a mov 57h,#'-'

movc a,@a+dptr mov 56h,a

movc a,@a+dptr mov 55h,a mov 54h,#'-'

movc a,@a+dptr mov 53h,a

movc a,@a+dptr

Trang 8

mov 52h,a ret

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

hien_thi_lcd: mov a,#080h ;dia chi hang 1 lcd

lcall ghimadk ;goi chuong trinh ghi lenh lcall delay

mov r0,#3fh ;hien thi thu, ngay, thang, nam dong 1lcd

lcall ghidata lcall delay dec r0 cjne r0,#2fh,x9

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

mov a,#0c1h ;nap dia chi hang thu 2 lcd lcall ghimadk

lcall delay mov r0,#5fh ;hien thi gpg tren dong 2 lcd

lcall ghidata lcall delay dec r0 cjne r0,#51h,x10 ret

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

ngat_t0: mov th0,#3ch ;khoi tao timer delay 50ms

mov tl0,#0b0h ;ngat tao ra sau 50ms de tao xung kich loa djnz r3,exit ;cho phep sau 0,5 s

cpl buzzer ;bu bit loa mov r3,#10 ;nap lai 10 vao r3 djnz r2,exit ;nhay neu r2 ≠ 0 setb buzzer ;tat chuong

exit: reti

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

delay41ms: mov 7fh,#100 ;chuong trinh con delay 4.1 ms

dell1: mov 7eh,#250

del1: djnz 7eh,del1

djnz 7fh,dell1 ret

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

delay: mov 7ch,#15 ;chuong trinh con delay 240 microgiay

djnz 7ch,$

ret delay1: mov 7ch,#200 ;chuong trinh con delay 55 microgiay

djnz 7ch,$

ret

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

org 900h

end

Ngày đăng: 04/08/2016, 22:58

TỪ KHÓA LIÊN QUAN

w