나는 몇 개의 LED를 깜박이기 위해 PIC 18F1200을 얻으려고하고 있으며, 그렇게해서는 안된다. 저는 PIC를 2 년 넘게 16F와 18F로 프로그래밍했지만 18F1220은 이번이 처음입니다. 하나의 LED는 PortA, 7에 있으며 다른 LED는 PortB, 3에 있습니다. 인터럽트뿐만 아니라 A/D 모듈도 꺼야한다고 생각합니다. 나는 MCLR로 바뀌었고 8MHz에서 온보드 오실레이터를 사용하고있다. 데이터 시트는 나의 성경이고 나는 그것을 통해보고 있었지만, 매초마다 켜지는 것이 아니라 불규칙하게 켜지거나 꺼지는 RB3에 깜박이는 LED를 얻는 것으로 끝납니다. 누구든지 올바른 방향으로 나를 가리킬 수 있습니다. 나는 뭔가를 놓치고 있어야합니다. 모든 답장을 보내 주셔서 감사 드리며, 나는 제안을 기꺼이 테스트 해 보겠습니다.PIC 18F1220 몇 개의 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의 내용을 보면 이것이 일어나지 않았 음을 알 수 있습니다.
감사합니다.