15
« -: Април 28, 2012, 06:50:37 pm »
Ето ти нещо резнато и от мен това съм го правил за подобен PIC сравни с твоето инициализация избор на банки и тн.
list p=16F877A
include <P16F877A.INC>
;FOSC = 20MHz
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
;********************* Дефиниране на Макроси **************************
BANK0 MACRO ;MACRO to select data RAM bank 0
bcf STATUS,RP0
bcf STATUS,RP1
ENDM
BANK1 MACRO ;MACRO to select data RAM bank 1
bsf STATUS,RP0
bcf STATUS,RP1
ENDM
BANK2 MACRO ;MACRO to select data RAM bank 2
bcf STATUS,RP0
bsf STATUS,RP1
ENDM
BANK3 MACRO ;MACRO to select data RAM bank 3
bsf STATUS,RP0
bsf STATUS,RP1
ENDM
LOAD_DATA_EEPROM MACRO ;MACRO for loading constants in internal EEPROM
org 0x2100
DATA 0x00
ENDM
;
;***EndMacros
;********************* Дефиниране на константи и променливи **************************
W EQU 0
f EQU 1
Z EQU 2
CBLOCK 0x20 ;0 RAM starts at address 20h
Counter
Counter1
IPortB
IPortB0
IPortB1
IPortB2
BlokStage
TempCoutPortF
ENDC
CBLOCK 0x070
Wtemp
STATUStemp
PCLATHtemp
FSRtemp
ENDC
;--------------------- Дефиниране на входно-изходните портове ------------------------
;#define SCK PORTC, 3 ;Изход Тактова честота
;#define SDI PORTC, 4 ;SDI за SPI
;#define SDO PORTC, 5 ;SDO за SPI
#define SS PORTA, 5 ;SS за SPI
#define REC IPortB, 0 ;Бутон за запис
#define PLAY IPortB, 1 ;Бутон за възпроизвеждане
#define STOP IPortB, 2 ;Бутон за стоп
#define SV_REC PORTB, 3 ;Светодиод за запис
#define SV_PLAY PORTB, 4 ;Светодиод за възпроизвеждане
#define SV_STOP PORTB, 5 ;Светодиод за стоп
;***StartBlock************************************************************************
; Начало на програма
;*************************************************************************************
ORG 0x0000 ;start address = 0000h
goto start
;***EndBlock**************************************************************************
;***StartBlock************************************************************************
; Обработка на прекъсванията
;*************************************************************************************
ORG 0x0004 ;interrupt address = 0004h
;-----------------Блок за влизане в прекъсване -------------------
movwf Wtemp ; Store W-reg
swapf STATUS,W ; Swap status to be saved into W
clrf STATUS ; bank 0, Clears IRP,RP1,RP0
movwf STATUStemp ; Save status to bank zero STATUS_TEMP
movf PCLATH,W ; pages 1, 2 and/or 3
movwf PCLATHtemp ; Save PCLATH into W
clrf PCLATH ; Page zero, regardless of current page
movf FSR,W ; Copy FSR to W
movwf FSRtemp ; Copy FSR from W to FSR_TEMP
;-----------------------------------------------------------------
nop
nop
;-----------------Блок за излизане от прекъсване -----------------
clrf STATUS ; bank0
movf FSRtemp,W ; Restore FSR register
movwf FSR
movf PCLATHtemp,W ; Restore PCLATH
movwf PCLATH ; Move W into PCLATH
swapf STATUStemp,W ; Swap STATUS_TEMP register into W (sets bank to original state)
movwf STATUS ; Move W into STATUS register
swapf Wtemp,F ; Swap W_TEMP
swapf Wtemp,W ; Swap W_TEMP into W
retfie ; end of interrupt vector
;-----------------------------------------------------------------
;***EndBlock**************************************************************************
;***StartBlock************************************************************************
; Използвани подпрограми
;*************************************************************************************
;--------------- Подпрограма "Wait_Tpud" формира времезадръжка от Xms ----------------
Wait_Tpud:
movlw D'10' ;Задава времето
movwf Counter ;
clrf TMR0 ;Нулира TMR0
again: ;Изпълни цикъла отново
bcf INTCON, T0IF ;Нулира бит T0IF
loop1:
btfss INTCON, T0IF ;Бит T0IF=1
goto loop1 ;Не,повтори отново
decfsz Counter,f ;
goto again ;Изпълни цикъла отново
return ;Връща към главна програма докадето е прекратена
;---endSub
start:
BANK1 ;Избор на Банка 1
movlw b'10010110' ;nternal instruction cycle clock (CLKO), Prescaler is assigned to the Timer0 module,TMR0 Rate 1 : 128
movwf OPTION_REG ;
movlw b'00000111' ;Настроиване на компараторния блок - всички компаратори изключени
movwf CMCON ;
movlw b'00000110' ;Настроиване на изходите само като цифрови
movwf ADCON1 ;
movlw b'11011111' ;RA0-RA4-Входове, RA5-Изход за SS(SLAVE Select)
movwf TRISA ;
movlw b'00000111' ;RB0-RB2-Входове, RB3-RB7-Изход
movwf TRISB ;
bcf TRISC, 3 ;SCK изводи на SPI.
bsf TRISC, 4 ;SDI
bcf TRISC, 5 ;SDO
movlw b'01000000' ;инициализация на SPI (SSPSTAT) - (CKE)Transmit occurs on transition from active to Idle clock state
movwf SSPSTAT ;
BANK0 ;Избор на Банка 0
bsf SS ;Забрана на SS(PORTA,0)
clrf PORTB ;Нулиране на PORTB
clrf PORTC ;Нулиране на PORTC
movlw b'00100010' ;инициализация на SPI (SSPCON) - (CKP)Idle state for clock is a low level, SPI Master mode, clock = FOSC/64 (312,5KHz)
movwf SSPCON ;
movlw b'00000111'
movwf IPortB
movwf IPortB0
movwf IPortB2
movlw .200
movwf TempCoutPortF
clrf BlokStage
goto main
nop
;***EndBlock**************************************************************************