ĐỒNG HỒ SỐ HIỆN THỊ TRÊN LCD BÁO GIỜ BẰNG CHUÔNG ;********************************************************************** ; DONG HO SO HIEN THI TREN LCD BAO GIO BANG CHUONG ;********************************************************************** rs bit p3.2 ; chon 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 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 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 clr tr0 ;cam ngat timer0 mov ie,#82h ;cho phep ngat timer0 mov bmode,#0 ;dat bien chon dieu chinh =0 setb buzzer ;tat chuong mov r2,#0 ;nap 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 = cjne r2,#0,tu_dau ;so sanh neu r2 = nhay toi tu_dau mov a,16h ;kt giay =0 cjne a,#0,tu_dau ;neu ≠ thi nhay lai tu_dau mov a,15h ;kt phut =0 cjne a,#0,tu_dau ; neu ≠ thi nhay lai tu_dau clr buzzer ;set loa mov r3,#10 ;nap 10 vao r3 setb tr0 ;cho phep timer0 hoat dong mov a,14h ;chuyen gio vao a mov b,#2 ;nap vao b mul ab ;nhan a voi b cjne a,#0,khac24 ;so sang xem co = 0, neu ≠ nhay toi khac24 mov a,#48 ;nap 48 vao a khac24: dec a ;giam a mov r2,a ;nap a vao ghi a jmp tu_dau ;nhay toi tu_dau ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx adj: jnb mode,$ ;cho buong nut MODE Trang ĐỒNG HỒ SỐ HIỆN THỊ TRÊN LCD BÁO GIỜ BẰNG CHUÔNG inc bmode ;tang bmode len don vi cjne bmode,#08,lb1 ;so sanh neu bmode = thi nhay toi lb1 mov bmode,#0 ;nhan du lan thi tra ve ljmp tu_dau ;nhay lai tu_dau ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx lb1: mov 67h,#10 ;nap 10 vao 67h 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 = jnb dwn,giam_lcd11 ; nhay toi giam_lcd neu DWN = jnb mode,adj ;kien tra MODE djnz 66h,lb2 ;nhay neu 66h = 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 = thi nhay toi tat_thang mov 39h,#' ' ;ngay nhap nhay mov 38h,#' ' sjmp tat_lcd tat_thang: cjne bmode,#3,tat_nam mov 35h,#' ' ;thang mov 36h,#' ' jmp tat_lcd tat_nam: cjne bmode,#4,tat_gio mov 30h,#' ' ;nam mov 31h,#' ' jmp tat_lcd tat_gio: cjne bmode,#5,tat_phut mov 59h,#' ' ;gio mov 58h,#' ' jmp tat_lcd tat_phut: cjne bmode,#6,tat_giay mov 56h,#' ' ;phut 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 ĐỒNG HỒ SỐ HIỆN THỊ TRÊN LCD BÁO GIỜ BẰNG CHUÔNG 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 ĐỒNG HỒ SỐ HIỆN THỊ TRÊN LCD BÁO GIỜ BẰNG CHUÔNG 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 mov movx dec bmode,#6,ss56 r0,#02h a,@r0 a Trang ĐỒNG HỒ SỐ HIỆN THỊ TRÊN LCD BÁO GIỜ BẰNG CHUÔNG 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 ghi b cua dallas mov a,#06h ;nap gtri 06h cho ghi b movx @r0,a mov r0,#0ah ; nap dia chi ghi a cua dallas mov a,#020h ; nap gtri 20h cho 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 tao function (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 ghi a port P1 setb rs ;RS cao liệu cho byte clr rw ;chế độ ghi setb enb ;cho phep clr enb ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ghimadk: mov p1,a ;xuat ghi a port P1 clr rs ;RS thấp cho lệnh byte clr rw ;chế độ ghi setb enb ;cho phep clr enb ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx doc_gpg: mov r0,#6 ;lay noi dung movx a,@r0 cjne a,#1,tt mov a,#8 ;neu la thi gan =8 Trang ĐỒNG HỒ SỐ HIỆN THỊ TRÊN LCD BÁO GIỜ BẰNG CHUÔNG tt: mov 10h,a ;ngay tuan luu o o nho 10h mov r0,#07 ;07 tuc la 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 x2: movx a,@r0 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 gma hb: mov a,@r0 ;giai ma hex sang bcd 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 lcd) mov r0,#14h mov r1,#27h ;gpg tt nhu 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 lcd) ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx giaima_lcd: mov 3fh,#'T' ;nap ma chu va cac gia tri dong lcd mov 3eh,#'h' ;vao vung nho mov 3dh,#'u' mov 3ch,#':' mov dptr,#900h mov a,20h ;thu movc a,@a+dptr mov 3bh,a ;luu lai vao vung nho (tt) Trang ĐỒNG HỒ SỐ HIỆN THỊ TRÊN LCD BÁO GIỜ BẰNG CHUÔNG mov 3ah,#' ' mov a,21h ;chuc movc a,@a+dptr mov 39h,a mov a,22h ;dv movc a,@a+dptr mov 38h,a mov 37h,#'-' mov a,23h ;chuc thang movc a,@a+dptr mov 36h,a mov a,24h ;dv thang movc a,@a+dptr mov 35h,a mov 34h,#'-' mov 33h,#'2' mov 32h,#'0' mov a,25h ;chuc nam movc a,@a+dptr mov 31h,a mov a,26h ;dv nam movc a,@a+dptr mov 30h,a ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx mov 5fh,#'G' ; nap ma chu va cac gia tri dong lcd mov 5eh,#'i' mov 5dh,#'o' mov 5ch,#' ' mov 5bh,#':' mov 5ah,#' ' mov dptr,#900h mov a,27h ;chuc gio movc a,@a+dptr mov 59h,a mov a,28h ;dv gio movc a,@a+dptr mov 58h,a mov 57h,#'-' mov a,29h ;chuc phut movc a,@a+dptr mov 56h,a mov a,2ah ;dv phut movc a,@a+dptr mov 55h,a mov 54h,#'-' mov a,2bh ;chuc giay movc a,@a+dptr mov 53h,a mov a,2ch ;dv giay movc a,@a+dptr Trang ĐỒNG HỒ SỐ HIỆN THỊ TRÊN LCD BÁO GIỜ BẰNG CHUÔNG mov 52h,a ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx hien_thi_lcd: mov a,#080h ;dia chi hang lcd lcall ghimadk ;goi chuong trinh ghi lenh lcall delay mov r0,#3fh ;hien thi thu, ngay, thang, nam dong 1lcd x9: mov a,@r0 ; (tu 3fh-30h) lcall ghidata lcall delay dec r0 cjne r0,#2fh,x9 ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx mov a,#0c1h ;nap dia chi hang thu lcd lcall ghimadk lcall delay mov r0,#5fh ;hien thi gpg tren dong lcd x10: mov a,@r0 ; (tu 5fh-52h) 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 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 ≠ setb buzzer ;tat chuong clr tr0 ;tat timer0 exit: reti ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx delay41ms: mov 7fh,#100 ; chuong trinh delay 4.1 ms dell1: mov 7eh,#250 del1: djnz 7eh,del1 djnz 7fh,dell1 ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx delay: mov 7ch,#15 ; chuong trinh delay 240 microgiay djnz 7ch,$ ret delay1: mov 7ch,#200 ;chuong trinh delay 55 microgiay djnz 7ch,$ ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx org 900h db '0123456789' ;bang ma end Trang