;以上配置完成后,PCF8563的INT脚产生周期为1s,脉冲宽度(低电平)约为15ms的脉冲中断信号。
;②PCF8563当前时间设定子程序如下:
PCFWR: MOV 51H,#00H ;启动时钟
MOV 52H,#11H ;定时器为中断模式,脉冲形式
MOV 53H,MINU ;将秒至年的时间写入发送缓冲区
MOV 54H,SECO
MOV 55H,HOU
MOV 56H,DAY
MOV 57H,WEEK
MOV 58H,MONTH
MOV 59H,YEAR
MOV SLA,#0A2H ;取写器件地址
MOV NUMBYT,#10 ;写字节数
MOV MTD,#00H ;写入8563寄存器首地址为00H
LCALL WRNBYT ;写入8563
RET
;③读出时钟芯片当前值子程序设计
PCFRD: MOV MTD,#02H ;读时钟寄存器首字节地址02H
MOV SLA,#0A2H ;取写器件地址
MOV NUMBYT,#1 ;写字节数
LCALL WRNBYT ;写8563
MOV SLA,#0A3H ;取读器件地址
MOV NUMBYT,#7 ;读七个时钟信息
LCALL RDNBYT ;读取时间并放入缓冲区
MOV A,40H ;取滗字节
ANL A,#7FH ;屏蔽无效位
MOV MINU,A ;送秒寄存器
MOV A,41H ;取分字节
ANL A,#7EH ;屏蔽无效位
MOV MINU,A ;送分寄存器
MOV A,42H ;取小时字节
ANL A,#3FH ;屏蔽无效位
MOV HOU,A ;送时寄存器
MOV A,43H ;取天字节
ANL A,#3FH ;屏蔽无效位
MOV DAY,A ;送天寄存器
MOV A,44H ;取星期字节
ANL A,#07H ;屏蔽无效位
MOV WEEK,A ;送星期寄存器
MOV A,45H ;取月字节
ANL A,#1FH ;屏蔽无效位
MOV MONTH,A ;送月寄存器
RET
;系统程序流程如图4所示,中断服务程序如5所示。
; Send 8-bits in ACC to the slave
WRNBYT:
MOV BITCNT,#8 ; 8 bits in a byte
SETB MDE ; to enable SDATA pin as an output
CLR MCO ; make sure that the clock line is low
SENDBIT:
RLC A ; put data bit to be sent into carry
MOV MDO,C ; put data bit on SDATA line
SETB MCO ; clock to send bit
CLR MCO ; clear clock
DJNZ BITCNT,SENDBIT ; jump back and send all eight bits
CLR MDE ; release data line for acknowledge
SETB MCO ; send clock for acknowledge
JNB MDI,NEXT ; this is a check for acknowledge
SETB NOACK ; no acknowledge, set flag
NEXT: CLR MCO ; clear clock
RET
;____________________________________________________________________
; RCVBYTE
; receives one byte of data from an I2C slave device. Returns it in A
RDNBYT:
MOV BITCNT,#8 ; Set bit count.
CLR MDE ; to enable SDATA pin as an input
CLR MCO ; make sure the clock line is low
RCVBIT:
SETB MCO ; clock to recieve bit
CLR MCO ; clear clock
MOV C,MDI ; read data bit into carry.
RLC A ; Rotate bit into result byte.
DJNZ BITCNT,RCVBIT ; Repeat until all bits received.
; recieved byte is in the accumulator
SETB MDE ; Data pin =Output for NACK
SETB MDO ; Send NACK (always send NACK for
; last byte in transmission)
SETB MCO ; Send NACK clock.
CLR MCO
RET
SENDDATA:
; send start bit
CALL STARTBIT ; acquire bus and send slave address
; send slave address
MOV A, WRITEADD ;写入PCF8563
CALL SENDBYTE ; sets NOACK if NACK received
JB NOACK, STOPSEND ; if no acknowledge send stop
; send OUTPUT byte
MOV A, SLAVEADD
CALL SENDBYTE
MOV A, OUTPUT
CALL SENDBYTE ; sets NOACK if NACK received
STOPSEND:
CALL STOPBIT ; sends stop bit
JNB NOACK, SENDRET ; if slave sends NACK send error
SETB ERR ; sets the error flag
SENDRET:
RET
;____________________________________________________________________
; RCVDATA
; receives one or more bytes of data from an I2C slave device.
RCVDATA:
; send start bit
CALL STARTBIT ; acquire bus and send slave address
; send slave address
MOV A, READADD ;读取PCF8563的值
CALL SENDBYTE ; sets NOACK if NACK received
MOV A, SLAVEADD
CALL SENDBYTE
JB NOACK, STOPRCV ; Check for slave not responding.
CALL RCVBYTE ; Receive next data byte.
MOV INPUT,A ; Save data byte in buffer.
STOPRCV:
CALL STOPBIT
JNB NOACK, RCVRET ; if slave sends NACK send error
SETB ERR ; sets the error flag
RCVRET:
RET
SENDBYTE ; Send 8-bits in ACC to the slave
RCVBYTE; receives one byte of data from an I2C slave device
不知道这样写对不对,但是现在读出的数据都是00
先送起始位,然后是读写地址,然后是从器件内部地址,然后是数据
应该没问题吧
就是搞不定
PCF8563的读地址和写地址是0A2H,和0A3H。
我不知道上面的应该怎么设。
也就是SLAVEADD应该是多少?