;======================================
;
;DS1388+IIC+12864LCD
;MCU:89S52
;MADE BY 651927693
;2012/09/06
;V1.3
;可显示时间,
;======================================
;NAME 01 //定义模块名
?PR?DS1388_6 SEGMENT CODE //声明 SETADC子程序所属代码段
PUBLIC DS1388_6 //声明子程序 DS1388_6为公用,以便C模块可以调用
RSEG ?PR?DS1388_6
DS1388_6:
;ORG 0000H
;LJMP MAIN
;ORG 0020H
;液晶管脚定义:
RS EQU P2.3 //寄存器选择端,H数据,L指令
RW EQU P2.4 //H读,L写
EEE EQU P2.5 //串口模式下为读写操作使能端。E的下降沿锁定数据
RES EQU P2.6
PSB EQU P2.7 //H并,L串
;实时芯片管脚定义
RST EQU P1.5
SCL EQU P1.4 //SERIAL CLOCK INPUT
SDA EQU P1.3 //SERIAL DATA OUTPUT内部寄存器的地址
IICADD EQU 38H //IIC器件(DS1388) 内部寄存器的地址
IICDAT EQU 39H //IIC器件(DS1388) 内部寄存器的内容(读出或写入)
IICNUM EQU 3AH //IIC器件(DS1388) 的地址
MAIN: ;初始化时间,30-37H分别存放着时间的数据
MOV 30H, #00H ;1/100s
MOV 31H, #00H ;s
MOV 32H, #54H ;min
MOV 33H, #08H ;h
MOV 34H, #07H ;day of week
MOV 35H, #08H ;date
MOV 36H, #07H ;month
MOV 37H, #12H ;year
;CLR 7FH //小时:分钟:秒 中的冒号显示与否的标志
;============================================
;DS1388's initialization
SETB SCL
SETB SDA
CLR RST
NOP
SETB RST
NOP
MOV IICNUM,#11010000B //DS1388's address
MOV R0, #30H
MOV R1, #00H
MOV R2, #08H
TIME_INIT:
MOV IICADD, R1
MOV IICDAT, @R0
LCALL IIC_WRITE
LCALL DEL0
INC R0
INC R1
DJNZ R2, TIME_INIT
LCD_INIT: CLR RES
LCALL DEL0
SETB RES
LCALL DEL0
SETB PSB
LCALL DEL0
MOV A,#30H
LCALL WRITE_COM
LCALL DEL0
MOV A,#30H
LCALL WRITE_COM
LCALL DEL0
MOV A,#0CH
LCALL WRITE_COM
LCALL DEL0
MOV A,#01H
LCALL WRITE_COM
LCALL DEL0
MOV A,#06H
LCALL WRITE_COM
LCALL DEL0
;LCD_INIT FINISHED
SHOW:
MOV R5, #0FFFFH
MOV R0, #30H //读出DS1388的时间
MOV R1, #00H
MOV R2, #08H
READTIME:
MOV IICADD, R1
LCALL IIC_READ
MOV @R0, IICDAT
INC R0
INC R1
DJNZ R2, READTIME
MOV A, #80H
LCALL WRITE_COM
LCALL DEL0
MOV A, 37H //年份+"/"
LCALL NUMSHOW
MOV A, #2FH
LCALL WRITE_DATA
LCALL DEL0
MOV A, 36H //月份+"/"
LCALL NUMSHOW
MOV A, #2FH
LCALL WRITE_DATA
LCALL DEL0
MOV A, 35H //日期+"/"
LCALL NUMSHOW
MOV A, #85H
LCALL WRITE_COM
LCALL DEL0
MOV DPTR,#WORD_1
MOV R7, #4
MOV R6, #0
LCALL SHOW_CHINESE
MOV DPTR, #WORD_2
MOV R7, #2
MOV R6,34H //日期的数据传给R6
DEC R6 //减一是因为要从0开始数
MOV A, R6 //乘以2,因为每个汉字占两位
ADD A, R6
MOV R6, A
LCALL SHOW_CHINESE
MOV A, #91H //小时+":"
LCALL WRITE_COM
LCALL DEL0
MOV A, 33H
LCALL NUMSHOW
MOV A, #3AH
LCALL WRITE_DATA
MOV A, 32H //分钟+":"
LCALL NUMSHOW
MOV A, #3AH
LCALL WRITE_DATA
MOV A, 31H //秒
LCALL NUMSHOW
DJNZ R5, SHOW
RET
NUMSHOW: MOV B,A //十六进制数据转换为LCD可显示的ASCII码数据
ANL A,#0F0H
SWAP A
ADD A,#30H
LCALL WRITE_DATA
LCALL DEL0
MOV A,B
ANL A,#0FH
ADD A,#30H
LCALL WRITE_DATA
LCALL DEL0
RET
WRITE_COM:
CLR RS
LCALL DEL0
CLR RW
LCALL DEL0
SETB EEE
RLC A
MOV 00H,C
RLC A
MOV 01H,C
RLC A
MOV 02H,C
RLC A
MOV 03H,C
RLC A
MOV 04H,C
RLC A
MOV 05H,C
RLC A
MOV 06H,C
RLC A
MOV 07H,C
MOV A,20H
MOV P0,A
LCALL DEL0
CLR EEE
LCALL DEL0
RET
WRITE_DATA:
SETB RS
LCALL DEL0
CLR RW
LCALL DEL0
SETB EEE
RLC A
MOV 00H,C
RLC A
MOV 01H,C
RLC A
MOV 02H,C
RLC A
MOV 03H,C
RLC A
MOV 04H,C
RLC A
MOV 05H,C
RLC A
MOV 06H,C
RLC A
MOV 07H,C
MOV A,20H
MOV P0,A
LCALL DEL0
CLR EEE
LCALL DEL0
RET
;;;;;;;;;;;延时程序;;;;;;;;;;;;;
DEL0:MOV 20H,#2
DEL1:MOV 21H,#2
DEL2:MOV 22H,#25
DJNZ 22H,$
DJNZ 21H,DEL2
DJNZ 20H,DEL1
RET
;--------------------------------------------
;IIC总线(读,写操作)
;IIC_WRITE:
;IICNUM中存放要写入的元件的地址,IICADD中存放要写入的地址, IICDAT中存放要写入的数据
;IIC_READ:
;IICNUM中存放要读取的元件的地址,IICADD中存放要写入的地址, IICDAT中存放读取的数据
;Made by 651927693
;2012/08/08
;--------------------------------------------
IIC_WRITE:
;LCALL IIC_INIT
LCALL IIC_START
MOV A, IICNUM
LCALL IIC_WRITE_BYTE
;LCALL IIC_WRITE_ACK
LCALL IIC_ACK
JC IIC_WRITE
MOV A, IICADD
LCALL IIC_WRITE_BYTE
;LCALL IIC_WRITE_ACK
LCALL IIC_ACK
JC IIC_WRITE
MOV A, IICDAT
LCALL IIC_WRITE_BYTE
;LCALL IIC_WRITE_ACK
LCALL IIC_ACK
JC IIC_WRITE
LCALL IIC_STOP
RET
IIC_READ:
;LCALL IIC_INIT
LCALL IIC_START
MOV A, IICNUM
LCALL IIC_WRITE_BYTE
;LCALL IIC_WRITE_ACK
LCALL IIC_ACK
JC IIC_READ
MOV A, IICADD
LCALL IIC_WRITE_BYTE
;LCALL IIC_WRITE_ACK
LCALL IIC_ACK
JC IIC_READ
;RESTART
LCALL IIC_START
MOV A, IICNUM
ORL A, #01H
LCALL IIC_WRITE_BYTE
;LCALL IIC_WRITE_ACK
LCALL IIC_ACK
JC IIC_READ
LCALL IIC_READ_BYTE
;LCALL IIC_READ_ACK
MOV IICDAT, A
LCALL IIC_STOP
RET
;IIC_INIT:
; SETB SDA
; SETB SCL
; NOP
; RET
;=====================================================
IIC_START:
SETB SDA
NOP
SETB SCL
NOP
NOP
NOP
NOP
NOP
CLR SDA
NOP
NOP
NOP
NOP
NOP
CLR SCL
RET
;=====================================================
IIC_STOP:
CLR SDA
NOP
SETB SCL
NOP
NOP
NOP
NOP
NOP
SETB SDA
NOP
NOP
NOP
NOP
NOP
RET
;=====================================================
IIC_WRITE_BYTE:
MOV B, #08H
IIC_WRITE_BYTE0:
RLC A
MOV SDA, C
NOP
SETB SCL
NOP
NOP
NOP
NOP
NOP
CLR SCL
NOP
DJNZ B, IIC_WRITE_BYTE0
RET
;====================================================
IIC_READ_BYTE:
MOV B, #08H
CLR A
SETB SDA
NOP
IIC_READ_BYTE0:
SETB SCL
NOP
NOP
NOP
NOP
NOP
MOV C, SDA
RLC A
CLR SCL
NOP
NOP
NOP
NOP
NOP
DJNZ B, IIC_READ_BYTE0
RET
;====================================================
MOV B, #0FFH
IIC_WRITE_ACK:
SETB SDA
SETB SCL
NOP
JB SDA, DEL_ACK
CLR SCL
NOP
RET
;=============================
DEL_ACK:
DJNZ B, $
CLR SCL
NOP
RET
;====================================================
IIC_READ_ACK:
CLR SCL
NOP
CLR SDA
NOP
SETB SCL
NOP
RET
;=====================================================
IIC_ACK: SETB SDA
NOP
NOP
SETB SCL
NOP
NOP
NOP
JB SDA,IIC_ACK0
CLR C
SJMP IIC_ACK_END
IIC_ACK0: SETB C
SJMP IIC_ACK_END
IIC_ACK_END: CLR SCL
RET
;=====================================================
;DPTR
;R7表示要显示的汉字个数*2
;A表示从第几个汉字开始显示
;=====================================================
SHOW_CHINESE:
MOV A, R6
MOVC A, @A+DPTR
LCALL WRITE_DATA
LCALL DEL0
INC DPTR
DJNZ R7, SHOW_CHINESE
LCALL DEL0
RET
;=====================================================
WORD_1:
DB "星期"
WORD_2:
DB "一二三四五六日"
END