我正在尝试让PIC 18F1200闪存几个LED,这应该不难。我已经用装配编程PICs超过两年,包括16F和18F,但这是18F1220的第一次。一个LED在PortA上,7个,另一个在PortB上,3。我想我正在关闭A / D模块以及中断。我已经转向MCLR而我正在使用8 MHz的板载振荡器。数据表是我的圣经,我一直在浏览它,但我最终得到的RB3闪烁的LED每秒都没有开启和关闭,而是不规则地闪烁。任何人都可以指出我正确的方向。我肯定错过了什么。感谢您的回复,我很乐意测试任何建议。
这是我目前的代码:
;******************************************************************************
LIST P=18F1220 ;directive to define processor
#Include <P18F1220.INC> ;processor specific variable definitions
; Compiler Directives:
Radix Dec
;******************************************************************************
; Configuration Bits:
CONFIG OSC = INTIO2 ; Internal RC, OSC1 as RA7, OSC2 as RA6
CONFIG FSCM = OFF ; Fail Safe Clock Monitor Disabled
CONFIG IESO = OFF ; Internal External Switch Over Mode Disabled
CONFIG PWRT = OFF ; Power-Up Timer Disabled
CONFIG BOR = OFF ; Brown-out Reset disabled in hardware and software
CONFIG BORV = 27 ; Brown-out Voltage bits
CONFIG WDT = OFF ; HW Disabled - SW Controlled
CONFIG WDTPS = 1 ; Watchdog Timer Postscale Select bits
CONFIG MCLRE = OFF ; MCLR Disabled
CONFIG STVR = OFF ; Stack full/underflow will not cause Reset
CONFIG LVP = OFF ; Single-Supply ICSP disabled
CONFIG DEBUG = OFF ; Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
CONFIG CP0 = OFF ; Block 0 (000800-001FFFh) not code-protected
CONFIG CP1 = OFF ; Block 1 (002000-003FFFh) not code-protected
CONFIG CPB = OFF ; Boot block (000000-0007FFh) not code-protected
CONFIG CPD = OFF ; Data EEPROM not code-protected
CONFIG WRT0 = OFF ; Block 0 (000800-001FFFh) not write-protected
CONFIG WRT1 = OFF ; Block 1 (002000-003FFFh) not write-protected
CONFIG WRTB = OFF ; Configuration registers (300000-3000FFh) not write-protected
CONFIG WRTC = OFF ; Boot block (000000-0007FFh) not write-protected
CONFIG WRTD = OFF ; Data EEPROM not write-protected
CONFIG EBTR0 = OFF ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
CONFIG EBTR1 = OFF ; Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
CONFIG EBTRB = OFF ; Boot block (000000-0007FFh) not protected from table reads executed in other blocks
;******************************************************************************
; Variable definitions
CBLOCK 0x080
Count1
CountA
CountB
ENDC
;******************************************************************************
; Reset vector
ORG 0x0000
GOTO Main ; Go to Start of Main Code
;******************************************************************************
; High priority interrupt vector
ORG 0x0008
BRA HighInt ; Go to High Priority Interrupt Routine
;******************************************************************************
; Low Priority Interrupt Vector and Routine
ORG 0x0018
BRA LowInt
;******************************************************************************
; High Priority Interrupt Routine
HighInt:
MOVLW 0x00
MOVWF EEADR
BCF EECON1,EEPGD ; Point to DATA memory
BCF EECON1,CFGS ; Access EEPROM
BSF EECON1,RD ; EEPROM Read
INCF EEDATA,F
BCF EECON1,EEPGD ; Point to DATA memory
BCF EECON1,CFGS ; Access EEPROM
BSF EECON1,WREN ; Enable writes
MOVLW 55h ; REQUIRED SEQUENCE
MOVWF EECON2 ; | Write 55h
MOVLW 0AAh ; |
MOVWF EECON2 ; | Write 0AAh
BSF EECON1,WR ; ----- Set WR bit to begin write
BCF EECON1,WREN ; Disable writes on write complete (EEIF set)
BTFSS PIR2,EEIF ; Check to See if Interrupt Flag Has Been Set
GOTO $-2 ; Not Set (Write In Progress), Go Back & Check Again
BCF PIR2,EEIF ; Clear EEIF Interrupt Flag
RETFIE FAST
LowInt:
MOVLW 0x01
MOVWF EEADR
BCF EECON1,EEPGD ; Point to DATA memory
BCF EECON1,CFGS ; Access EEPROM
BSF EECON1,RD ; EEPROM Read
INCF EEDATA,F
BCF EECON1,EEPGD ; Point to DATA memory
BCF EECON1,CFGS ; Access EEPROM
BSF EECON1,WREN ; Enable writes
MOVLW 55h ; REQUIRED SEQUENCE
MOVWF EECON2 ; | Write 55h
MOVLW 0AAh ; |
MOVWF EECON2 ; | Write 0AAh
BSF EECON1,WR ; ----- Set WR bit to begin write
BCF EECON1,WREN ; Disable writes on write complete (EEIF set)
BTFSS PIR2,EEIF ; Check to See if Interrupt Flag Has Been Set
GOTO $-2 ; Not Set (Write In Progress), Go Back & Check Again
BCF PIR2,EEIF ; Clear EEIF Interrupt Flag
RETIE
;******************************************************************************
; Start of Main Program
Main:
CALL INITIALIZE
FlashLED:
BSF LATB,3 ; Turn On LED
BCF LATA,7
CALL Delay1S ; Wait 1 Second
BCF LATB,3 ; Turn Off LED
BSF LATA,7
CALL Delay1S ; Wait 1 Second
GOTO FlashLED
;******************************************************************************
INITIALIZE:
MOVLW 0x72 ; SET INTERNAL OSCILLATOR FREQUENCY
MOVWF OSCCON ; INITIALIZE
MOVLW 0x00 ;
MOVWF INTCON ; Disable Interrupts
MOVLW 0x80 ; |
MOVWF INTCON2 ; |
MOVLW 0x00 ; |
MOVWF INTCON3 ; |
MOVWF PIE1 ; |
MOVWF PIE2 ; |
MOVWF RCON ; Disables Interrupts
MOVLW 0X00 ; SET UP PORTB TO BE ALL OUTPUTS
MOVWF TRISB ; INITIALIZE
CLRF PORTB ; CLEAR PORTB OUTPUTS
MOVLW 0X00 ; SET UP PORTA TO BE ALL OUTPUTS
MOVWF TRISA ; INITIALIZE
CLRF PORTA ; CLEAR PORTA
MOVLW 0X00 ; SET UP ADC
MOVWF ADCON0 ; ENABLE ADC, BUT DO NOT START CONVERSION
MOVLW 0XFF ; SET UP ADC
MOVWF ADCON1 ; AN0/RA0=ANALOG INPUT
CALL Delay50
RETURN
; ===== MilliSecond Delay Subroutines ===== (48 MHz Clock)
Delay255
MOVLW 0xFF ; Delay 255 MilliSeconds
GOTO D0
Delay100
MOVLW 0x64 ; Delay 100 MilliSeconds
GOTO D0
Delay50
MOVLW 0x32 ; Delay 50 MilliSeconds
GOTO D0
Delay20
MOVLW 0x14 ; Delay 20 Milliseconds
GOTO D0
Delay5
MOVLW 0x05 ; Delay 5.000 MilliSeconds
D0 MOVWF Count1
Delay1
MOVLW 0x5F ; Delay 1.000 MilliSeconds
MOVWF CountA
MOVLW 0x0A
MOVWF CountB
MSDelay
DECFSZ CountA,F
GOTO SKP
DECFSZ CountB,F
SKP GOTO MSDelay
DECFSZ Count1,F
GOTO Delay1
RETURN
; ===== 1 Second Delay Subroutine =====
Delay1S ; 11,999,993 Cycles
MOVLW 0x6C
MOVWF Count1
MOVLW 0x29
MOVWF CountA
MOVLW 0x1B
MOVWF CountB
Delay1S_Sub
DECFSZ Count1,F
GOTO SKP1
DECFSZ CountA,F
SKP1 GOTO SKP2
DECFSZ CountB,F
SKP2 GOTO Delay1S_Sub
NOP ; 3 Cycles
NOP
NOP
RETURN ; 4 Cycles (Including Call)
; ===== 100 MicroSecond Delay Subroutine =====
Delay100uS ; 1,193 Cycles
MOVLW 0xEE
MOVWF Count1
MOVLW 0x01
MOVWF CountA
Delay_100uS_Sub
DECFSZ Count1,F
GOTO SKP3
DECFSZ CountA,F
SKP3 GOTO Delay_100uS_Sub
NOP ; 3 Cycles
NOP
NOP
RETURN ; 4 Cycles (Including Call)
;******************************************************************************
END ;End of Program
添加了EEPROM读写序列,以查看其中一个中断是否被触发。查看EEPROM内容表明这不是正在发生的事情。
感谢您的期待!
答案 0 :(得分:2)
你有一个错字!
您的LowInt
中断未以RETFIE
指令结束,而是以标签RETIE
结束。