??? 02/28/05 20:53 Read: times Msg Score: +1 +1 Good Question |
#88695 - Problem interfacing DS12887 to 8051 |
Hello all,
I'm having a slight problem getting a Dallas Semiconductor Real Time Clock (DS12887) working with an 8051 (T89C51RD2 from Atmel). I have the clock and a HD44780U compatible display connected up to port 0, along with a keypad to port 1 as follows: Display: ![]() and the keypad/clock ![]() I know that using the 74C922 isn't really necessary but I have a bucket load of them here so I might as well. Both the keypad and the display are working perfectly (also the other ports will be occupied in the final design so they are not available). As far as I can gather from reading the datasheet for the DS12887, reading and writing to it is the same as to external RAM. In the following code I'm trying to write a 1 into the seconds register of the clock (address 00H) when '1' is pressed on the keypad and when any other button is pressed the value of this register is read and displayed on the display. (I have a led connected to pin 3.4 just to show that the routine to write to the register is being executed). When I try reading the the value of the register (after writing to it) I get the value "EE" written to the display. No matter what I do all I read is "EE". I've tried everything I can think of to get this working with no success so I'm not sure if there is a problem with my write code, my read code, both or just the logic behind the whole program. Any suggestions will be greatly appreciated. Code: DB0 EQU P0.0 DB1 EQU P0.1 DB2 EQU P0.2 DB3 EQU P0.3 DB4 EQU P0.4 DB5 EQU P0.5 DB6 EQU P0.6 DB7 EQU P0.7 EN EQU P3.7 RS EQU P3.6 RW EQU P3.5 DATA0 EQU P0 PORT_PIN_LED EQU P3.4 ENABLE_LCD EQU P1.4 FLASH EQU 07FH CSEG ORG 0000H LJMP MAIN ORG 0013H LJMP INT1_ISR ORG 0048H MAIN: SETB EX1 SETB EA MOV A, 8EH ; Needed to access off chip external ram ORL A, #3H MOV 8EH, A SETB ENABLE_LCD LCALL INIT_LCD CLR ENABLE_LCD SETB FLASH lpl1: JB FLASH, lpl1 CPL PORT_PIN_LED LCALL delay JMP lpl1 delay: MOV R7, #200 MOV R5, #20 dly1: MOV R6, #229 dly2: DJNZ R6, dly2 DJNZ R7, dly1 DJNZ R5, dly1 RET WAIT_LCD: PUSH ACC not_ready: SETB EN CLR RS SETB RW MOV DATA0,#0FFH MOV A,DATA0 JB ACC.7,not_ready CLR EN CLR RW POP ACC RET INIT_LCD: SETB EN CLR RS MOV DATA0,#038H CLR EN LCALL WAIT_LCD SETB EN CLR RS MOV DATA0,#038H CLR EN LCALL WAIT_LCD SETB EN CLR RS MOV DATA0,#0Eh CLR EN LCALL WAIT_LCD SETB EN CLR RS MOV DATA0,#06h CLR EN LCALL WAIT_LCD RET CLEAR_LCD: SETB EN CLR RS MOV DATA0,#01H CLR EN LCALL WAIT_LCD RET WRITE_TEXT: SETB EN SETB RS MOV DATA0,A CLR EN LCALL WAIT_LCD RET INT1_ISR: PUSH PSW PUSH ACC PUSH 00H ;R0 PUSH 02H ;R2 PUSH 03H ;R3 MOV A, P1 ANL A, #0FH DEC A JZ one MOV R0, #0 MOVX A, @R0 MOV R3, A SETB FLASH JMP write one: CLR ENABLE_LCD MOV A, #1 MOV R0, #0 MOVX @R0, A CLR FLASH JMP finish write: SETB ENABLE_LCD LCALL CLEAR_LCD MOV A, R3 ANL A, #0FH CJNE A, #0AH, next1 MOV A, #41H JMP write1 next1: CJNE A, #0BH, next2 MOV A, #42H JMP write1 next2: CJNE A, #0CH, next3 MOV A, #42H JMP write1 next3: CJNE A, #0DH, next4 MOV A, #43H JMP write1 next4: CJNE A, #0EH, next5 MOV A, #44H JMP write1 next5: CJNE A, #0FH, digit1 MOV A, #45H JMP write1 digit1: ADD A, #30H write1: LCALL WRITE_TEXT MOV A, R3 ANL A, #0F0H SWAP A CJNE A, #0AH, next6 MOV A, #41H JMP write2 next6: CJNE A, #0BH, next7 MOV A, #42H JMP write2 next7: CJNE A, #0CH, next8 MOV A, #42H JMP write2 next8: CJNE A, #0DH, next9 MOV A, #43H JMP write2 next9: CJNE A, #0EH, next10 MOV A, #44H JMP write2 next10: CJNE A, #0FH, digit2 MOV A, #45H JMP write2 digit2: ADD A, #30H write2: LCALL WRITE_TEXT CLR ENABLE_LCD finish: POP 03H ; R3 POP 02H ; R2 POP 00H ; R0 POP ACC POP PSW RETI END |
Topic | Author | Date |
Problem interfacing DS12887 to 8051 | 01/01/70 00:00 | |
CS? | 01/01/70 00:00 | |
!CS | 01/01/70 00:00 | |
Re: !CS | 01/01/70 00:00 | |
P0 is open drain | 01/01/70 00:00 | |
Re: P0 is open drain | 01/01/70 00:00 | |
SeriAL PORT | 01/01/70 00:00 | |
where? | 01/01/70 00:00 | |
re: where? | 01/01/70 00:00 | |
Used a scope? | 01/01/70 00:00 | |
Common project! | 01/01/70 00:00 | |
re: Common Project | 01/01/70 00:00 | |
I am sure this is helpful!![]() | 01/01/70 00:00 |