Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/13/99 19:48
Read: times


 
#1054 - RE: ds1302 program please help
Here is the program module for Keil C51 written in assembly language.

;----------------------------------------------------------------------
; Program name : RTCC.A51
; Author : Urbanc Franc
; Date : 29.jul.1998
; Version : V 2.1
; Compiler : Keil A51 V5.04
; Processor : 8051 and derivates
;
; - Low-Level RTCC DS1302 communication routines
;
; (In C51 V5.10 all routines with parameter passing in registers
; are flagged with '_' , all others are not.)
;
;----------------------------------------------------------------------

$NOMOD51
$INCLUDE (C:C51ASMREG550.INC)

NAME RTCC_IO

?PR?_RTCC_WRITE?RTCC_IO SEGMENT CODE INBLOCK
?PR?_RTCC_READ?RTCC_IO SEGMENT CODE INBLOCK
?PR?_BCD2BIN?RTCC_IO SEGMENT CODE INBLOCK
?PR?_BIN2BCD?RTCC_IO SEGMENT CODE INBLOCK
?PR?VKLOPI_RTCC?RTCC_IO SEGMENT CODE INBLOCK
?PR?IZKLOPI_RTCC?RTCC_IO SEGMENT CODE INBLOCK


GND bit P3.3 ;RTCC modul pin 5 - masa napajanja
SCLK bit P2.2 ;RTCC modul - serial clock
I_O bit P2.3 ;RTCC modul - data I/O
RST bit P2.4 ;RTCC modul - reset

RTCCPORT EQU P2 ;RTCC vrata so P2
RTCCPINS EQU 01ch ;RTCC pini na P2

public RST,SCLK,I_O,GND

$REGUSE _rtcc_write (R1,A,PSW)
$REGUSE _rtcc_read (R7,R1,A,PSW)
$REGUSE _bcd2bin (R7,A,B,PSW)
$REGUSE _bin2bcd (R7,A,B,PSW)
$REGUSE vklopi_rtcc ()
$REGUSE izklopi_rtcc ()

PUBLIC _rtcc_read
PUBLIC _rtcc_write
PUBLIC _bin2bcd
PUBLIC _bcd2bin
PUBLIC vklopi_rtcc
PUBLIC izklopi_rtcc

;----------------------------------------------------------------------

RSEG ?PR?_RTCC_WRITE?RTCC_IO

;void rtcc_write (unsigned char adr, unsigned char dta)

_rtcc_write: clr SCLK ;SCLK must be low at start
mov a,r7 ;adrs passed in R7
mov r1,#8 ;8 bits to send
setb RST ;enable shift register logic
rtcc_wr1: clr SCLK
rrc a ;LSB first
mov I_O,c ;put bit on pin
setb SCLK ;SCLK rising edge - write operation
djnz r1,rtcc_wr1 ;loop until done
;
mov a,r5 ;dta passed in R5
mov r1,#8 ;8 bits to send
rtcc_wr2: clr SCLK ;emit clock pulse
rrc a ;LSB first
mov I_O,c ;put bit on pin
setb SCLK ;SCLK rising edge - write operation
djnz r1,rtcc_wr2 ;loop until done
clr RST ;drop RST, stop transmission
ret

;----------------------------------------------------------------------

RSEG ?PR?_RTCC_READ?RTCC_IO

;unsigned char rtcc_read (unsigned char adr)

_rtcc_read: clr SCLK ;SCLK must be low at start
mov a,r7 ;adrs passed in R7
orl a,#01h ;set command RD bit
mov r1,#8 ;8 bits to send
setb RST
rtcc_rd1: clr SCLK
rrc a ;LSB first
mov I_O,c ;put bit on pin
setb SCLK ;SCLK rising edge - write operation
djnz r1,rtcc_rd1 ;loop until done
;
setb I_O ;set I_O as input
mov r1,#8 ;8 bits to receive
rtcc_rd2: clr SCLK ;SCL falling edge - read operation
mov c,I_O ;pick bit off of pin
rrc a
setb SCLK ;SCLK high
djnz r1,rtcc_rd2 ;more bits to receive?
clr RST ;drop RST, stop transmission
mov r7,a ;return data in R7
ret

;----------------------------------------------------------------------

RSEG ?PR?VKLOPI_RTCC?RTCC_IO

;void vklopi_rtcc ()

vklopi_rtcc: anl RTCCPORT,#NOT RTCCPINS
clr GND ;RTCC GND pin se nahaja na P3
ret

;----------------------------------------------------------------------

RSEG ?PR?IZKLOPI_RTCC?RTCC_IO

;void izklopi_rtcc ()

izklopi_rtcc: setb GND
orl RTCCPORT,#RTCCPINS
ret

;----------------------------------------------------------------------

RSEG ?PR?_BIN2BCD?RTCC_IO

;unsigned char bin2bcd (unsigned char dta)

_bin2bcd: mov a,r7
mov b,#0ah
div ab
swap a
anl a,#0f0h
orl a,b
mov r7,a
ret

;----------------------------------------------------------------------

RSEG ?PR?_BCD2BIN?RTCC_IO

;unsigned char bcd2bin (unsigned char dta)

_bcd2bin: mov a,r7
swap a
anl a,#0fh
mov b,#0ah
mul ab
xch a,r7
anl a,#0fh
add a,r7
mov r7,a
ret

;----------------------------------------------------------------------

end


List of 4 messages in thread
TopicAuthorDate
ds1302 program please help            01/01/70 00:00      
RE: ds1302 program please help            01/01/70 00:00      
RE: ds1302 program please help            01/01/70 00:00      
RE: ds1302 program please help            01/01/70 00:00      

Back to Subject List