Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;******************************************************************************
- ; ;******************************************************************************
- ; This file is a basic template for assembly code for a PIC18F4550. Copy *
- ; this file into your project directory and modify or add to it as needed. *
- ; *
- ; The PIC18FXXXX architecture allows two interrupt configurations. This *
- ; template code is written for priority interrupt levels and the IPEN bit *
- ; in the RCON register must be set to enable priority levels. If IPEN is *
- ; left in its default zero state, only the interrupt vector at 0x008 will *
- ; be used and the WREG_TEMP, BSR_TEMP and STATUS_TEMP variables will not *
- ; be needed. *
- ; *
- ; Refer to the MPASM User's Guide for additional information on the *
- ; features of the assembler. *
- ; *
- ; Refer to the PIC18FXX50/XX55 Data Sheet for additional *
- ; information on the architecture and instruction set. *
- ; *
- ;******************************************************************************
- ; *
- ; Filename: *
- ; Date: *
- ; File Version: *
- ; *
- ; Author: *
- ; Company: *
- ; *
- ;******************************************************************************
- ; *
- ; Files required: P18F4550.INC *
- ; *
- ;******************************************************************************
- LIST P=18F4550, F=INHX32 ;directive to define processor
- #include <P18F4550.INC> ;processor specific variable definitions
- ;******************************************************************************
- ;Configuration bits
- ;Microchip has changed the format for defining the configuration bits, please
- ;see the .inc file for futher details on notation. Below are a few examples.
- ; Oscillator Selection:
- CONFIG FOSC = XT_XT ;XT oscillator, XT used by USB
- ;******************************************************************************
- ;Variable definitions
- ; These variables are only needed if low priority interrupts are used.
- ; More variables may be needed to store other special function registers used
- ; in the interrupt routines.
- #define RX_BUF_LEN 32
- ADDRESS equ 0x22
- UDATA
- FSRsave RES 1
- PCLATHsave RES 1
- Index RES 1
- Temp RES 1
- RXBuffer RES 1
- ;example of a variable in access RAM
- ;******************************************************************************
- ;EEPROM data
- ; Data to be programmed into the Data EEPROM is defined here
- DATA_EEPROM CODE 0xf00000
- ; DE "Test Data",0,1,2,3,4,5
- memset macro Buf_addr,Value,Length
- movlw Length
- movwf Temp
- movlw Buf_addr
- movwf FSR0L
- SetNext
- movlw Value
- movwf INDF0
- incf FSR0L,F
- decfsz Temp,F
- goto SetNext
- endm
- load macro Address,Offset
- movlw Address
- movwf FSR0L
- movf Offset,W
- addwf FSR0L,F
- endm
- PRG CODE 0x00
- goto Start
- INT1 CODE 0x08
- goto Int
- INT2 CODE 0x18
- goto Int
- MAIN CODE 0x30
- ;---------------------------------------------------------------------
- ; Main Code
- ;---------------------------------------------------------------------
- Start
- clrf Index
- clrf Temp
- clrf RXBuffer
- call Setup
- Main
- goto Main
- Setup
- bsf TRISC,3
- bsf TRISC,4
- clrf FSR0L
- clrf FSR0H
- movlw ADDRESS
- movwf SSPADD
- movlw 0x36
- movwf SSPCON1
- clrf SSPSTAT
- clrf SSPCON2
- bsf SSPCON2,SEN
- bcf PIR1,SSPIF
- bsf PIE1,SSPIE
- movlw 0xC0
- movwf INTCON
- return
- Int
- movf FSR0L,W;
- movwf FSRsave
- btfss PIR1,SSPIF
- goto $
- bcf PIR1,SSPIF
- call SSP_Handler
- movf FSRsave,W
- movwf FSR0L
- bsf SSPCON1,CKP
- retfie FAST
- SSP_Handler
- movf SSPSTAT,W
- andlw b'00101101'
- movwf Temp
- State1:
- movlw b'00001001'
- xorwf Temp,W
- btfss STATUS,Z
- goto State2
- memset RXBuffer,0,RX_BUF_LEN
- clrf Index
- movf SSPBUF,W
- return
- State2:
- movlw b'00101001'
- xorwf Temp,W
- btfss STATUS,Z
- goto State3
- load RXBuffer,Index
- movf SSPBUF,W
- movwf INDF0
- incf Index,F
- movf Index,W
- sublw RX_BUF_LEN
- btfsc STATUS,Z
- clrf Index
- return
- State3:
- movf Temp,W ;
- andlw b'00101100'
- xorlw b'00001100'
- btfss STATUS,Z
- goto State4
- movf SSPBUF,W
- clrf Index
- load RXBuffer,Index
- movf INDF0,W
- call WriteI2C
- incf Index,F
- return
- State4
- movlw b'00101100'
- xorwf Temp,W
- movf Index,W
- sublw RX_BUF_LEN
- btfsc STATUS,Z
- clrf Index
- load RXBuffer,Index
- movf INDF0,W
- call WriteI2C
- incf Index,F
- return
- WriteI2C
- btfsc SSPSTAT,BF
- goto WriteI2C
- DoI2CWrite
- bcf SSPCON1,WCOL
- movwf SSPBUF
- btfsc SSPCON1,WCOL
- goto DoI2CWrite
- return
- END
Add Comment
Please, Sign In to add comment