MCP 3201 İletişimi

Başlatan _MOD_, 01 Nisan 2011, 21:40:09

_MOD_

Selam. MCP 3201 ile analog dijital çevrim yapmaya çalışıyorum. MCP 3201 spı portunu kullanıyor. Çalıştırmak için microchip' in örnek dökümanına baktım fakat kafama bazı noktalar takıldı.

1. Proteusda 3201 yok 3001 kullandım. 3001 10 bit bir adc. Ama aşağıdaki programa göre çalıştırınca 12 bit sonuç üretiyor.
2. Programı adım adım çalıştırınca gördüm ki adc den gelen ilk değerler input geriliminin anlık değeri değil. 2. 3. 4. tekrarlarda yavaş yavaş artarak anlık değere ulaşıyor.
3. SPI iletişimini çalıştırmak için çok uğraştım. Ayar registerlarına gerekli değerleri atamama rağmen çalışmıyordu. En sonunda aşağıdaki örnek kod da gördüm ki iletişimi başlatmak için SSPBUF registerına 01 ve 81  bilgileri gönderilmiş. Bu bilgiler neye göre gönderiliyor? 01 ne demek 81 ne demek?

list		p=16f887	; list directive to define processor
	#include	<p16f887.inc>	; processor specific variable definitions


; '__CONFIG' directive is used to embed configuration data within .asm file.
; The labels following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.

	__CONFIG    _CONFIG1, _LVP_OFF & _FCMEN_ON & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _HS_OSC
	__CONFIG    _CONFIG2, _WRT_OFF & _BOR21V



;***** VARIABLE DEFINITIONS
HIZL		EQU 0x20
HIZH		EQU 0x21
w_temp		EQU	0x7D		; variable used for context saving
status_temp	EQU	0x7E		; variable used for context saving
pclath_temp	EQU	0x7F		; variable used for context saving


;**********************************************************************
	ORG     0x000             ; processor reset vector

	nop
  	goto    main              ; go to beginning of program


	ORG     0x004             ; interrupt vector location

	movwf   w_temp            ; save off current W register contents
	movf	STATUS,w          ; move status register into W register
	movwf	status_temp       ; save off contents of STATUS register
	movf	PCLATH,w	  ; move pclath register into w register
	movwf	pclath_temp	  ; save off contents of PCLATH register

; isr code can go here or be located as a call subroutine elsewhere

	movf	pclath_temp,w	  ; retrieve copy of PCLATH register
	movwf	PCLATH		  ; restore pre-isr PCLATH register contents
	movf    status_temp,w     ; retrieve copy of STATUS register
	movwf	STATUS            ; restore pre-isr STATUS register contents
	swapf   w_temp,f
	swapf   w_temp,w          ; restore pre-isr W register contents
	retfie                    ; return from interrupt



main
	CLRF HIZL
	CLRF HIZH
	BANKSEL ANSEL
	CLRF ANSEL
	BANKSEL ANSELH
	CLRF ANSELH
	BANKSEL TRISA
	BCF TRISA, 5
	BANKSEL PORTA
	CLRF PORTA
	BANKSEL TRISB
	BSF TRISB, 0
	BSF TRISB, 1
	BANKSEL PORTB
	BCF PORTB, 0
	BCF PORTB, 1
	BANKSEL OPTION_REG
	BCF OPTION_REG, 7
	BANKSEL WPUB
	BSF WPUB, 0
	BSF WPUB, 1
	movlw B'00110001'
	banksel SSPCON ; linker to select SFR bank
	movwf SSPCON ; enable Master SPI, bus mode 1,1, FOSC/4
	banksel SSPSTAT ; linker to select SFR bank
	clrf SSPSTAT
	BANKSEL TRISC
    MOVLW B'11010000'
	MOVWF TRISC
	BANKSEL PORTC
	CLRF PORTC
TARA
	BANKSEL PORTB
	BTFSC PORTB, 0
	GOTO TARA
	BANKSEL PORTA
	BCF PORTA, 5
	MOVLW H'01'
	BANKSEL SSPBUF
	MOVWF SSPBUF
	BANKSEL SSPSTAT
GERI1
	BTFSS SSPSTAT, BF
	GOTO GERI1
	BANKSEL SSPBUF
	MOVF SSPBUF, W
	BANKSEL HIZH
	MOVWF HIZH
	MOVLW H'81'
	BANKSEL SSPBUF
	MOVWF SSPBUF
	BANKSEL SSPSTAT
GERI2
	BTFSS SSPSTAT, BF
	GOTO GERI2
	BANKSEL PORTA
	BSF PORTA, 5
	BANKSEL SSPBUF
	MOVF SSPBUF, W
	BANKSEL HIZL
	MOVWF HIZL
	BCF STATUS, C
	RRF HIZH
	RRF HIZL
	BCF STATUS, C
	GOTO TARA
END