📄 app_1169.asm
字号:
;******************************************************************************
; Filename: APP_1169 (Absolute Code Version)
; Date: 8/22/03
; File Version: 1.1
;
; Author: Ted Salazar
; Company: Maxim
;
;
; Description: This program gives Maxim customers a working example
; of interfacing to the MAX1169 16-bit I2C ADC using
; the PIC18F442's internal MSSP I2C peripheral.
;
;
; History:
; 08/22/03: Upgraged UART baud rate from 2400bps to 115.2kbps
; 08/22/03: Moved UART "OK" & LF after initializing PORTC
; 05/19/03: PIC18F442 HWI2C peripheral code now working
;******************************************************************************
;
; Files required: P18F442.INC
;
;******************************************************************************
radix hex ;Default to HEX
LIST P=18F442, F=INHX32 ;Directive to define processor and file format
#include <P18F442.INC> ;Microchip's Include File
;******************************************************************************
;******************************************************************************
; Bit Definitions
xmit equ 06 ; Asynchronous TX is at C6
;
;******************************************************************************
;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.
CBLOCK 0x080
WREG_TEMP ;variable used for context saving
STATUS_TEMP ;variable used for context saving
BSR_TEMP ;variable used for context saving
;
ENDC
CBLOCK 0x000
EXAMPLE ;example of a variable in access RAM
data0
data0_temp
data1_temp
temp
xmtreg
cntrb
cntra
bitctr
tcount
xcount
;
ENDC
;******************************************************************************
;Reset vector
; This code will start executing when a reset occurs.
ORG 0x0000
goto Main ;go to start of main code
;******************************************************************************
;High priority interrupt vector
; This code will start executing when a high priority interrupt occurs or
; when any interrupt occurs if interrupt priorities are not enabled.
ORG 0x0008
bra HighInt ;go to high priority interrupt routine
;******************************************************************************
;Low priority interrupt vector and routine
; This code will start executing when a low priority interrupt occurs.
; This code can be removed if low priority interrupts are not used.
ORG 0x0018
movff STATUS,STATUS_TEMP ;save STATUS register
movff WREG,WREG_TEMP ;save working register
movff BSR,BSR_TEMP ;save BSR register
; *** low priority interrupt code goes here ***
movff BSR_TEMP,BSR ;restore BSR register
movff WREG_TEMP,WREG ;restore working register
movff STATUS_TEMP,STATUS ;restore STATUS register
retfie
;******************************************************************************
;High priority interrupt routine
; The high priority interrupt code is placed here to avoid conflicting with
; the low priority interrupt vector.
HighInt:
; *** high priority interrupt code goes here ***
retfie FAST
;******************************************************************************
;Start of main program
; The main program code is placed here.
Main:
; *** main code goes here ***
start
movlw 0x0FF
movwf PORTB
clrf PORTA
movlw 0x06 ;T Configure PortA as Digital
movwf ADCON1
movlw 0x00FB ;T A2 OUTPUT, ALL OTHERS INPUT
movwf TRISA
movlw 0x0001 ;T B0 INPUT, ALL OTHERS OUTPUT
movwf TRISB
;******************************************************************************
HWI2C_init ;T I2C MSSP Initialization for M2EAM schematic
movlw 0x00BF ;T C6 (TX) OUTPUT, ALL OTHER C's INPUTs
movwf TRISC
movlw 0x0028 ;T turn MSSP ON & I2C MASTER
movwf SSPCON1 ;T used to be sspcon
movlw 0x0000 ;T I2C FAST Mode Slew Rate Setting
movwf SSPSTAT ;T used to be sspstat
movlw 0x0018 ;T SSPADD = (FOSC/(4*SCL)) -1 => 400kHz @ 40MHz
movwf SSPADD ;T used to be sspadd
;******************************************************************************
;
bsf PORTC,xmit
dly clrf bitctr
dly0 call full
decfsz bitctr,f
goto dly0
;
movlw 0x4F ; 'O' = 0x4F
movwf xmtreg
call asyxmtc
movlw 0x4B ; 'K' = 0x4B
movwf xmtreg
call asyxmtc
movlw 0x0D ; CR = Carriage Return = 0x0D
movwf xmtreg
call asyxmtc
movlw 0x0A ; LF = Line Feed = 0x0A
movwf xmtreg
call asyxmtc
;******************************************************************************
;
InitializeMAX1169
; *** InitializeMAX1169 code goes here ***
; No code Required...
; Ensure ADD[3:0] make slave address 0x7F
; on the PCB hardware.
; Ensure REFADJ is NOT tied to AVDD so
; that internal reference mode is enabled
ContinuousReadMAX1169
; *** ContinuousReadMAX1169 code goes here ***
call HWI2C_start ; I2C read
movlw 0x7F ; load w with literal
call HWI2C_W_slaveAddr ; Call Slave_Address Function w/ R = 1
btfsc STATUS,0 ; Bit0 = C Flag; C Flag set = error
goto errorsr ; Goto the error service routine
loop4ever
;1st 8-bits
call delay ; Clock Stretch for tconv
call HWI2C_readMore_W ;
btfsc SSPCON2,ACKSTAT ; Is there an error?
goto errorsr ; Goto the error service routine
movf data0,w ; Move received data in data0 to w
movwf data0_temp ; Move w to data0_temp
;2nd 8-bits
call HWI2C_readMore_W ;
btfsc SSPCON2,ACKSTAT ; Is there an error?
goto errorsr ; Goto the error service routine
movf data0,w ; Move received data in data0 to w
movwf data1_temp ; Move w to data1_temp to make program
; easier to follow
; Perform Asynchronous comm
movf data0_temp,w ; Move received data in data0_temp to w
movwf xmtreg ; Move w to xmtreg
call asyxmtc ; Call UART routine
movf data1_temp,w ; Move received data in data0_temp to w
movwf xmtreg ; Move w to xmtreg
call asyxmtc ; Call UART routine
goto loop4ever ; Goto the endless loop
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -