Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 13th January 2009, 02:26 PM   #1
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
burnediode is offline  
Old 13th January 2009, 02:41 PM   #2
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
__________________
Pete
picprojects.org.uk
geko is offline  
Old 13th January 2009, 02:53 PM   #3
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.
AtomSoft is online now  
Old 14th January 2009, 04:15 PM   #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
File Type: zip imoret.zip (19.8 KB, 30 views)
burnediode is offline  
Old 14th January 2009, 04:35 PM   #5
Default

ok thanks ill test this out as much as i can and hopefully can help
AtomSoft is online now  
Old 14th January 2009, 05:10 PM   #6
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 05:19 PM.
AtomSoft is online now  
Old 14th January 2009, 08:57 PM   #7
Default

ok atomsoft i see what can i do, thank you very much!!!!!!
burnediode is offline  
Old 14th January 2009, 09:47 PM   #8
Default

im sorry i couldnt help you much more on this but heh ASM is spooky sometimes with larger projects like this.
AtomSoft is online now  
Old 15th January 2009, 01:52 AM   #9
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.
Pommie is offline  
Old 15th January 2009, 01:59 AM   #10
Default

pommie ... what about the config stuff? doesnt he have to set it?
AtomSoft is online now  
Old 15th January 2009, 02:23 AM   #11
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.
Pommie is offline  
Old 15th January 2009, 02:36 AM   #12
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 02:38 AM.
AtomSoft is online now  
Old 15th January 2009, 02:05 PM   #13
Default

first of all thanks
Quote:
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!?
burnediode is offline  
Old 15th January 2009, 02:20 PM   #14
Default

post the config line. ... well post entire line 5
AtomSoft is online now  
Old 15th January 2009, 02:21 PM   #15
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.
Pommie is offline  
Reply

Tags
asm, ds1307, handling

Thread Tools
Display Modes


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



All times are GMT. The time now is 11:22 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker