![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) | |
|
Hi esconele,
Quote:
I looked back at the coding I made for M6242B and found that several things that you have not done, yet. I marked them with "<<<<<<" in the code I posted. 1. hold/stop the RTC before changing its registers or operating mode 2. wait the required time(I mostly waited longer) that specified in the datasheet 3. only issue commands to the RTC when it can accepts it(not busy) And finally, do yourself a favour. Write your code properly with lots of comments so even after many years, the codes still means something when you read it again. Here is part of my code that I have used. 11.0592MHz for MCU and 32.768KHz for RTC. The codes is different to what you'll need as I also have external EPROM,SRAM & LCD connected to the databus too, so the RTC registers are memory mapped to appear as memory locations. Code:
;#################################################################
;
;SUBROUTINES - rtc_init
;
;FUNCTION: Read data from 8052 time/date buffer and put
; into RTC registers
;
; ENTRY: new RTC timing data ready in 80C32 RAM
; EXIT: nil
; USING: a,r0,r1
;PRESERVE: a,r0,r1
; DESTROY:
; AFFECT: flags
;
; CALLING: wait_250us
;
;#################################################################
;
rtc_init:
push a
push 00h
push 01h
;
clr p2.7
mov r0,#rtc_d ;select rtc reg D
mov a,#00000001b ;data to hold RTC count <<<<<<<<<<
movx @r0,a ;send to RTC
;
call wait_250us ;wait <<<<<<<<<<
$rtc1: movx a,@r0 ;read back status
jb acc.1,$rtc1 ;is RTC busy <<<<<<<<<<
jb acc.1,$rtc1
;
mov r0,#rtc_f ;set address of RTC F register
mov a,#00000101b ;select 24 Hour mode
movx @r0,a ;send to RTC with Reset Bit set
call wait_250us
mov a,#00000100b
movx @r0,a ;lower Reset bit
;
;now check whether we can put data into RTC timer registers
;
mov r0,#rtc_d ;status register
$rtc2: call wait_250us
movx a,@r0 ;read from RTC status register
jb acc.1,$rtc2 ;loop until RTC not busy
jb acc.1,$rtc2
;
;Now RTC not busy
;
mov r1,#rtc_sec ;start of time data register
;
mov a,cur_sec ;get curent seconf value
;
;
;
__________________
L.Chung |
||
|
|
|
|
|
(permalink) |
|
sir,
i cheked the oscillator its working and the std.p pin is low all times data is also there on data pins but counter doesnts give the incremented time why pls help me thank ypu |
|
|
|
|
|
|
(permalink) |
|
sir,
i've worked a lot on this but still i'm not getting the results where i'm wrong ? data is there on chip data pins i checked with oscilloscope but when i read it its not giving why pls help me here is the code pls suggest me the solution org 0000h main: call INIT_MT LOOP: CALL FINE1 CALL DISPLAY_TIME SJMP LOOP INIT_MT: PUSH ACC PUSH 00H PUSH 01H MOV R0,#0D0H MOV A,#00000001B ;; HOLD=1 CALL TWRITE CALL WAIT250US $RTC1:MOVX A,@R0 JB ACC.1,$RTC1 ;CHECK FOR BUSY BIT JB ACC.1,$RTC1 MOV R0,#0F0H MOV A,#00000101B ;24 HR MODE,RESET=1 CALL TWRITE CALL WAIT250US MOV A,#00000100B ;24 HR MODE RESET=0 CALL TWRITE ;CALL WAIT250US MOV R0,#0D0H $RTC2:CALL WAIT250US CALL TWRITE JB ACC.1,$RTC2 ;CHECK FOR BUSY JB ACC.1,$RTC2 MOV R1,#50H ;HR10 REG ADDRESS MOV A, #00000001B ; SET HR10 = 1 CALL TWRITE CALL WAIT250US MOV R1,#40H ;HR1 REG ADDRESS MOV A,#00000010B ;SET HR1 = 2 CALL TWRITE CALL WAIT250US MOV R1,#40H ;MIN10 ADDRESS MOV A, #00000100B ;SET MIN10 = 4 CALL TWRITE CALL WAIT250US MOV R1,#30H ;MIN1 ADDRESS MOV A,#00000101B ;SET MIN1 =5 CALL TWRITE RET FINE1: MOV R1,#060H ;READ DAY1 REG LCALL READRTC ANL A,#0FH ;ONLY LOWER BYTE MOV 3FH,A MOV R1,#070H ;READ DAY10 REG LCALL READRTC ANL A,#03H ;ONLY LOWER 2 BITS MOV 3EH,A MOV R1,#020H ;READ MIN1 REG LCALL READRTC ANL A,#0FH ;LOWER BYTE ONLY MOV 3DH,A MOV R1,#030H ;READ MIN10 REG LCALL READRTC ANL A,#07H ;LOWER 3 BITS MOV 3CH,A MOV R1,#040H ;;HOUR1 REG LCALL READRTC ANL A,#0FH MOV 3BH,A MOV R1,#050H ;HOUR10 REG READ LCALL READRTC ANL A,#03H MOV 3AH,A MOV R1,#080H ;MONTH1 REG READ LCALL READRTC ANL A,#0FH MOV 39H,A MOV R1,#090H MONTH10 REG READ LCALL READRTC ANL A,#01H MOV 38H,A MOV R1,#0A0H ;READ YEAR1 READ LCALL READRTC ANL A,#0FH MOV 37H,A MOV R1,#0B0H ;READ YEAR1 REG LCALL READRTC ANL A,#0FH MOV 36H,A RET ;AS PER TIMING DIAGRAM TWRITE AND READRTC FUNCTIONS ARE WRITTEN TWRITE: clr CS0 clr CS1 nop nop nop nop SETB CS1 nop setb CS0 nop clr CS0 nop CLR TWR MOVX @R1,A CALL WAIT250US NOP SETB TWR nop nop CLR CS1 RET READRTC: clr CS1 clr CS0 nop nop nop nop SETB CS1 nop setb CS0 nop nop nop CLR CS0 nop CLR TRD NOP MOV A,@R1 nop CALL WAIT250US SETB TRD nop nop CLR CS1 RET WAIT250US:MOV 34H,#07DH DF1: DJNZ 34H,DF1 RET |
|
|
|
|
|
|
(permalink) | |
|
Quote:
The ALE, WR and RD signals already existed as standard signals in the 89C52, so why would you want to generate it yourself. You just made your life so much difficult. With the connections shown, you can use the same method in my code to access the registers on the RTC. Good luck to you.
__________________
L.Chung Last edited by eblc1388; 17th May 2006 at 08:47 PM. |
||
|
|
|
|
|
(permalink) |
|
sir,
thank you for helping me. but in your code you are not doing anything with RD WR AND ALE pins but in datasheet it is ghiven that there should be high to low high transaction on WR AND RD pins while writing and reading and CS0 should be low can i use the ffunctions i've written for reading and writing purpose or your code will give the results.thanks a lot sir |
|
|
|
|
|
|
(permalink) |
|
Connect the WR' pin to the WR' pin of the 8051, the RD' pin to the RD' pin of the 8051, and enable the RTC. On memory, there is a CE' pin which must be grounded in order for the chip to be enabled.
__________________
-=: The best low-priced components to troubleshoot with are the speaker and the LED :=- |
|
|
|
|
|
|
(permalink) | |
|
Quote:
You have to study the 8051 datasheet and familiar yourself with how the MOVX instruction works. The attached image would help you along.
__________________
L.Chung |
||
|
|
|