Gps data logger with FM25W256



Schematics


GPS data logger code:



;------------------------------------------------- 12.05.2006
;------------------------------------------------------------
;	configure programmer
	list	p=16f628;f=inhx8m
	__CONFIG	_PWRTE_ON  & _WDT_OFF & _XT_OSC & _BODEN_OFF & _LVP_OFF & _CP_OFF & _MCLRE_OFF
;------------------------------------------------------------
;	www.bertys.ro
;------------------------------------------------------------
 	org	0x00
	goto	init
	org	0x04
;------------------------------------------------------------
	#INCLUDE P16F628.INC
;------------------------------------------------------------
;       cpu init
	cblock 0x20	; Beginn General Purpose-Register
;------------------------------------------------------------
	count1	
	count2	
	count3	
	count4	
	count5
;-------------------------- registrii transfer
	transo
	transl
	ranso
	ransl
;-------------------------- registrii date rmc
	orah
	oral
	minh
	minl
	fix
	lat1
	lat2
	lat3
	lat4
	lat5
	lat6
	lat7
	lat8
	log1
	log2
	log3
	log4
	log5
	log6
	log7
	log8
	c_hi
	c_lo
;------------------------------------------------------------	
	endc
;------------------------------------------------------------
#DEFINE	en	PORTB,4
#DEFINE	rw	PORTB,5
#DEFINE	rs	PORTB,6
#DEFINE	rsrx	PORTA,3
#DEFINE	spi_sda	PORTA,0
#DEFINE	spi_clk	PORTA,1
#DEFINE	spi_cs	PORTA,2
#DEFINE	spi_so	PORTA,4
#DEFINE	rset		PORTA,5
;------------------------------------------------------------
;------------------------------------------------------------
	org	0x00
;	goto	init
	org	0x04
;------------------------------------------------------------
init	
	clrf	PORTA
	clrf	PORTB
	movlw	0x07		; Turn comparators off and enable pins for I/O 
	movwf	CMCON
	bcf	STATUS,RP1
	bsf	STATUS,RP0  ; switch to bank 1
	movlw	0xF8
	movwf	TRISA
	clrf	TRISB
	bcf	STATUS,RP0  ; switch back to bank 0
	movlw	0x0F
	movwf	count5
;***************************************************
start	
	call	haltd
	movlw	0x02
	call	lcdcmd
	call	haltd	;
	movlw	0x02
	call	lcdcmd
	movlw	0x08
	call	lcdcmd
	call	haltd	;
	movlw	0x00
	call	lcdcmd
	movlw	0x0C
	call	lcdcmd
	call	haltd	;
	movlw	0x00
	call	lcdcmd
	movlw	0x01
	call	lcdcmd
	call	haltd	;
	call	linia1
	btfsc	rset
	call	adr_reset
	call	read_adr
;-------------------------- 	asteapta $GPRMC
homa	
	call	ser_rx
	sublw	0x24
	btfss	STATUS,Z
	goto	homa
	call	ser_rx
	sublw	0x47
	btfss	STATUS,Z
	goto	homa
	call	ser_rx
	sublw	0x50
	btfss	STATUS,Z
	goto	homa
	call	ser_rx
	sublw	0x52
	btfss	STATUS,Z
	goto	homa
	call	ser_rx
	sublw	0x4D
	btfss	STATUS,Z
	goto	homa
	call	ser_rx
	sublw	0x43
	btfss	STATUS,Z
	goto	homa
;-------------------------- 	asteapta virgula si timp
	call	wartv
	call	ser_rx
	movwf	orah
	call	ser_rx
	movwf	oral
	call	ser_rx
	movwf	minh
	call	ser_rx
	movwf	minl
;-------------------------- 	asteapta virgula si validare sateliti
	call	wartv
	call	ser_rx
	movwf	fix
;-------------------------- asteapta virgula si latitudine
	call	wartv
	call	ser_rx
	movwf	lat1
	call	ser_rx
	movwf	lat2
	call	ser_rx
	movwf	lat3
	call	ser_rx
	movwf	lat4
	call	ser_rx
	call	ser_rx
	movwf	lat5
	call	ser_rx
	movwf	lat6
	call	ser_rx
	movwf	lat7
	call	ser_rx
	movwf	lat8
;-------------------------- asteapta virgula si longitudine
	call	wartv
	call	ser_rx
	call	wartv
	call	ser_rx
	call	ser_rx
	movwf	log1
	call	ser_rx
	movwf	log2
	call	ser_rx
	movwf	log3
	call	ser_rx
	movwf	log4
	call	ser_rx
	call	ser_rx
	movwf	log5
	call	ser_rx
	movwf	log6
	call	ser_rx
	movwf	log7
	call	ser_rx
	movwf	log8
