Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[51] Code to implement in proteus and confused to connect it.

Status
Not open for further replies.

Karthikeswar

Newbie level 3
Joined
Apr 3, 2017
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
37
This code is to implement DIGITAL CLOCK using rtc DS1307 and 8051.
But I'm confused that whether code is wrong or connections:roll: Screenshot (79).png

Code:
ORG 0000H
        ACALL  DELAY_200ms       ;RTC NEEDS 200ms UPON POWER UP
        SETB P3.6
        CLR P3.6
;====TURNING ON  THE  RTC=========================================
        MOV DPTR,#10        ;R0=0AH,REG. A ADDRESS
        MOV A,#20H        ;010 IN D6-D4 TO TURN ON OSC.
        MOVX  @DPTR,A        ;SEND IT TO REGISTER A OF RTC

;====SETTING THE  TIME  MODE======================================
        SETB P3.6
        CLR P3.6
        MOV DPTR,#11        ;REG. B ADDRESS
        MOV A,#83H        ;BCD,24 HRS ,DAYLIGHT SAVING
        MOVX @DPTR,A        ;SEND IT TO REG R


;====SETTING THE TIME=========================================
        SETB P3.6
        CLR P3.6
 OUT1:      ACALL DELAY
        MOV DPTR,#00        ;POINT TO SECONDS ADDRESS
        MOV A,#01H        ;SECONDS=00H
        MOVX @DPTR,A        ;SET SECONDS
        SETB P3.6
        CLR P3.6
        ACALL DELAY
        MOV DPTR,#02        ;POINT TO MINUTES ADDRESS
        MOV A,#03H        ;MINUTES=O00H
        MOVX @DPTR,A        ;SET MINUTES
        
        SETB P3.6
        CLR P3.6
        ACALL DELAY
        MOV DPTR,#04        ;POINT TO HOURS ADDRESS
        MOV A,#02H        ;HOURS=00H
        MOVX @DPTR,A        ;SET HOURS

        SETB P3.6
        CLR P3.6
        ACALL DELAY
        MOV DPTR,#11        ;REG B ADDRESS
        MOV A,#03        ;D7=0 OF REG B TO ALLOW UPDATE
        MOVX @DPTR,A        ; SEND IT TO REGISTER B
        SETB P3.6        ;DISABLING THE WRITE SIGNAL
       
;====INITIALSING LCD============================================
        
        MOV A,#80H
        ACALL command
        MOV A,#38H
        ACALL command
        MOV A,#0EH
        ACALL command
        MOV A,#01H
        ACALL command
        ACALL  delay
        MOV A,#80H
        ACALL command
        MOV DPTR,#LINE_1
      NXT1: MOV A,#00H
        MOVC A,@A+DPTR
        JZ OUTx
        ACALL DISPLAY        ;/--("TIME:")
        INC DPTR
        SJMP NXT1

;====READING TIME==============================================

outx:
AGAIN1:     MOV DPTR,#04
        SETB P3.7
        CLR P3.7        ;SET READ
        ACALL DELAY
        MOVX A,@DPTR        ;READ SECONDS
        MOV P0,A
        ACALL DISPLAYNUM
        MOV A,#':'
        ACALL DISPLAY
        
        MOV DPTR,#02        ;POINT TO SEC. LOC.
        SETB P3.7
        CLR P3.7        ;SET READ
        ACALL DELAY
        MOVX A,@DPTR        ;READ SECONDS
        MOV P0,A
        ACALL DISPLAYNUM
        MOV A,#':'
        ACALL DISPLAY
        

        MOV DPTR,#00        ;POINT TO SEC. LOC.
        SETB P3.7
        CLR P3.7        ;SET READ
        ACALL DELAY
        MOVX A,@DPTR        ;READ SECONDS
        MOV P0,A
        ACALL DISPLAYNUM
        ACALL DELAY_1SEC
        MOV A,#86H        ;GOING BACK TO 1ST LINE & 6TH POSITION
        ACALL command
        SJMP AGAIN1
     
;====LCD COMMAND & DATA SUBROUTINE=============================      

command:        acall ready
        mov p1,a
        clr p3.3
        clr p3.4
        setb p3.5
        clr p3.5
        ret
ready:        setb p1.7
        clr p3.3
        setb p3.4
check1:        clr p3.5
        setb p3.5
        jb p1.7,check1
        ret
display:        acall ready
        mov p1,a
        setb p3.3
        clr p3.4
        setb p3.5
        clr p3.5
        ret

DISPLAYNUM:
        MOV B,A
        SWAP A
        ANL A,#0FH
        ORL A,#30H
        
        ACALL DISPLAY
        MOV A,B
        ANL A,#0FH
        ORL A,#30H
        ACALL DISPLAY
        RET 
        
