![]() |
![]() |
![]() |
|
|
|||||||
| 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) |
|
Experienced Member
|
hello everybody,
i'm interfacing MSM6242B ITS A RTC WITH at89c52 FOR DISPLAYING TIME AND DATE ON LCD IN 00:00:00 DD:MM:YY FORMAT HERE I'VE CONNECTION LIKE THIS FOR MSM6242B STD.P IS OPEN ALE =VDD A0-A3 ARE CONNECTED TO PORT2 P2.4_P2.7 D0-D3 ARE CONNECTED TO PORT2 P2.0-P2.3 TRD-P0.7 TWR-P0.6 CS0-P0.5 CS1-P0.4 CODE: MOV A,#0FH MOV P2,A ;MAKING PORT2 P2.0-P2.3 INPUT PINS MOV A, #00H MOV P2,A RCALL READRTC ;OTHER REGISTERS LIKE MINUTES,HRS.... ARE READ AS SAME READRTC: SETB CS1 CLR CS0 CLR TRD MOV VALUE,P2 SETB TRD SETB CS0 CLR CS1 RET BUT ITS NOT GIVING THE RESULTS ALSO I TRIED TO WRITE TO RTC BUT ITS NOT WORKING .AND IS IT NECESSORY TO WRITE TO D,E AND F REGISTERS PLS HELP ME IF ANY ONE HAVE ANY IDEA ABOUT THIS PLS REPLY THANK YOU. |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Do you need pullup resistors on the PORT 0 pins? They probably are open drain outputs, but you knew that, right?
Writinga 0x0F to Port 2 followed by writng a 0 to port 2 looks a bit suspicious. Are you sure that is waht you wanted to do? |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
sir,
actually first i wanted to make port2 lower bit as input port and then after i want to load seconds register address which is 00 for first and then i'm taking input from lower bit of port2 even if i do like this mov a,#0fh mov p2,a ;;; making port2 lower byte as input mov address,#00h call readrtc ;; readrtc: mov p2,address clr trd mov value,p2 setb trd ret then also its not giving the results i've given pull up to port0 what about cs0 and cs1 pins these pins are setted to high only and ALE of RTC is connected to VDD and is it necessory to write to D,E,F registers of RTC MSM6242 pls help me |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
I'm having a hard time understanding what you are doing. This is not uncommon when there is no schematic diagram. Natural languages are very poor methods for describing circuits.
About one thing I am quite certain though, connecting ALE to Vdd sounds like a really bad thing to do. A peripheral device with a multiplexed bus needs the falling edge of ALE to define a valid register address. ALE won't go low in your circuit. |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
sir,
actually in datasheet of msm6242b it is given that we can connect ALE to VDD thats why i've made connections like this i've check the datapins for both at89c52 and msm6242b and data is there on data pins but when i read the data for respective registers it gives only that number which i've written last to rtc like if i've written mov addr,#00h ; addres of second1 register mov data,#03h setb cs1 clr cs0 mov p2,addr clr twr mov p2,data setb twr setb cs0 clr cs1 and now if i read data from rtc like mov addr,#01h ;address of second2 register setb cs1 clr cs0 mov p2,addr clr trd mov data,p2 setb trd setb cs0 clr cs0 then it gives number 3 for every other registers what connection should be make to ALE pin of rtc kindly give me any sample code for this when writing or reading rtc what status should be there on cs1 and cs0 pins what i'm doing is correct or wrong pls suggest me the solution thank you |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
It sounds like the RTC can be interfaced to different types of processors. Some of the processors have a multiplexed address/data bus and some processors have separate address/data busses. If the address and data busses are separate then tying ALE to Vdd may be appropriate. You are not using the actual address/data bus of the AT89C52, but are using a port to synthesize a bus transaction. You need to do two things:
1. Understand how the AT89C52 creates a bus transaction for reading and writing external memory. You want to mimic theses signals with port pins, but at a much slower rate. 2. Understand how to configure the RTC as if you were using the actual AT89C52 bus transactions. Then using the port pins should look exactly the same, except slower. The problem that you describe sounds like not being able to get a register address into the chip, so you always read back the content of the default address which is the same as the last thing you wrote. |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
sir,
herewith i've attached ckt diagram for msm6242 and 89c52 with the same ckt one of my frend wrote a program and getting time and date but i'm not getting where i'm wrong i'm going in the same way as frend only the differenc in ckt is i'm using 32.78khz crystal for rtc and 12Mhz for 89c52 whereas frend used 4Mhz for rtc and 12 Mhz for 89c52 should i increase the crystal value but recomended value is 32.78khz and is it necessory to give high to low pulse on cs0 and cs1 pins for reading and writing pls suggest me the solution thank you. |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Do you know how to read the timing diagram in Figure 4 of the MSM6242B datasheet? Have you complied with the setup and hold times required of CS1 and CS0, and can you confirm this with an oscilliscope?
To make a valid transaction you need to study the timing diagrams in the datasheet. As I see it you need to take CS1 high for the whole transaction. You need 1 usec = 1000 nsec before the address bits and CS0 change. How do you ensure that? After the transaction is complete there is a address hold time before CS1 goes low. How do you ensure that? I seriously doubt that your friend used 4 MHz as the crystal for the RTC. You realize that this part is obsolete and not recommended for new designs, right? Last edited by Papabravo; 14th May 2006 at 05:26 PM. |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
sir,
now i connected ALE PIN OF RTC TO P0.4 AND IN CODE WHEN WRITING ADDRSS I'VE GIVEN HIGH TO LOW TRANSACTION TO THIS PIN BUT STILL ITS NOT GIVING THE RESULTS PLS TELL ME WHERE I'M WRONG WHAT I'M DOING IS LIKE THIS INITRTC: MOV A,#0F5H ;HOLD=1;24/12=1 CALL TWRITE MOV A,#0F4H ;HOLD=0;24/12=1 CALL TWRITE MOV A,#0E0H CALL TWRITE MOV A,#D4H ;IRQ=1 CALL TWRITE RET READALL: MOV A,#00H ;SECOND1 REG ADDRESS CALL READRTC ANL A,#0FH MOV 3FH,A MOV A,#10H ;SECOND10 REG ADDRESS CALL READRTC ANL A,#07H MOV 3EH,A RET TWRITE: SETB CS1 CLR CS0 SETB TALE ;TALE IS DEFINED AS FOR P0.4 MOV P2,A CLR TALE CLR TWR MOV P2,A NOP NOP SETB TWR SETB CS0 CLR CS1 RET READRTC: SETB CS1 CLR CS0 SETB TALE MOV P2,A CLR TALE CLR TRD NOP NOP MOV A,P2 SETB TRD SETB CS0 CLR CS1 RET |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Starting with the TWRITE routine. How do you guarantee that 1 microsecond elapses between the rising edge of CS1 and the falling edge of CS0 as required by the RTC and mentioned in it's data sheet. If I knew or could remember what your clock frequency was it would help. Now that you have gone and connected ALE I'll have to look at the next picture in the datasheet.
You need to review the timing diagram for the RTC and match that to the instruction execution time in the processor. If you coud see the results on an oscilliscope it would help you a great deal. |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
sir,
somewhere i saw a program for interfacing msm6242b with pic16f84 in that they didn't used cs0,cs1 these pins were kept always high i tried it in my program but didn't get results sould i connect ALE OF MSM TO ALE OF MICROCONTROLLER THEN HOW I CAN GIVE HIGH TO LOW TRANSITION IF U HAVE ANY SAMPLE CODE THEN PLS GIVE ME IDEA THANK YOU. |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
As I said before I have no sample code for this device. I have worked with other similar devices and the key to making them work is to duplicate the timing diagrams in the datasheet in excruciating detail. Making the time between events on a timing diagram longer is generally not a problem. Making them shorter is fatal. If you do not have a scope to help you see what is going on then you must analyze your program's timing on an instruction cycle basis.
For Example: SETB is a 2 Byte 1 cycle Instruction. If you know the oscillator frequency and the number of oscillator cycles per instruction then you can compute how long it takes for the bit to be set. CLR is also a 2 byte 1 cycle instruction so you can see there is one instruction cycle between the SETB CS1 and the CLR CS0. Question, is this time more or less than 1 microsecond. If the answer is no, then write Code:
SETB CS1 NOP CLR CS0 NOP I would recommend that you go back to tying ALE on the RTC high, especially since you don't seem to have a scope and don't seem to be familiar with timing diagrams and timing requirements. Last edited by Papabravo; 16th May 2006 at 02:05 AM. |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
sir,
in the following code its giving the data which i've writen in the respective registers but there is no increment in the values its always showing the same data what are the steps to read rtc pls suggest me.THE OUTPUT IS LIKE TIME: 12:51 , DATE:12:05:06 thank you org 0000h main: CALL INIT_RTC CALL RTC_WRITE HERE: CALL READ_RTC SJMP HERE INIT_RTC: MOV A,#0F5H CALL TWRITE MOV A,#0F4H CALL TWRITE MOV A,#0E0H CALL TWRITE MOV A,#0D4H CALL TWRITE RET RTC_WRITE: MOV A,#21H CALL TWRITE MOV A,#35H CALL TWRITE MOV A,#42H CALL TWRITE MOV A,#51H CALL TWRITE MOV A,#62H CALL TWRITE MOV A,#71H CALL TWRITE MOV A,#85H CALL TWRITE MOV A,#90H CALL TWRITE MOV A,#0A6H CALL TWRITE MOV A,#0B0H CALL TWRITE RET READ_RTC: MOV A,#20H CALL READ ANL A,#0FH MOV 3AH,A MOV A,#30H CALL READ ANL A,#07H MOV 3BH,A MOV A,#40H CALL READ ANL A,#0FH MOV 3CH,A MOV A,#50H CALL READ ANL A,#03H MOV 3DH,A MOV A,#0D0H CALL TWRITE RET TWRITE: CLR CS1 CLR CS0 NOP SETB CS1 NOP SETB CS0 MOV P2,A NOP CLR CS0 CLR TWR MOV P2,A NOP NOP SETB TWR NOP CLR CS1 RET READ: CLR CS1 CLR CS0 NOP SETB CS1 NOP SETB CS0 MOV P2,A NOP CLR CS0 CLR TRD MOV A,P2 NOP NOP SETB TRD NOP CLR CS1 RET Last edited by esconele; 16th May 2006 at 06:06 PM. |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
If you had an oscilliscope you could see if the oscillator was running.
I see that you are writing a 5 then a 4 to register F which should reset the fractional seconds counter. I see that you have written a 0 to register E. Is there any kind of waveform at the STD.P pin, pin 1? I see that you are writing a 4 to register D which should clear the hold bit. I can't see anything that would prevent the clock from running. Sorry. Edit: Why do you think this poor CMOS part will work at 4MHz. Where did this quaint notion come from? |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Why do you need a RTC just to display date and time?
Your 8051 based IC has internal timer functions. If you can determine how to use them and embed them in your code, then you will only need all of port 1 for the 8-bit data output, and Port P3.7 and Port P3.6. One for enable pin and one for the data/command pin. I assume here your LCD is HD47780 compatible (standard character LCD). I think your AT89C52 has internal program ROM. If not, you can connect external ROM to it and use that, provided the chip supports it. If it has internal rom, then the only other external components you need are the oscillator circuitry (at minimum, 2 capacitors, and a crystal), the LCD, a decent, and regulated 5V power source, and a pull-down resistor for the LCD enable line.
__________________
-=: The best low-priced components to troubleshoot with are the speaker and the LED :=- |
|
|
|