;-------------------------- afiseaza
	movf	orah,W
	call	scrie
	movf	oral,W
	call	scrie
	movlw	0x3A
	call	scrie
	movf	minh,W
	call	scrie
	movf	minl,W
	call	scrie
	movlw	0x20
	call	scrie
	movlw	0x20
	call	scrie
	movlw	0x20
	call	scrie
	movf	fix,W
	call	scrie
	call	linia2 ; linia2
	movf	lat1,W
	call	scrie
	movf	lat2,W
	call	scrie
	movf	lat3,W
	call	scrie
	movf	lat4,W
	call	scrie
	movlw	0x2E
	call	scrie
	movf	lat5,W
	call	scrie
	movf	lat6,W
	call	scrie
	movf	lat7,W
	call	scrie
	movf	lat8,W
	call	scrie
	movlw	0x20
	call	scrie
	movlw	0x4E
	call	scrie
	call	linia3 ; linia3
	movf	log1,W
	call	scrie
	movf	log2,W
	call	scrie
	movf	log3,W
	call	scrie
	movf	log4,W
	call	scrie
	movlw	0x2E
	call	scrie
	movf	log5,W
	call	scrie
	movf	log6,W
	call	scrie
	movf	log7,W
	call	scrie
	movf	log8,W
	call	scrie
	movlw	0x20
	call	scrie
	movlw	0x45
	call	scrie
	call	linia4 ; linia4
;-------------------------- verifica punct fix
	movf	fix,W
	sublw	0x41
	btfss	STATUS,Z
	goto	no_memory
;-------------------------- delay 1'
	decfsz	count5,F
	goto	no_memory
;---------------------------------------
	call	vren		; enable write to spi ram
	bcf	spi_clk
	bcf	spi_cs	; spi write
	movlw	0x02
	call	send_spi
	movf	c_hi,W
	call	send_spi
	movf	c_lo,W
	call	send_spi
	movf	orah,W
	call	send_spi
	movf	oral,W
	call	send_spi
	movlw	0x3A
	call	send_spi
	movf	minh,W
	call	send_spi
	movf	minl,W
	call	send_spi
	movlw	0x20
	call	send_spi
	movf	lat1,W
	call	send_spi
	movf	lat2,W
	call	send_spi
	movf	lat3,W
	call	send_spi
	movf	lat4,W
	call	send_spi
	movlw	0x2E
	call	send_spi
	movf	lat5,W
	call	send_spi
	movf	lat6,W
	call	send_spi
	movf	lat7,W
	call	send_spi
	movf	lat8,W
	call	send_spi
	movlw	0x20
	call	send_spi
	movlw	0x4E
	call	send_spi
	movf	log1,W
	call	send_spi
	movf	log2,W
	call	send_spi
	movf	log3,W
	call	send_spi
	movf	log4,W
	call	send_spi
	movlw	0x2E
	call	send_spi
	movf	log5,W
	call	send_spi
	movf	log6,W
	call	send_spi
	movf	log7,W
	call	send_spi
	movf	log8,W
	call	send_spi
	movlw	0x20
	call	send_spi
	movlw	0x45
	call	send_spi
	bsf	spi_cs
;--------------------------------------- adress increment
	movf	c_lo,W
	sublw	0xE3
	btfss	STATUS,C
	incf	c_hi,F
	movlw	0x1C
	addwf	c_lo,F
;------------------------------------------- write last adress
	call	vren		; enable write to spi ram
	bcf	spi_clk
	bcf	spi_cs	; spi write adress
	movlw	0x02
	call	send_spi
	movlw	0x7F
	call	send_spi
	movlw	0xF0
	call	send_spi
	movf	c_hi,W
	call	send_spi
	movf	c_lo,W
	call	send_spi
	bsf	spi_cs
;------------------------------------------- delay 1'
	movlw	0x18
	movwf	count5
;--------------------------------------- display current adress
no_memory
	movf	c_hi,W
	call	schr
	movf	c_lo,W
	call	schr
	call	pause
	call	linia1 ; linia1
;***************************************************
	goto	homa
;***************************************************
scrie
	movwf	transo
	andlw	0x0F
	movwf	transl
	rrf	transo,F
	rrf	transo,F
	rrf	transo,F
	rrf	transo,W
	andlw	0x0F
	call	lcddta
	movf	transl,W
	call	lcddta
 	return
;***************************************************
schr
	movwf	ranso
	andlw	0x0F
	movwf	ransl
	rrf	ranso,F
	rrf	ranso,F
	rrf	ranso,F
	rrf	ranso,W
	andlw	0x0F
	movwf	ranso
	movlw	0x0A
	subwf	ranso,W
	btfsc	STATUS,C
	goto	op1
	movlw	0x30
	goto	op2
op1	movlw	0x37
op2	addwf	ranso,W
	call	scrie
	movlw	0x0A
	subwf	ransl,W
	btfsc	STATUS,C
	goto	op3
	movlw	0x30
	goto	op4
