Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Handling DS1307 with ASM

Status
Not open for further replies.

burnediode

New Member
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:eek:. thanks
 
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.
 
Hi again here is the code, sorry the spanish comments i hope you understand what im trying to do:eek:
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:D:D
 

Attachments

  • imoret.zip
    19.8 KB · Views: 381
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 :D
 
Last edited:
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 
 		[COLOR="Red"]bsf	SSPCON2,4	; Added[/COLOR]
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.
 
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.
 
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:
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:eek:, 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!?:confused:
 
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.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top