PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   MPASM (http://www.picvietnam.com/forum/forumdisplay.php?f=34)
-   -   [Help] Đọc, ghi trong DS1307 theo I2C (http://www.picvietnam.com/forum/showthread.php?t=31467)

alibaba123 12-12-2012 02:51 AM

[Help] Đọc, ghi trong DS1307 theo I2C
 
Trích:

SDA bit p2.1
SCL bit p2.0
_GetTime:
;===== Đoc du lieu tu DS1307 =====
MOV A,#0D0H
LCALL START
LCALL SEND
MOV A,R7
LCALL SEND
LCALL START
MOV A,#0D1H
LCALL SEND
LCALL RECV
//LCALL GIAI_NEN
//MOV P3,R4
LCALL STOP
RET

_SetTime:
MOV A,#0D0H
LCALL START
LCALL SEND
MOV A,R7
LCALL SEND
MOV A,R5
LCALL SEND
LCALL STOP
RET
;=================================
START:
CLR SCL
SETB SDA
NOP
NOP
NOP
SETB SCL
CLR SDA
NOP
NOP
NOP
RET
;=================================
STOP:
NOP
NOP
NOP
CLR SDA
SETB SCL
NOP
SETB SDA
NOP
NOP
NOP
CLR SCL
RET
;=================================
RECV:
MOV R6,#08
BACK_RECV:

SETB SCL
NOP
NOP
NOP
MOV C,SDA
NOP
NOP
NOP
CLR SCL
NOP
NOP
NOP
MOV A,R7
RLC A
MOV R7,A

DJNZ R6,BACK_RECV

SETB SDA
NOP
NOP
NOP
SETB SCL
NOP
NOP
NOP
CLR SCL
NOP
NOP
NOP
RET
;================================
SEND:
MOV R6,#8
BACK_SEND:

CLR SCL
NOP
NOP
NOP
RLC A
MOV SDA,C
SETB SCL
NOP
NOP
NOP
CLR SCL
NOP
NOP
NOP

DJNZ R6,BACK_SEND

SETB SDA
NOP
NOP
NOP
SETB SCL
NOP
NOP
NOP
CLR SCL
NOP
NOP
NOP
RET
;=================================
Pro nào có thể giải thích nguyên lý cho em được không, nhất là chỗ CT con SEND với RECV ạ?
Em cảm ơn nhìu nhìu


Múi giờ GMT. Hiện tại là 05:50 AM.

Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam