Bạn tramng cho mình hỏi sao chủ nhật nó hiển thị không đúng
Mình không hiểu bạn tạo mã led 7SEG như thế nào nên không sửa được
Mình không hiểu bạn tạo mã led 7SEG như thế nào nên không sửa được
Code gốc:
//---------------thang-------------------
if (month<10)
{
chucthang=0xff;
ledchucthang=0x00;
}
if (month>9)
{
chucthang=(ma[month/10]);
ledchucthang=0x80; //(0000/1000)
}
--------------------------------------------------------------------
Sửa thành:
//---------------thang-------------------
if (month<10)
{
chucthang=0xff;
ledchucthang=0x00;
}
if (month>9)
{
chucthang=(ma[month/10]);
ledchucthang=0x08;
}
THU EQU 30H
NGAY EQU 31H
THANG EQU 32H
NAM EQU 33H
GIO EQU 34H
PHUT EQU 35H
GIAY EQU 36H
MCNHIET EQU 37H
MCPHUT EQU 38H
MCGIO EQU 39H
MCTHU EQU 3AH
MCNGAY EQU 3BH
MCTHANG EQU 3CH
MCNAM EQU 3DH
MDVNHIET EQU 3EH
MDVPHUT EQU 3FH
MDVGIO EQU 40H
MDVTHU EQU 41H
MDVNGAY EQU 42H
MDVTHANG EQU 43H
MDVNAM EQU 44H
DAT EQU 45H
ADDRTC EQU 46H
DEM EQU 47H
TEMP EQU 48H
T_LSB EQU 49H
T_MSB EQU 4AH
TAM EQU 4BH
KT EQU R7
TEST BIT 00H
ACK BIT 01H
SET0 BIT 02H
SET1 BIT 03H
DOWN0 BIT 04H
DOWN1 BIT 05H
UP0 BIT 06H
UP1 BIT 07H
SCL BIT P0.7
SDA BIT P0.6
DQ BIT P0.0
SELECT BIT P0.4
UP BIT P0.5
DOWN BIT P0.3
LEDCNHIET BIT P3.4
LEDDVNHIET BIT P3.5
LEDCNGAY BIT P3.0
LEDDVNGAY BIT P3.1
LEDCTHU BIT P3.3
LEDDVTHU BIT P3.2
LEDCTHANG BIT P1.6
LEDDVTHANG BIT P1.7
LEDCNAM BIT P1.5
LEDDVNAM BIT P1.4
LEDCPHUT BIT P1.1
LEDDVPHUT BIT P1.0
LEDCGIO BIT P1.3
LEDDVGIO BIT P1.2
DATA7DOAN DATA P2
ORG 0000H
MOV KT,#00H
CLR TEST
SETB SET0
SETB SET1
SETB UP0
SETB UP1
SETB DOWN0
SETB DOWN1
MAIN:
LCALL I2C_START
MOV A,#0D0H
LCALL I2C_WRITE
MOV A,#07H
LCALL I2C_WRITE
MOV A,#10H
LCALL I2C_WRITE
LCALL I2C_STOP
CHUONG_TRINH_CHINH:
LCALL QUETPHIM
LCALL READ_DS1307
LCALL DELAY_HIENTHI
LCALL DOC_NHIETDO
LCALL QUETPHIM
LCALL DELAY_HIENTHI
JMP CHUONG_TRINH_CHINH
SCL_HIGHT:
SETB SCL
LCALL DELAY_I2C
RET
;**********************************************************
SCL_LOW:
CLR SCL
LCALL DELAY_I2C
RET
;**********************************************************
I2C_START:
SETB SDA
SETB SCL
CLR SDA
LCALL DELAY_I2C
CLR SCL
SETB SDA
RET
;**********************************************************
I2C_STOP:
CLR SDA
LCALL SCL_HIGHT
SETB SDA
RET
;**********************************************************
I2C_WRITE:
MOV DEM,#8
LAP:
RLC A
MOV SDA,C
LCALL SCL_HIGHT
LCALL SCL_LOW
DJNZ DEM,LAP
SETB SDA
LCALL SCL_HIGHT
LCALL SCL_LOW
RET
;**********************************************************
I2C_READ:
MOV DEM,#8
LAP1:
LCALL SCL_HIGHT
MOV C,SDA
RLC A
LCALL SCL_LOW
DJNZ DEM,LAP1
JB ACK,LAP2
CLR SDA
LAP2:
SETB SDA
LCALL SCL_HIGHT
CLR SCL
CLR SDA
LCALL DELAY_I2C
RET
RTC_WRITE:
LCALL I2C_START
MOV A,#0D0H
LCALL I2C_WRITE
MOV A,ADDRTC
LCALL I2C_WRITE
MOV A,DAT
MOV B,#10
DIV AB
SWAP A
ORL A,B
LCALL I2C_WRITE
LCALL I2C_STOP
RET
;**********************************************************
RTC_READ:
LCALL I2C_START
MOV A,#0D0H
LCALL I2C_WRITE
MOV A,ADDRTC
LCALL I2C_WRITE
LCALL I2C_START
MOV A,#0D1H
LCALL I2C_WRITE
CLR ACK
LCALL I2C_READ
LCALL I2C_STOP
RET
;**********************************************************
WRITE_DS1307:
MOV ADDRTC,#00H
MOV DAT,#00H
LCALL RTC_WRITE
MOV ADDRTC,#01H
MOV DAT,PHUT
LCALL RTC_WRITE
MOV ADDRTC,#02H
MOV DAT,GIO
LCALL RTC_WRITE
MOV ADDRTC,#03H
MOV DAT,THU
LCALL RTC_WRITE
MOV ADDRTC,#04H
MOV DAT,NGAY
LCALL RTC_WRITE
MOV ADDRTC,#05H
MOV DAT,THANG
LCALL RTC_WRITE
MOV ADDRTC,#06H
MOV DAT,NAM
LCALL RTC_WRITE
RET
;**********************************************************
DOC_PHUT:
MOV B,#10
MOV ADDRTC,#01H
LCALL RTC_READ
MOV PHUT,A
ANL PHUT,#0FH
ANL A,#0F0H
SWAP A
MUL AB
ADD A,PHUT
MOV PHUT,A
RET
;**********************************************************
DOC_GIO:
MOV B,#10
MOV ADDRTC,#02H
LCALL RTC_READ
MOV GIO,A
ANL GIO,#0FH
ANL A,#0F0H
SWAP A
MUL AB
ADD A,GIO
MOV GIO,A
RET
;**********************************************************
DOC_THU:
MOV B,#10
MOV ADDRTC,#03H
LCALL RTC_READ
MOV THU,A
ANL THU,#0FH
ANL A,#0F0H
SWAP A
MUL AB
ADD A,THU
MOV THU,A
RET
;**********************************************************
DOC_NGAY:
MOV B,#10
MOV ADDRTC,#04H
LCALL RTC_READ
MOV NGAY,A
ANL NGAY,#0FH
ANL A,#0F0H
SWAP A
MUL AB
ADD A,NGAY
MOV NGAY,A
RET
;**********************************************************
DOC_THANG:
MOV B,#10
MOV ADDRTC,#05H
LCALL RTC_READ
MOV THANG,A
ANL THANG,#0FH
ANL A,#0F0H
SWAP A
MUL AB
ADD A,THANG
MOV THANG,A
RET
;**********************************************************
DOC_NAM:
MOV B,#10
MOV ADDRTC,#06H
LCALL RTC_READ
MOV NAM,A
ANL NAM,#0FH
ANL A,#0F0H
SWAP A
MUL AB
ADD A,NAM
MOV NAM,A
RET
;**********************************************************
READ_DS1307:
CJNE KT,#0,OUT_READ
JNB TEST,DOC_GIATRI
LCALL WRITE_DS1307
CLR TEST
DOC_GIATRI:
LCALL DOC_PHUT
LCALL DOC_GIO
LCALL DOC_THU
LCALL DOC_NGAY
LCALL DOC_THANG
LCALL DOC_NAM
OUT_READ:
RET
WRITE_TIME_SLOT:
CLR DQ
NOP
NOP
NOP
NOP
MOV DQ,C
MOV R5,#31
LCALL DELAY_DS18B20
SETB DQ
NOP
NOP
RET
;**********************************************************
READ_TIME_SLOT:
CLR DQ
NOP
NOP
NOP
NOP
SETB DQ
MOV R5,#9
LCALL DELAY_DS18B20
MOV C,DQ
MOV R5,#51
LCALL DELAY_DS18B20
RET
;**********************************************************
RESET_DS1820:
CLR DQ
MOV R5,#244
LCALL DELAY_DS18B20
SETB DQ
MOV R5,#73
LCALL DELAY_DS18B20
JB DQ,RESET_DS1820
MOV R5,#212
CALL DELAY_DS18B20
RET
;**********************************************************
WRITE_BYTE:
MOV DEM,#8
WRITE_LAI:
RRC A
LCALL WRITE_TIME_SLOT
DJNZ DEM, WRITE_LAI
SETB DQ
MOV R5,#101
LCALL DELAY_DS18B20
RET
;**********************************************************
READ_BYTE:
MOV DEM,#8
READ_LAI:
LCALL READ_TIME_SLOT
RRC A
DJNZ DEM, READ_LAI
MOV R5,#101
LCALL DELAY_DS18B20
RET
;**********************************************************
HIEU_CHINH_NHIETDO:
MOV TEMP,#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
RET
;**********************************************************
HEXTOBCD_GIAIMA_NHIETDO:
MOV A,TEMP
MOV B,#10
DIV AB
MOV MDVNHIET,B
MOV B,#10
DIV AB
MOV MCNHIET,B
RET
;**********************************************************
DOC_NHIETDO:
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 HIEU_CHINH_NHIETDO
RET
KTPHIM:
MOV C,SET1
MOV SET0,C
MOV C,SELECT
MOV SET1,C
JNB SET0,OUT_KTPHIM
JB SET1,OUT_KTPHIM
INC KT
CJNE KT,#7,OUT_KTPHIM
MOV KT,#00H
OUT_KTPHIM:
RET
;**********************************************************
CHINH_THU:
MOV C,UP1
MOV UP0,C
MOV C,UP
MOV UP1,C
MOV C,DOWN1
MOV DOWN0,C
MOV C,DOWN
MOV DOWN1,C
JNB UP0,GIAM_THU
JB UP1,GIAM_THU
SETB TEST
INC THU
MOV A,THU
CJNE A,#8,GIAM_THU
MOV THU,#1
GIAM_THU:
JNB DOWN0,OUT_THU
JB DOWN1,OUT_THU
DJNZ THU,OUT_THU
MOV THU,#7
OUT_THU:
RET
;**********************************************************
CHINH_NGAY:
MOV C,UP1
MOV UP0,C
MOV C,UP
MOV UP1,C
MOV C,DOWN1
MOV DOWN0,C
MOV C,DOWN
MOV DOWN1,C
JNB UP0,GIAM_NGAY
JB UP1,GIAM_NGAY
SETB TEST
INC NGAY
MOV A,NGAY
CJNE A,#32,GIAM_NGAY
MOV NGAY,#1
GIAM_NGAY:
JNB DOWN0,OUT_NGAY
JB DOWN1,OUT_NGAY
DJNZ NGAY,OUT_NGAY
MOV NGAY,#31
OUT_NGAY:
RET
;**********************************************************
CHINH_THANG:
MOV C,UP1
MOV UP0,C
MOV C,UP
MOV UP1,C
MOV C,DOWN1
MOV DOWN0,C
MOV C,DOWN
MOV DOWN1,C
JNB UP0,GIAM_THANG
JB UP1,GIAM_THANG
SETB TEST
INC THANG
MOV A,THANG
CJNE A,#13,GIAM_THANG
MOV THANG,#1
GIAM_THANG:
JNB DOWN0,OUT_THANG
JB DOWN1,OUT_THANG
DJNZ THANG,OUT_THANG
MOV THANG,#12
OUT_THANG:
RET
;**********************************************************
CHINH_NAM:
MOV C,UP1
MOV UP0,C
MOV C,UP
MOV UP1,C
MOV C,DOWN1
MOV DOWN0,C
MOV C,DOWN
MOV DOWN1,C
JNB UP0,GIAM_NAM
JB UP1,GIAM_NAM
SETB TEST
INC NAM
MOV A,NAM
CJNE A,#100,GIAM_NAM
MOV NAM,#0
GIAM_NAM:
JNB DOWN0,OUT_NAM
JB DOWN1,OUT_NAM
DEC NAM
MOV A,NAM
CJNE A,#255,OUT_NAM
MOV NAM,#99
OUT_NAM:
RET
;**********************************************************
CHINH_GIO:
MOV C,UP1
MOV UP0,C
MOV C,UP
MOV UP1,C
MOV C,DOWN1
MOV DOWN0,C
MOV C,DOWN
MOV DOWN1,C
JNB UP0,GIAM_GIO
JB UP1,GIAM_GIO
SETB TEST
INC GIO
MOV A,GIO
CJNE A,#24,GIAM_GIO
MOV GIO,#0
GIAM_GIO:
JNB DOWN0,OUT_GIO
JB DOWN1,OUT_GIO
DEC GIO
MOV A,GIO
CJNE A,#255,OUT_GIO
MOV GIO,#23
OUT_GIO:
RET
;**********************************************************
CHINH_PHUT:
MOV C,UP1
MOV UP0,C
MOV C,UP
MOV UP1,C
MOV C,DOWN1
MOV DOWN0,C
MOV C,DOWN
MOV DOWN1,C
JNB UP0,GIAM_PHUT
JB UP1,GIAM_PHUT
SETB TEST
INC PHUT
MOV A,PHUT
CJNE A,#60,GIAM_PHUT
MOV PHUT,#0
GIAM_PHUT:
JNB DOWN0,OUT_PHUT
JB DOWN1,OUT_PHUT
DEC PHUT
MOV A,PHUT
CJNE A,#255,OUT_PHUT
MOV PHUT,#59
OUT_PHUT:
RET
;**********************************************************
QUETPHIM:
LCALL KTPHIM
CJNE KT,#0,THU0
JMP OUT_QUET
THU0:
CJNE KT,#1,NGAY0
LCALL CHINH_THU
JMP OUT_QUET
NGAY0:
CJNE KT,#2,THANG0
LCALL CHINH_NGAY
JMP OUT_QUET
THANG0:
CJNE KT,#3,NAM0
LCALL CHINH_THANG
JMP OUT_QUET
NAM0:
CJNE KT,#4,GIO0
LCALL CHINH_NAM
JMP OUT_QUET
GIO0:
CJNE KT,#5,PHUT0
LCALL CHINH_GIO
JMP OUT_QUET
PHUT0:
CJNE KT,#6,OUT_QUET
LCALL CHINH_PHUT
JMP OUT_QUET
OUT_QUET:
RET
HEXTOBCD_GIAIMA_PHUT:
MOV A,PHUT
MOV B,#10
DIV AB
MOVC A,@A+DPTR
MOV MCPHUT,A
MOV A,B
MOVC A,@A+DPTR
MOV MDVPHUT,A
RET
;**********************************************************
HEXTOBCD_GIAIMA_GIO:
MOV A,GIO
MOV B,#10
DIV AB
CJNE A,#0,NHAY5
MOV MCGIO,#0FFH
JMP NHAY6
NHAY5:
MOVC A,@A+DPTR
MOV MCGIO,A
NHAY6:
MOV A,B
MOVC A,@A+DPTR
MOV MDVGIO,A
RET
;**********************************************************
HEXTOBCD_GIAIMA_THU:
MOV A,THU
CJNE A,#1,NHAY0
MOV MDVTHU,#0C2H
MOV MCTHU,#0C9H
JMP OUT0
NHAY0:
MOV B,#10
DIV AB
MOV A,B
MOVC A,@A+DPTR
MOV MDVTHU,A
MOV MCTHU,#0FFH
OUT0:
RET
;**********************************************************
HEXTOBCD_GIAIMA_NGAY:
MOV A,NGAY
MOV B,#10
DIV AB
CJNE A,#0,NHAY1
MOV MCNGAY,#0FFH
JMP NHAY2
NHAY1:
MOVC A,@A+DPTR
MOV MCNGAY,A
NHAY2:
MOV A,B
MOVC A,@A+DPTR
MOV MDVNGAY,A
RET
;**********************************************************
HEXTOBCD_GIAIMA_THANG:
MOV A,THANG
MOV B,#10
DIV AB
CJNE A,#0,NHAY3
MOV MCTHANG,#0FFH
JMP NHAY4
NHAY3:
MOVC A,@A+DPTR
MOV MCTHANG,A
NHAY4:
MOV A,B
MOVC A,@A+DPTR
MOV MDVTHANG,A
RET
;**********************************************************
HEXTOBCD_GIAIMA_NAM:
MOV A,NAM
MOV B,#10
DIV AB
MOVC A,@A+DPTR
MOV MCNAM,A
MOV A,B
MOVC A,@A+DPTR
MOV MDVNAM,A
RET
;**********************************************************
HEXTOBCD_GIAIMA:
MOV DPTR,#MA7DOAN
LCALL HEXTOBCD_GIAIMA_THU
LCALL HEXTOBCD_GIAIMA_NGAY
LCALL HEXTOBCD_GIAIMA_THANG
LCALL HEXTOBCD_GIAIMA_NAM
LCALL HEXTOBCD_GIAIMA_GIO
LCALL HEXTOBCD_GIAIMA_PHUT
LCALL HEXTOBCD_GIAIMA_NHIETDO
RET
;**********************************************************
HIENTHI_NHIETDO:
MOV A,MCNHIET
MOVC A,@A+DPTR
MOV DATA7DOAN,A
SETB LEDCNHIET
LCALL DELAY50US
CLR LEDCNHIET
MOV A,MDVNHIET
MOVC A,@A+DPTR
MOV DATA7DOAN,A
SETB LEDDVNHIET
LCALL DELAY50US
CLR LEDDVNHIET
RET
;**********************************************************
HIENTHI_PHUT:
MOV DATA7DOAN,MCPHUT
SETB LEDCPHUT
LCALL DELAY50US
CLR LEDCPHUT
MOV DATA7DOAN,MDVPHUT
SETB LEDDVPHUT
LCALL DELAY50US
CLR LEDDVPHUT
RET
;**********************************************************
HIENTHI_GIO:
MOV DATA7DOAN,MCGIO
SETB LEDCGIO
LCALL DELAY50US
CLR LEDCGIO
MOV DATA7DOAN,MDVGIO
SETB LEDDVGIO
LCALL DELAY50US
CLR LEDDVGIO
RET
;**********************************************************
HIENTHI_THU:
MOV DATA7DOAN,MCTHU
SETB LEDCTHU
LCALL DELAY50US
CLR LEDCTHU
MOV DATA7DOAN,MDVTHU
SETB LEDDVTHU
LCALL DELAY50US
CLR LEDDVTHU
RET
;**********************************************************
HIENTHI_NGAY:
MOV DATA7DOAN,MCNGAY
SETB LEDCNGAY
LCALL DELAY50US
CLR LEDCNGAY
MOV DATA7DOAN,MDVNGAY
SETB LEDDVNGAY
LCALL DELAY50US
CLR LEDDVNGAY
RET
;**********************************************************
HIENTHI_THANG:
MOV DATA7DOAN,MCTHANG
SETB LEDCTHANG
LCALL DELAY50US
CLR LEDCTHANG
MOV DATA7DOAN,MDVTHANG
SETB LEDDVTHANG
LCALL DELAY50US
CLR LEDDVTHANG
RET
;**********************************************************
HIENTHI_NAM:
MOV DATA7DOAN,MCNAM
SETB LEDCNAM
LCALL DELAY50US
CLR LEDCNAM
MOV DATA7DOAN,MDVNAM
SETB LEDDVNAM
LCALL DELAY50US
CLR LEDDVNAM
RET
;**********************************************************
HIENTHI:
LCALL HIENTHI_THU
LCALL HIENTHI_NGAY
LCALL HIENTHI_THANG
LCALL HIENTHI_NAM
LCALL HIENTHI_GIO
LCALL HIENTHI_PHUT
LCALL HIENTHI_NHIETDO
RET
DELAY_HIENTHI:
MOV R1,#20
DEL:
LCALL HEXTOBCD_GIAIMA
CJNE KT,#00H,DEL1
LCALL HIENTHI
JMP DEL7
DEL1:
CJNE KT,#01H,DEL2
LCALL HIENTHI_THU
LCALL HIENTHI_NHIETDO
JMP DEL7
DEL2:
CJNE KT,#02H,DEL3
LCALL HIENTHI_NGAY
LCALL HIENTHI_NHIETDO
JMP DEL7
DEL3:
CJNE KT,#03H,DEL4
LCALL HIENTHI_THANG
LCALL HIENTHI_NHIETDO
JMP DEL7
DEL4:
CJNE KT,#04H,DEL5
LCALL HIENTHI_NAM
LCALL HIENTHI_NHIETDO
JMP DEL7
DEL5:
CJNE KT,#05H,DEL6
LCALL HIENTHI_GIO
LCALL HIENTHI_NHIETDO
JMP DEL7
DEL6:
CJNE KT,#06H,DEL7
LCALL HIENTHI_PHUT
LCALL HIENTHI_NHIETDO
JMP DEL7
DEL7:
DJNZ R1,DEL
RET
;**********************************************************
DELAY50US:
MOV R0,#50
DJNZ R0,$
RET
;**********************************************************
DELAY_I2C:
MOV R6,#5
DJNZ R6,$
RET
;**********************************************************
DELAY_DS18B20:
DJNZ R5,$
RET
MA7DOAN:
DB 0C0H, 0F6H, 0A1H, 0A4H, 96H, 8CH, 88H, 0E6H, 80H, 84H
END
Comment