op3	movlw	0x37
op4	addwf	ransl,W
	call	scrie
 	return
;***************************************************
;-------------------------- asteapta virgula
wartv	call	ser_rx
	sublw	0x2C
	btfss	STATUS,Z
	goto	wartv
	return
;***************************************************
linia1
	movlw	0x08
	call	lcdcmd
	movlw	0x02
	call	lcdcmd
 	return
;***************************************************
linia2
	movlw	0x08
	call	lcdcmd
	movlw	0x0C
	call	lcdcmd
 	return
;***************************************************
linia3
	movlw	0x0C
	call	lcdcmd
	movlw	0x00
	call	lcdcmd
 	return
;***************************************************
linia4
	movlw	0x0C
	call	lcdcmd
	movlw	0x0C
	call	lcdcmd
 	return
;***************************************************
lcdcmd
	bcf	rw
	nop
	bcf	rs
	nop
	movwf	PORTB
	nop
	bsf	en
	nop
	nop
	bcf	en
	call	haltd
 	return
;***************************************************
lcddta
	bcf	rw
	nop
	bsf	rs
	nop
	addlw	0x40
	movwf	PORTB
	nop
	bsf	en
	nop
	nop
	bcf	en
	call	haltd
 	return

;**********************************************************************
;	Subrutine protocol serial			 			
;**********************************************************************
;--------------------------	citeste seriala si stocheaza in W
ser_rx
	clrf	transo
wart1	btfsc rsrx
	goto	wart1
	call	haltb	; asteapta 101 us .5*Bst
	movlw 0x08
	movwf count4
wdh2	call	halta	; asteapta 202 us
	bcf	STATUS,C
	btfsc rsrx
	bsf	STATUS,C	
	rrf	transo,F
	decfsz count4,F
	goto	wdh2
	call	halta	; asteapta 202 us 1*Bsp
	movf	transo,W
	return
;-------------------------- ramtron fram spi
send_spi			
	movwf	transo
	movlw 0x08	
	movwf count4
txbit	bcf	spi_clk	
	btfss transo,7	;bit0
	bcf	spi_sda
	btfsc transo,7	;bit0
	bsf	spi_sda
	nop
	bsf	spi_clk
	rlf	transo,F
	decfsz count4,F
	goto	txbit
	bcf	spi_clk
	return
;-------------------------- 
vren	bcf	spi_clk
	bcf	spi_cs
	movlw	0x06
	call	send_spi
	bsf	spi_cs
	return
;-------------------------- 
rx_spi
	movlw 0x08
	movwf count1
sbit	bcf	spi_clk
	bcf	STATUS,C
	btfsc spi_so
	bsf	STATUS,C	
	rlf	transo,F
	bsf	spi_clk
	decfsz count1,F
	goto	sbit
	movf	transo,W
	return
;--------------------------
adr_reset
	call	vren
	bcf	spi_clk
	bcf	spi_cs	; spi write adress
	movlw	0x02
	call	send_spi
	movlw	0x7F
	call	send_spi
	movlw	0xF0
	call	send_spi
	movlw	0x00
	call	send_spi
	movlw	0x00
	call	send_spi
	bsf	spi_cs
	return
;-------------------------- 
read_adr	
	bcf	spi_clk
	bcf	spi_cs	; spi write adress
	movlw	0x03
	call	send_spi
	movlw	0x7F
	call	send_spi
	movlw	0xF0
	call	send_spi
	call	rx_spi	;read data
	movwf	c_hi
	call	rx_spi
	movwf	c_lo
	bsf	spi_cs
	return
;************************************************************************
;	Subrutine de intarziere				 				*
;************************************************************************

;**********************************************************************
halta	movlw	0x43	; 207us
	movwf	count1
q0	decfsz	count1,F	
	goto 	q0
	nop		
 	retlw	0x00
;______________________________________________________________________
haltb	movlw	0x20	; 101us
	movwf	count1
q1	decfsz	count1,F	
	goto 	q1	
 	retlw	0x00
;________________________________________________________________________
haltd
	movlw	0xFA	  
	movwf	count2
r2	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	decfsz	count2,F	
	goto	r2
 	return
;________________________________________________________________________
pause	movlw	0x10 ;	cca. 4s
hopa	movwf	count3
d3	movlw	0xFA
	movwf	count1
d1	movlw	0xFA	  
	movwf	count2
d2	nop
	decfsz	count2,F	
	goto	d2		
	decfsz	count1,F	
	goto	d1		
	decfsz	count3,F    
	goto	d3          
	retlw	0x00
;************************************************************************

;------------------------------------------------------------
	end
;============================================================
Fram memory:Ramtron
Back to my home page
Make your own free website on Tripod.com