Kênh Tên Miền chuyên cung cấp tên miền đẹp, giá rẻ! Hãy liên hệ kỹ thuật: 0914205579 - Kinh doanh: 0912191357 để được tư vấn, hướng dẫn miễn phí, Cảm ơn quý khách đã ủng hộ trong thời gian qua!
Tuesday, April 21, 2015




Code mã nguồn ASM:
; HTTP://ECHiPKOOL.COM
DQ BIT P3.0
MODE1 BIT P2.0 // Low
MODE2 BIT P2.1 // hight
UP BIT P2.2
DOWN BIT P2.3
LUU BIT P2.4   // ok
DEM EQU R2
T_LSB EQU 30H
T_MSB EQU 20H
TEMP EQU 32H
DIGIT EQU 31H
T_DIGIT EQU 33H
T_LED EQU 34H
ORG 0000H
JMP CHUONG_TRINH_CHINH
WRITE_TIME_SLOT:
CLR DQ
NOP
NOP
MOV DQ,C
MOV R5,#15
LCALL DELAY
SETB DQ
NOP
RET
READ_TIME_SLOT:
CLR DQ
NOP
NOP
SETB DQ
MOV R5,#4
CALL DELAY
MOV C, DQ
MOV R5,#25
LCALL DELAY
RET
RESET_DS1820:
CLR DQ
MOV R5,#244
LCALL DELAY
SETB DQ
MOV R5,#36
LCALL DELAY
JB DQ,RESET_DS1820
MOV R5,#212
CALL DELAY
RET
WRITE_BYTE:
MOV DEM,#8
WRITE_LAI:
RRC A
LCALL WRITE_TIME_SLOT
DJNZ DEM, WRITE_LAI
SETB DQ
MOV R5,#50
LCALL DELAY
RET
READ_BYTE:
MOV DEM,#8
READ_LAI:
LCALL READ_TIME_SLOT
RRC A
DJNZ DEM, READ_LAI
MOV R5,#50
LCALL DELAY
RET
DELAY:
DJNZ R5,$
RET
DELAY_LONG:
MOV R6,#0FFH
DELAY_LAI:
LCALL DELAY
DJNZ R6,DELAY_LAI
RET
BCD:
MOV B,#10
DIV AB
MOV T_LED,A
RET
HIEU_CHINH:
MOV TEMP,#0
MOV DIGIT,#0
ANL A,#0FH
MOV TEMP,A
MOV A,T_LSB
ANL A,#0F0H
ORL TEMP,A
MOV A,TEMP
SWAP A
MOV TEMP,A

MOV A,T_LSB
ANL A,#0FH
MOV DPTR,#TABLE1
MOVC A,@A+DPTR
MOV DIGIT,A
RET
KIEMTRA:
JNB 6,OUT_KT
MOV A,#0FFH
CLR C
SUBB A,TEMP
MOV TEMP,A
MOV A,#0FH
ANL A,T_LSB
CJNE A,#0,OUT_KT1
INC TEMP
JMP OUT_KT
OUT_KT1:
MOV DPTR,#TABLE2
MOVC A,@A+DPTR
MOV DIGIT,A
OUT_KT:
RET
; Hien thi led 7 thanh
OUTLED:
MOV DPTR,#TABLE0
MOV A,TEMP
CALL BCD
MOV A,B
MOVC A,@A+DPTR
ANL A,#01111111B
MOV P1,A
CLR P3.4
CALL DELAYLED
SETB P3.4
MOV A,T_LED
CALL BCD
JNB 6,NEXT1
MOV A,#10
NEXT1:
MOVC A,@A+DPTR
MOV P1,A
CLR P3.2
CALL DELAYLED
SETB P3.2
MOV A,B
MOVC A,@A+DPTR
MOV P1,A
CLR P3.3
CALL DELAYLED
SETB P3.3
MOV A,DIGIT
MOVC A,@A+DPTR
MOV P1,A
CLR P3.5
CALL DELAYLED
SETB P3.5
RET
DELAYLED:
MOV R7,#5
LOOPD: MOV R6,#255
DJNZ R6,$
DJNZ R7,LOOPD
RET
CHUONG_TRINH_CHINH:
SETB MODE1
SETB MODE2
SETB LUU
SETB UP
SETB DOWN
SETB DQ
AGAIN:

