Hej nu har jag fått problem med en fil till pic16f84 krets
Postat: 30 mars 2006, 21:47:12
Jag ska försöka att få timer-interrupten att fungera i denna kod nedanför. Men den hoppar aldrig fattar inte vad felet är. Det enda fel jag hittat jämnt nu är att jag inte påverkar option_reg register ovaset om jag skickar in värdet till registret med hjälp av movf, bsf, bcf. Ingen av instruktionerna påverkar option_reg. Är fortfarande standard värdet som är från början alltså FF=Option_reg. Fattar inte hur jag ska påverka detta register.
Här kommer koden så får ni testa och se själv fall ni kommer på felet. Programmet hoppar aldrig till timer interupt subrutinen hög.
This file is a basic code template for assembly code generation *
; on the PICmicro PIC16F84A. This file contains the basic code *
; building blocks to build upon. *
; *
; If interrupts are not used all code presented between the ORG *
; 0x004 directive and the label main can be removed. In addition *
; the variable assignments for 'w_temp' and 'status_temp' can *
; be removed. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PICmicro data sheet for additional *
; information on the instruction set. *
; *
; Template file built using MPLAB V4.00 with MPASM V2.20 and *
; MPLINK 1.20 as the language tools. *
; *
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files required: *
; *
; *
; *
;**********************************************************************
; *
; Notes: *
; *
; *
; *
; *
;**********************************************************************
list p=16F84A ; list directive to define processor
#include <p16F84.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _RC_OSC
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;**************Variabler***********************************************
Rotation EQU 1
Input EQU 1
Delay EQU 1
Delay_Temp EQU 1
inreloop EQU 1
;**************************Konstanter**************************************
; Definiera upp några konstanter
#define STOPPA_VARDE 1
#define RULLA_ENA_HALLET 2
#define RULLA_ANDRA_HALLET 4
;******************Reset_start*************************************************
;Reset and interrupt vectors
code h'0000'
goto Main
ISR_hog code h'4'
goto isr_start_hog
;***************************RULLA_ENA**********************************
RULLA_ENA_CODE code
RULLA_ENA:
bsf PORTB,0
movf Delay,W
sublw H'01'
btfsc STATUS,2
goto MinGrans
movlw H'01'
subwf Delay
MinGrans: movf Delay,W
movwf Delay_Temp
nedrakning2E: movlw H'10'
movwf inreloop
nedrakningE: decfsz inreloop
goto nedrakningE ;inreloop 10 mikrosekundersz
decfsz Delay_Temp
goto nedrakning2E
bcf PORTB,0
nop
return
;********************RULLA_ANDRA*****************************************
RULLA_ANDRA_CODE code
RULLA_ANDRA:
bsf PORTB,0
movf Delay,W
sublw H'C8'
btfsc STATUS,2
goto MaxGrans
movlw H'01'
addwf Delay
MaxGrans: movf Delay,W
movwf Delay_Temp
nedrakning2A: movlw H'10'
movwf inreloop
nedrakningA: decfsz inreloop
goto nedrakningA ;inreloop 10 mikrosekunder
decfsz Delay_Temp
goto nedrakning2A
bcf PORTB,0
nop
return
;********************STA_STILLA******************************************
STA_STILLA_CODE code
STA_STILLA:
bsf PORTB,0
movf Delay,W
movwf Delay_Temp
nedrakning2S: movlw H'10'
movwf inreloop
nedrakningS: decfsz inreloop
goto nedrakningS ;inreloop 10 mikrosekunder
decfsz Delay_Temp
goto nedrakning2S
bcf PORTB,0
nop
return
;**************Interrupt overflow**************************************************************
isr_hog_code code
isr_start_hog
; switch(Rotation)
NOP
CASE_S1
movf Rotation,W
sublw 0x02
btfss STATUS,2
goto CASE_S2
call RULLA_ENA
goto END_SUB ; break;
CASE_S2
movf Rotation,W
sublw 0x04
btfss STATUS,2
goto CASE_S3
call RULLA_ANDRA
goto END_SUB ; break;
CASE_S3
movf Rotation,W
sublw 0x01
btfss STATUS,2
goto END_SUB ; break;
Call STA_STILLA
END_SUB:
movlw h'EC'
movwf TMR0
bcf INTCON,T0IF
retfie
;***************interrupt_konfig***********************************************
;här ställer jag in konfigruerar jag pic:en EX ställer in Out/in defineras och register ställs in.
;init_code code
init
;****************************Konfig portA/portB*********************************************
movlw B'11111111'
movwf TRISA ;Sätter PortA till ingångar bit 0-7
movlw B'00000000'
movwf TRISB ;sätter PortB till ingång bit 0-7
;****************************Generella Interrupts inställningar*************
; bsf RCON,IPEN ;Enable priority levels on interrupts
; bsf INTCON,PEIE ;Enables all unmasked peripheral interrupts
bsf INTCON,GIE ;Enable global interrupts.
;*************************nollställning variabler/sätter start värden********************
clrf Rotation
clrf Input
clrf Delay
clrf Delay_Temp
clrf inreloop
movlw H'01'
movwf Delay
;********************************************************************
bcf OPTION_REG,TOCS
bcf OPTION_REG,PSA
bcf OPTION_REG,PS2
bcf OPTION_REG,PS1
bcf OPTION_REG,PS0
clrf TMR0
movlw h'EC'
movwf TMR0
bsf INTCON,T0IE
;********************************************************************
return
;*********************Main********************************************
; Start of main program
Main
call init
movlw STOPPA_VARDE ; Rotation = Stoppa_Värde
movwf Rotation
MAIN_LOOP
clrf PORTA
movf PORTA,W ; Input = PORTA & 0x03
andlw 0x03
movwf Input
; switch(Input)
CASE_1
btfss Input,0 ; Bit 0 satt?
goto CASE_2 ; Nix, hoppa vidare
movlw RULLA_ENA_HALLET ; Japp! Rotation = Rulla_Ena_Hållet
movwf Rotation
goto MAIN_LOOP ; break;
CASE_2
btfss Input,1 ; Bit 1 satt?
goto CASE_3 ; Nix, hoppa vidare
movlw RULLA_ANDRA_HALLET ; Japp!
movwf Rotation ; Rotation = Rulla_Andra_Hållet
goto MAIN_LOOP ; break;
CASE_3
btfsc Input,0 ; Bit 0 & bit 1 inte satt?
goto MAIN_LOOP ; Nix, hoppa vidare
btfsc Input,1
goto MAIN_LOOP
movlw STOPPA_VARDE ; Japp! Rotation = Stoppa_Värde
movwf Rotation
goto MAIN_LOOP ;break
;******************************************************************************
;End of program
END
Här kommer koden så får ni testa och se själv fall ni kommer på felet. Programmet hoppar aldrig till timer interupt subrutinen hög.
This file is a basic code template for assembly code generation *
; on the PICmicro PIC16F84A. This file contains the basic code *
; building blocks to build upon. *
; *
; If interrupts are not used all code presented between the ORG *
; 0x004 directive and the label main can be removed. In addition *
; the variable assignments for 'w_temp' and 'status_temp' can *
; be removed. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PICmicro data sheet for additional *
; information on the instruction set. *
; *
; Template file built using MPLAB V4.00 with MPASM V2.20 and *
; MPLINK 1.20 as the language tools. *
; *
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files required: *
; *
; *
; *
;**********************************************************************
; *
; Notes: *
; *
; *
; *
; *
;**********************************************************************
list p=16F84A ; list directive to define processor
#include <p16F84.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _RC_OSC
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;**************Variabler***********************************************
Rotation EQU 1
Input EQU 1
Delay EQU 1
Delay_Temp EQU 1
inreloop EQU 1
;**************************Konstanter**************************************
; Definiera upp några konstanter
#define STOPPA_VARDE 1
#define RULLA_ENA_HALLET 2
#define RULLA_ANDRA_HALLET 4
;******************Reset_start*************************************************
;Reset and interrupt vectors
code h'0000'
goto Main
ISR_hog code h'4'
goto isr_start_hog
;***************************RULLA_ENA**********************************
RULLA_ENA_CODE code
RULLA_ENA:
bsf PORTB,0
movf Delay,W
sublw H'01'
btfsc STATUS,2
goto MinGrans
movlw H'01'
subwf Delay
MinGrans: movf Delay,W
movwf Delay_Temp
nedrakning2E: movlw H'10'
movwf inreloop
nedrakningE: decfsz inreloop
goto nedrakningE ;inreloop 10 mikrosekundersz
decfsz Delay_Temp
goto nedrakning2E
bcf PORTB,0
nop
return
;********************RULLA_ANDRA*****************************************
RULLA_ANDRA_CODE code
RULLA_ANDRA:
bsf PORTB,0
movf Delay,W
sublw H'C8'
btfsc STATUS,2
goto MaxGrans
movlw H'01'
addwf Delay
MaxGrans: movf Delay,W
movwf Delay_Temp
nedrakning2A: movlw H'10'
movwf inreloop
nedrakningA: decfsz inreloop
goto nedrakningA ;inreloop 10 mikrosekunder
decfsz Delay_Temp
goto nedrakning2A
bcf PORTB,0
nop
return
;********************STA_STILLA******************************************
STA_STILLA_CODE code
STA_STILLA:
bsf PORTB,0
movf Delay,W
movwf Delay_Temp
nedrakning2S: movlw H'10'
movwf inreloop
nedrakningS: decfsz inreloop
goto nedrakningS ;inreloop 10 mikrosekunder
decfsz Delay_Temp
goto nedrakning2S
bcf PORTB,0
nop
return
;**************Interrupt overflow**************************************************************
isr_hog_code code
isr_start_hog
; switch(Rotation)
NOP
CASE_S1
movf Rotation,W
sublw 0x02
btfss STATUS,2
goto CASE_S2
call RULLA_ENA
goto END_SUB ; break;
CASE_S2
movf Rotation,W
sublw 0x04
btfss STATUS,2
goto CASE_S3
call RULLA_ANDRA
goto END_SUB ; break;
CASE_S3
movf Rotation,W
sublw 0x01
btfss STATUS,2
goto END_SUB ; break;
Call STA_STILLA
END_SUB:
movlw h'EC'
movwf TMR0
bcf INTCON,T0IF
retfie
;***************interrupt_konfig***********************************************
;här ställer jag in konfigruerar jag pic:en EX ställer in Out/in defineras och register ställs in.
;init_code code
init
;****************************Konfig portA/portB*********************************************
movlw B'11111111'
movwf TRISA ;Sätter PortA till ingångar bit 0-7
movlw B'00000000'
movwf TRISB ;sätter PortB till ingång bit 0-7
;****************************Generella Interrupts inställningar*************
; bsf RCON,IPEN ;Enable priority levels on interrupts
; bsf INTCON,PEIE ;Enables all unmasked peripheral interrupts
bsf INTCON,GIE ;Enable global interrupts.
;*************************nollställning variabler/sätter start värden********************
clrf Rotation
clrf Input
clrf Delay
clrf Delay_Temp
clrf inreloop
movlw H'01'
movwf Delay
;********************************************************************
bcf OPTION_REG,TOCS
bcf OPTION_REG,PSA
bcf OPTION_REG,PS2
bcf OPTION_REG,PS1
bcf OPTION_REG,PS0
clrf TMR0
movlw h'EC'
movwf TMR0
bsf INTCON,T0IE
;********************************************************************
return
;*********************Main********************************************
; Start of main program
Main
call init
movlw STOPPA_VARDE ; Rotation = Stoppa_Värde
movwf Rotation
MAIN_LOOP
clrf PORTA
movf PORTA,W ; Input = PORTA & 0x03
andlw 0x03
movwf Input
; switch(Input)
CASE_1
btfss Input,0 ; Bit 0 satt?
goto CASE_2 ; Nix, hoppa vidare
movlw RULLA_ENA_HALLET ; Japp! Rotation = Rulla_Ena_Hållet
movwf Rotation
goto MAIN_LOOP ; break;
CASE_2
btfss Input,1 ; Bit 1 satt?
goto CASE_3 ; Nix, hoppa vidare
movlw RULLA_ANDRA_HALLET ; Japp!
movwf Rotation ; Rotation = Rulla_Andra_Hållet
goto MAIN_LOOP ; break;
CASE_3
btfsc Input,0 ; Bit 0 & bit 1 inte satt?
goto MAIN_LOOP ; Nix, hoppa vidare
btfsc Input,1
goto MAIN_LOOP
movlw STOPPA_VARDE ; Japp! Rotation = Stoppa_Värde
movwf Rotation
goto MAIN_LOOP ;break
;******************************************************************************
;End of program
END