+ Reply to Thread
Results 1 to 15 of 15

Thread: Handling DS1307 with ASM

  1. #1
    burnediode Newbie
    Join Date
    Jan 2009
    Posts
    4

    Default Handling DS1307 with ASM

    Hi everyone, im working in a real time clock proyect with a 16F876 coding it with assembler. According with the datasheet of both IC's, the code seems to be fine, the problem is when i simulated it in Proteus Isis (7.4) it just doesnt work. The DS1307 sends the corresponding ack signals, but i cant write any register of it. Does anyone have an asm code working with this IC? thanks you very much

    PD: it has to be in asm code. thanks


  2. #2
    geko Good geko Good geko Good geko Good
    Join Date
    Mar 2006
    Location
    Rutland, England, UK
    Posts
    262

    Default

    Source code for this project which uses a DS1307
    Microchip PIC based central heating programmer with serial CLI interface
    is here
    http://picprojects.org.uk/projects/chc/source/chp.zip

    I think the DS1307 bits are in TimeControl.inc and i2c_driver.inc

  3. #3
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,745

    Default

    can you post the code you have made? You are simulating in Proteus Isis. Why not on a breadboard? I understand the benefit but its more fun on breadboard. Anyway post some code and well see what we can find.
    AtomSofts eBay Store
    AtomSoftTech: C18 TIPS & TRICKS v9 PDF

    My Name: Jason Lopez
    My BLOG | My YouTube Videos!
    My Favorite Store:
    dipmicro Electronics
    Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
    Electronic Components & Tools Exchange

  4. #4
    burnediode Newbie
    Join Date
    Jan 2009
    Posts
    4

    Default

    Hi again here is the code, sorry the spanish comments i hope you understand what im trying to do
    Code:
    LIST P=16F876A
    #INCLUDE P16F876.INC
    #define	LCDE	PORTC,0 		;Habilitación del LCD
    #define	LCDRS	PORTC,1		;Selección de modo del LCD
    ORG		00H
    GOTO		INICIO
    ORG		04H
    GOTO		ISR
    ORG		05H
    		
    		PCL				equ	0x02
    		LCDlinea1		equ	H'0080'
    		LCDlinea2		equ	H'00c0'
    		LCDCLR			equ	H'0001'
    		LCDCasa		equ	H'0002'
    		LCDInc			equ	H'0006'
    		LCDDec			equ	H'0004'
    		LCDOn			equ	H'000C'
    		LCDOff			equ	H'0008'
    		CursorOn		equ	H'000E'
    		CursorOff		equ	H'000C'				
    		CursBlink		equ	H'000F'
    		LCDIzda			equ	H'0018'
    		LCDDecha		equ	H'001C'
    		CursIzda		equ	H'0010'
    		CursDecha		equ	H'0014'
    		LCDFuncion		equ	H'0038'
    		LCDCGRAM		equ	H'0040'
    		RTCWRT			equ	b'11010000'
    		RTCRD			equ b'11010001'
    		AUX				equ H'0021'
    		AUX1			equ H'0022'
    		tiempo1			equ	0x23		;Usados para temporizar
    		tiempo2			equ	0x24
    		SEG				equ H'0025' ; usados para guardar los
    		MIN 			equ H'0026' ; datos que
    		HOR 			equ H'0027' ; se 
    		DIA 			equ H'0028' ; muestran
    		FECHA			equ	H'0029' ; en
    		MES 			equ H'002A' ; el
    		AÑO 			equ H'002B' ; LCD
    		DIRI2C			equ H'002C'	; DATO TEMPORAL A SER ENVIADO A TRAVES DEL BUS I2C
    		rtc_SEG			equ H'00'
    		rtc_MIN 			equ H'01'
    		rtc_HOR 		equ H'02'
    		rtc_DIA 			equ H'03'
    		rtc_FECHA		equ	H'04'
    		rtc_MES 			equ H'05'
    		rtc_AÑO 		equ H'06'
    		rtc_CONTROL	equ	H'07'
    		
    
    INICIO		BCF			STATUS,RP0
    			BCF			STATUS,RP1
    			BCF			ADCON0,0
    			BSF			STATUS,RP0
    			MOVLW 	H'06'
    			MOVWF		ADCON1
    			BCF			STATUS,RP1
    			MOVLW		H'D5'
    			MOVWF		OPTION_REG
    			CLRF		TRISA
    			CLRF		TRISB
    			CLRF		TRISC
    			BSF			TRISC,3
    			BSF			TRISC,4
    			CLRF		PIE1
    			CLRF		PIE2
    			BCF 		STATUS,5
    			CLRF		PIR1
    			CLRF		PIR2
    			CLRF		PORTA
    			CLRF		PORTB
    			MOVLW		.4
    			CALL		Pausa5ms
    			CALL      	INILCD		
    			CALL	 	INIMSSP
    			MOVLW		.0 ;EMPIEZO DESDE LOS SEGUNDOS
    			CALL		I2CSTARTW
    			MOVLW		H'51'
    			CALL		I2CDATOW
    			MOVLW		H'45'
    			CALL		I2CDATOW
    			MOVLW		H'23'
    			CALL		I2CDATOW
    			MOVLW		H'01'
    			CALL		I2CDATOW
    			MOVLW		H'14'
    			CALL		I2CDATOW
    			MOVLW		H'01'
    			CALL		I2CDATOW
    			MOVLW		H'99'
    			CALL		I2CDATOW
    			MOVLW		H'10'
    			CALL		I2CDATOW
    			CALL		I2CSTOPACK
    			CLRF		STATUS
    		      MOVLW		.10
    			CALL		Pausa5ms
    			MOVLW		H'FF'
    			CALL		DATO
    			MOVLW		H'57'
    			CALL		CONTROL
    			MOVLW		H'FF'
    			CALL		DATO
    			MOVLW		H'C0'
    			CALL		CONTROL
    			MOVLW		H'FF'
    			CALL		DATO
    			MOVLW		H'67'
    			CALL		CONTROL
    			MOVLW		H'FF'
    			CALL		DATO
    			NOP
    			GOTO	$-1
    			
    ;*************RUTINA DE SERVICIO DE INTERRUPCION*****************
    		ISR		
    					RETFIE	
    ;*********************BUS I2C***********
    	INIMSSP			CLRF		STATUS
    					MOVLW		H'28'
    					MOVWF		SSPCON	;HABILITA PINES SDA Y SCL Y CONFIGURA AL PIC COMO I2C MASTER
    					BSF			STATUS,RP0
    					MOVLW		.9
    					MOVWF		SSPADD; VALOR NECESARIO PARA QUE EL CLOCK SEA DE 100KHZ (CK=OSC/4(SSPADD+1)) OK
    					BSF			SSPSTAT,7; TRANSMISION A 100KHZ
    					BCF			SSPCON2,5; VALOR DEL ACK  CUANDO TERMINA DE RECIBIR UN BYTE (1 ES NACK)
    					BCF			PIE1,3
    					BCF			STATUS,RP0
    					BCF			PIR1,3
    					RETURN
    	
    	I2CSTARTW		BCF			STATUS,RP1 ; ESCRIBIR EN W LA PRIMER DIRECCION DE MEMORIA DONDE SE QUIERE ESCRIBIR Y LLAMAR
    					BCF			STATUS,RP0
    					MOVWF		DIRI2C
    					BSF			STATUS,RP0
    					BSF			SSPCON2,0; START
    					CALL		I2CHEK     ; EL MODULO ESTA OCUPADO?
    					BCF			STATUS,RP0
    					MOVLW		RTCWRT	   ; DIRECCION DEL RTC MAS BIT DE ESC 0
    					MOVWF		SSPBUF
    					CALL		I2CHEK     ; EL MODULO ESTA OCUPADO?
    					MOVF		DIRI2C,W  ; PRIMER DIRECCION DONDE VOY A ESCRIBIR 
    					MOVWF		SSPBUF
    					CALL		I2CHEK	; EL MODULO ESTA OCUPADO?
    					RETURN
    	
    	I2CDATOW		; CARGAR EN W EL SIG DATO Y LLAMAR
    					CALL		I2CHEK 
    					BCF			STATUS,RP0
    					BCF			STATUS,RP1
    					MOVWF		SSPBUF
    					CALL		I2CHEK
    					RETURN
    	
    	I2CSTOPACK		BCF		STATUS,RP1
    					BSF		STATUS,RP0
    					BCF		SSPCON2,5 ;ANTES DEL STOP HABRA UN ACK SI ESTUVIESE EN RECIBIR 
    					CALL	I2CHEK
    					BSF		SSPCON2,2; STOP
    					CALL	I2CHEK
    					RETURN
    					
    	I2CSTOPNACK	BCF		STATUS,RP1
    					BSF		STATUS,RP0
    					BSF		SSPCON2,5 ;NACK ANTES DEL STOP  
    					BSF		SSPCON2,4; NACK
    					CALL	I2CHEK
    					BSF		SSPCON2,2 ; STOP
    					CALL	I2CHEK
    					RETURN				
    				
    	
    	I2CHEK			BCF		STATUS,RP1
    					BSF		STATUS,RP0
    					BTFSC	SSPSTAT,2; TRANSMICION EN PROGRESO?
    					GOTO	$-1;ENTONCES ESPERA
    			VER		MOVF	SSPCON2,W	;CHEQUEA 
    					ANDLW	H'1F'		;QUE NO ESTE HACIENDO
    					BTFSS	STATUS,Z	;OTRA TAREA
    					GOTO	VER
    					BCF		STATUS,RP0
    					RETURN	
    ;*************RUTINA DE ESCRITURA Y CONTROL LCD*******		
    		CONTROL	BCF    		LCDRS
    					GOTO   		CHEK
    		DATO		BSF	   		LCDRS
    		CHEK		CLRF		STATUS
    					MOVWF		PORTB
    					BSF			STATUS,RP0
    					BSF			TRISB,7
    					CLRF		STATUS
    					BSF			LCDE
    					NOP
    		        		BCF			LCDE
    			    		NOP
    			    		BTFSC		PORTB,7
    					GOTO		$-1
    					BSF			STATUS,RP0
    					BCF			TRISB,7
    					CLRF		STATUS
    					RETURN			
    ;******INICIACION DEL LCD***********
    		INILCD	CLRF		STATUS
    				MOVLW		.6
    				MOVWF		AUX1
    				MOVF		AUX1,0 ;AUX1 -> W
    				CALL 		LISTA1
    				CALL    		CONTROL
    				CLRF           STATUS
    				DECFSZ		AUX1
    				GOTO		$-4
    				MOVLW		CursorOff
    				CALL		CONTROL
    				RETURN	
    		LISTA1	ADDWF		PCL,1
    				RETLW		CursBlink
    				RETLW		LCDCLR
    				RETLW		CursorOn
    				RETLW		LCDOn
    				RETLW		LCDInc
    				RETLW		LCDFuncion
    ;******RUTINAS DE TEMPORIZACION*********						
    Pausa5ms	CLRF		STATUS
    			MOVWF		AUX	
    HOLD		clrf			INTCON
    			movlw		.178
    			movwf		TMR0
    			btfss		INTCON,2
    			goto		$-1
    			DECFSZ		AUX
    			GOTO		HOLD
    			return		
    			END
    
    and also i attached de dsn file for proteus 7.4
    thank you very much
    Attached Files

  5. #5
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,745

    Default

    ok thanks ill test this out as much as i can and hopefully can help
    AtomSofts eBay Store
    AtomSoftTech: C18 TIPS & TRICKS v9 PDF

    My Name: Jason Lopez
    My BLOG | My YouTube Videos!
    My Favorite Store:
    dipmicro Electronics
    Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
    Electronic Components & Tools Exchange

  6. #6
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,745

    Default

    Hey add a 22k resistor from MCLR to VCC (not straight though) also in the code you need to set the config like
    Code:
    	LIST P=16F876A
    	#INCLUDE P16F876.INC
    	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _LVP_ON & _CPD_OFF
    
    I can only see 4 arrows on screen now. I think it has to do with your 5ms delay code.

    EDIT
    Sorry i cant help much more my asm is sluggish and i get lost in it quick. If it was C then it would have been fixed
    Last edited by AtomSoft; 14th January 2009 at 04:19 PM.
    AtomSofts eBay Store
    AtomSoftTech: C18 TIPS & TRICKS v9 PDF

    My Name: Jason Lopez
    My BLOG | My YouTube Videos!
    My Favorite Store:
    dipmicro Electronics
    Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
    Electronic Components & Tools Exchange

  7. #7
    burnediode Newbie
    Join Date
    Jan 2009
    Posts
    4

    Default

    ok atomsoft i see what can i do, thank you very much!!!!!!

  8. #8
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,745

    Default

    im sorry i couldnt help you much more on this but heh ASM is spooky sometimes with larger projects like this.
    AtomSofts eBay Store
    AtomSoftTech: C18 TIPS & TRICKS v9 PDF

    My Name: Jason Lopez
    My BLOG | My YouTube Videos!
    My Favorite Store:
    dipmicro Electronics
    Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
    Electronic Components & Tools Exchange

  9. #9
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,805

    Default

    The only thing I can see wrong is you don't set the ACKEN bit in one of your routines,

    Code:
    I2CSTOPACK	bcf	STATUS,RP1
    		bsf	STATUS,RP0
    		bcf	SSPCON2,5	;ANTES DEL STOP HABRA UN 
     		bsf	SSPCON2,4	; Added
    ACK SI ESTUVIESE EN RECIBIR 
    		call	I2CHEK
    		bsf	SSPCON2,2	; STOP
    		call	I2CHEK
    		return
    
    I2CSTOPNACK	bcf	STATUS,RP1
    		bsf	STATUS,RP0
    		bsf	SSPCON2,5	;NACK ANTES DEL STOP  
    		bsf	SSPCON2,4	; NACK
    		call	I2CHEK
    		bsf	SSPCON2,2	; STOP
    		call	I2CHEK
    		return
    
    Mike.

  10. #10
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,745

    Default

    pommie ... what about the config stuff? doesnt he have to set it?
    AtomSofts eBay Store
    AtomSoftTech: C18 TIPS & TRICKS v9 PDF

    My Name: Jason Lopez
    My BLOG | My YouTube Videos!
    My Favorite Store:
    dipmicro Electronics
    Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
    Electronic Components & Tools Exchange

  11. #11
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,805

    Default

    Quote Originally Posted by AtomSoft View Post
    pommie ... what about the config stuff? doesnt he have to set it?
    Yes he does but as you had already mentioned it then I didn't bother. BTW, I would turn LVP off by changing _LVP_ON to _LVP_OFF just incase RB3 is floating.

    Mike.

  12. #12
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,745

    Default

    Actually i took that config of the templates that come with MPLAB LD just changed the OSC to XT since its most likely @ 4 Mhz

    EDIT
    burnediode off topic some but wanted to know if you have or know where i can get a MODEL for Isis for a DS1306. I would love to rebuild my clock in it. Looks like fun and can make more changes and stuff faster and test better.
    Last edited by AtomSoft; 15th January 2009 at 01:38 AM.
    AtomSofts eBay Store
    AtomSoftTech: C18 TIPS & TRICKS v9 PDF

    My Name: Jason Lopez
    My BLOG | My YouTube Videos!
    My Favorite Store:
    dipmicro Electronics
    Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
    Electronic Components & Tools Exchange

  13. #13
    burnediode Newbie
    Join Date
    Jan 2009
    Posts
    4

    Default

    first of all thanks
    Pommie The only thing I can see wrong is you don't set the ACKEN bit in one of your routines,
    Code:
    I2CSTOPACK	bcf	STATUS,RP1
    		bsf	STATUS,RP0
    		bcf	SSPCON2,5	;ANTES DEL STOP HABRA UN 
     		bsf	SSPCON2,4	; Added
    ACK SI ESTUVIESE EN RECIBIR 
    		call	I2CHEK
    		bsf	SSPCON2,2	; STOP
    		call	I2CHEK
    		return
    
    I2CSTOPNACK	bcf	STATUS,RP1
    		bsf	STATUS,RP0
    		bsf	SSPCON2,5	;NACK ANTES DEL STOP  
    		bsf	SSPCON2,4	; NACK
    		call	I2CHEK
    		bsf	SSPCON2,2	; STOP
    		call	I2CHEK
    		return
    
    Pommie... i try this but it doesnt work thank you anyway
    Atomsoft... i cant help you with that, i really dont know where to find it.

    im thinking, is there any chance that proteus doesnt have a simulating model for DS1307?

    and about the config the compiler throw me this msg Error[126] C:\ELECTRONICA\PROYECTOS ASSEMBLER\IMORET.ASM 5 : Argument out of range (not a valid config register address)
    what!?

  14. #14
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,745

    Default

    post the config line. ... well post entire line 5
    AtomSofts eBay Store
    AtomSoftTech: C18 TIPS & TRICKS v9 PDF

    My Name: Jason Lopez
    My BLOG | My YouTube Videos!
    My Favorite Store:
    dipmicro Electronics
    Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
    Electronic Components & Tools Exchange

  15. #15
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,805

    Default

    That config line should work fine. Is it after the list and include lines?

    Also, I have notice that you are specifying two different chips,
    Code:
    	LIST P=16F876A
    	#INCLUDE P16F876.INC
    
    You need to use either the A or non-A version.

    Mike.

+ Reply to Thread

Similar Threads

  1. LED Pulse Handling Capability
    By Stellarcore in forum General Electronics Chat
    Replies: 5
    Latest: 30th June 2008, 04:19 AM
  2. handling clock pulse
    By freezemenot in forum Micro Controllers
    Replies: 1
    Latest: 20th January 2008, 05:32 PM
  3. Need some tricks in VB handling
    By Alex_rcpilot in forum General Electronics Chat
    Replies: 8
    Latest: 16th October 2005, 11:11 AM
  4. HANDLING THE INTERRUPT.
    By alamy in forum Micro Controllers
    Replies: 6
    Latest: 26th March 2005, 03:37 PM
  5. R.P.S's Rated Power Handling.
    By Screech in forum General Electronics Chat
    Replies: 3
    Latest: 8th June 2004, 08:41 AM

Tags for this Thread