LCALL RESET_DS1820
MOV A,#0CCH
LCALL WRITE_BYTE
MOV A,#44H
LCALL WRITE_BYTE
LCALL RESET_DS1820
MOV A,#0CCH
LCALL WRITE_BYTE
MOV A,#0BEH
LCALL WRITE_BYTE
LCALL READ_BYTE
MOV T_LSB,A
LCALL READ_BYTE
MOV T_MSB,A
LCALL RESET_DS1820
LCALL HIENTHI
JNB MODE1,NHIETDO_DAT1
JNB MODE2,NHIETDO_DAT2
CALL SOSANH1
CALL SOSANH2
CLR C
JMP AGAIN
HIENTHI:
CALL HIEU_CHINH
CALL KIEMTRA
CALL OUTLED
RET
SOSANH1:
CLR C
MOV A,50H
CJNE A,TEMP,NHAY1
SOSANH2:
CLR C
MOV A,51H
CJNE A,TEMP,NHAY2
RET
NHAY1:
JC RELAY
CLR P0.0
RET
RELAY:
SETB P0.0
RET
NHAY2:
JNC ALARM
CPL P0.1
RET
ALARM:
CLR P0.1
RET
NHIETDO_DAT1:
JB UP,NUT_DOWN
JNB UP,$
INC 50H
MOV A,50H
CJNE A,#125,NUT_DOWN
MOV 50H,#0
NUT_DOWN:
JB DOWN,HIENTHI2
JNB DOWN,$
DEC 50H
MOV A,50H
CJNE A,#0,HIENTHI2
MOV 50H,#125
HIENTHI2:
MOV P1,#0C7H
CLR P3.2
CALL DELAYLED
SETB P3.2
MOV R4,50H
ACALL HIENTHI1
JB LUU,NHIETDO_DAT1
JNB LUU,THOAT
NHIETDO_DAT2:
JB UP,NUT_DOWN1
JNB UP,$
INC 51H
MOV A,51H
CJNE A,#125,NUT_DOWN1
MOV 51H,#0
NUT_DOWN1:
JB DOWN,HIENTHI3
JNB DOWN,$
DEC 51H
MOV A,51H
CJNE A,#0,HIENTHI3
MOV 51H,#125
HIENTHI3:
MOV P1,#89H
CLR P3.2
CALL DELAYLED
SETB P3.2
MOV R4,51H
ACALL HIENTHI1
JB LUU,NHIETDO_DAT2
THOAT:
LJMP CHUONG_TRINH_CHINH
HIENTHI1:
MOV DPTR,#TABLE0
MOV A,R4
MOV B,#100
DIV AB
MOVC A,@A+DPTR
MOV P1,A
CLR P3.3
CALL DELAYLED
SETB P3.3
MOV A,B
MOV B,#10
DIV AB
MOVC A,@A+DPTR
MOV P1,A
CLR P3.4
CALL DELAYLED
SETB P3.4
MOV A,B
MOVC A,@A+DPTR
MOV P1,A
CLR P3.5
CALL DELAYLED
SETB P3.5
RET
DELAY1S:
MOV R0,#250
LAPLAI:
MOV R1,#255
DJNZ R1,$
DJNZ R0,LAPLAI
RET
TABLE0:
DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,0BFH, 0FFH
TABLE1:
DB 0,0,1,0,2,3,0,4,5,0,6,0,7,8,0,9
TABLE2:
DB 0,0,9,8,0,7,0,6,5,0,4,3,0,2,0,1
END


( Code Full + Mô phỏng Protues 8.0)
Khi nhấn nút "Tải Về Máy", bạn sẽ vào trang quảng cáo, vui lòng chờ 5 giây. Nút  hiện ra ở góc phải phía trên, nhấn vào để đến trang download

Điện Tử | Tin Học - echipkool.com - Chia sẻ kiến thức kết nối đam mê điện tử

0 comments:

Post a Comment

domain, domain name, premium domain name for sales

Popular Posts