;====DELAY SUBROUTINE======================================
;====200MSEC SUBROUTINE======================================
DELAY_200ms:
        MOV R1,#4
HERE1:        MOV R2,#250
HERE:        NOP
        NOP
        DJNZ R2,HERE
        DJNZ R1,HERE1
        RET
;====SIMPLE DELAY==========================================

delay:        
        MOV R1,#10
        HERE11:        MOV R2,#0FAH
        HEREX:  NOP
        NOP
        DJNZ R2,HEREX
        DJNZ R1,HERE11
        RET
;====ONE SECOND DELAY===================================

DELAY_1SEC:     MOV TMOD,#01        ;Timer 0, 16-bitmode
        mov r1,#0Ah
xx2:        mov r0,#64h
        
xx1:        MOV TL0,#0FDh        ;TL0=0, the low byte
        MOV TH0,#92h        ;TH0=0, the high byte
        SETB TR0        ;Start timer 0
AGAIN:        JNB TF0,AGAIN
        djnz r0,xx1
        djnz r1,xx2        ;Monitor timer flag 0
        CLR TR0        ;Stop the timer 0
        CLR TF0        ;Clear timer 0 flag
        sjmp $

;====

org 350h
    LINE_1: DB 'TIME: ',0

    END
 
Last edited by a moderator:

Hi,

I recommend to read the existing discussions about 8051 interfacing with DS1307.
Schematics and code available.

Klaus
 

I have already gone through them but not useful.
I need it in assembly language and not in C.
 

Hi,

Assember or C ... you will need to configure the I2C periferal...I don´t see this in your code.

I´m not familiar with 8051, therefore maybe I don´t understand it... but I can´t find out how your I2C communication should work.

Klaus
 
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
8051 has no dedicated I2C interface, must be serviced by bit-banging.
Then can I have entire code for digital clock which displays time.
If possible circuit too.
 

For me it's too late. If you had asked me 30 years ago, I might have considered to write 8051 assembly code. But at that time I started to use C-compiler.
 

Hi,

Then can I have entire code for digital clock which displays time.
If possible circuit too.

nice try ;-)

Can I have a new car?
If possible fuel too.

***
It seems you simply are too lazy to do a simple search in this forum.

This is just the 4´th hit (today) if you do a forum serach for "ds1307 8051"
https://www.edaboard.com/threads/345563/#post1475026

then go to first link. --> schematic and assembler code.

Klaus
 

Hold a second bro.
I am not too lazy.
I have searched everywhere but I didn't get assembly code instead all of them are stick up wit c code.
Even if I get assembly code It is not programmed with 8051.
I have tried the link even before you send it but it's too complex and not supported with MCU 8051 IDE where I program or create hex file.
 

Before this turns into an argument...

If you isolate the code in post #1 you will see the LCD routines (although poorly commented) and with a little research you can see how the interface to the RTC works. You do not need I2C support in hardware, especially if there is only one I2C device on the bus because you do not have to implement the full protocol.

I haven't programmed 8051 for over 20 years, in fact I think it might have been an 8035 I used last so I'm certainly not well experienced with the instruction set or hardware but such a simple task should only take a few hours at most. Even if you look at code written in 'C' you can see the program flow and convert it to assembly language easily.

Brian.
 

Hi,

Hold a second bro.
I am not too lazy.
I have searched everywhere but I didn't get assembly code instead all of them are stick up wit c code.
Even if I get assembly code It is not programmed with 8051.
I have tried the link even before you send it but it's too complex and not supported with MCU 8051 IDE where I program or create hex file.

It seems you didn´t even follow the link.
It leads you to a page.. I made this screenshot:
* there is the schematic
* it clearely tells "8051 code for DS1307"
* it gives assembler code.
DS1307.PNG
What more do you expect?

If you want someone to do your job, then you should pay him.

Klaus
 

In addition to the comments above, there are details that should be noted in your code. For the purpose of simulation in an ideal scenario, even if it works in Proteus, in the real world you would certainly face problems, depending on your hardware (pullup resistors, crystal frequencies, routing, etc ...). The code snippet below generates a high level pulse with only one machine cycle:

Code:
        SETB P3.6
        CLR P3.6

Even knowing that the 8051 microcontroller core has a CISC architecture (meanning that run few clock cycles per instruction), the above pulse width may be too small, not enough to ensure a stable level for a sufficient amount of time. Anyway, you should really go a little deeper into your work, even because in ISIS itself it is possible with a little creativity to debug the program variables, and even to monitor the waveforms to try to determine exactly what is happening.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top