📄 gp2021.a51
字号:
;*********************************************************************************
; Module description:
; This file is used to read/write GP2021 regs,
; It is written in ASM in order to fast the access
;
;
;Author : Yu Lu ,
; luyu1974@gmail.com
;
;*********************************************************************************/
NAME GP2021_MD
PUBLIC _read_gps, _write_gps, _get_gp2021_6ch_accum,_get_gp2021_6ch_cntl,ser_hexasc, ser_dispchar,_write_gps_noint
PUBLIC _get_gp2021_epochchk
USING 0
SUB_GP2021 SEGMENT CODE
DAT_GP2021 SEGMENT DATA OVERLAYABLE
DPS EQU 86H ; this is control register of dual DPTRs in DS89C420
; ID1: DPS.7
; ID0: DPS.6
; TSL: DPS.5
; AID: DPS.4
; SEL: DPS.0
; The following values are for offset=0
CH0_CNTL EQU 00H
CH6_CNTL EQU 30H
CH0_ACCM EQU 84H
CH6_ACCM EQU 9cH
CH0_ACCM_RST EQU 85H
CH6_ACCM_RST EQU 9dH
RSEG DAT_GP2021
TEMP: DS 1
RSEG SUB_GP2021
;************************************
;sbit GPS_ALE = P2^0;
;sbit GPS_WR = P2^1;
;sbit GPS_CS = P2^2;
;sbit GPS_RD = P2^3;
;sbit GPS_OE = P2^4;
;**************************************/
;************************************************************
; This subroutine is used to send a char to serial in ASCII (hex)
; Argument: A --> lower 4 bits are hex char( 0-F)
; just for debugging
;************************************************************
ser_hexasc:
ANL A,#0Fh ; Make sure we're working with only
; one nibble.
CJNE A,#0Ah,HA1 ; Test value range.
HA1: JC HAVal09 ; Value is 0 to 9.
ADD A,#7 ; Value is A to F, extra adjustment.
HAVal09: ADD A,#'0'
RET
;*******************************************************
; Here is an example to display the value of R7
;*******************************************************
; mov A,R7 ;
; swap A
; lcall ser_hexasc;
; mov sbuf , A;
; jnb TI, $
; clr TI
; mov A,R7
; lcall ser_hexasc;
; mov sbuf , A;
; jnb TI, $
; clr TI
;************************************************************
; This subroutine is used to send a char to serial in ASCII (hex)
; Argument:
; INPUT : A : the char to be sent to serport
; just for debugging
;************************************************************
ser_dispchar:
push acc
MOV TEMP, A
SWAP A
LCALL ser_hexasc;
MOV SBUF, A
JNB TI, $
CLR TI
MOV A, TEMP
LCALL ser_hexasc;
MOV SBUF, A
JNB TI, $
CLR TI
pop acc
RET
;************************************************************
; This subroutine is used to read one data(16bit) from gp2021
; Argument:
; INPUT: R7 --> address
; R4,R5 --> pointer for stored data
; OUTPUT:
; NONE
; USAGE :
;; read_gps(char add, unsigned int* datadd);
;************************************************************
/* old one :
#define read_gps() {\
EA = 0; \
P0 = gps_add; \
P2 = 0xEF; \
P2 = 0xEE; \
P0 = 0xff; \
P1 = 0xff; \
P2 = 0xE2; \
gps_lodat = P0; \
gps_hidat = P1; \
P2 = 0xFE; \
EA = 1;}
*/
_read_gps:
CLR EA ; disable all int
push DPH
push DPL
MOV DPH, R2 ; set the data pointer
MOV DPL, R1 ;
MOV P0, R7 ; send address first
MOV P2,#0EFh ; GPS_OE=0, GPS_ALE = 1
MOV P2,#0EEh ; GPS_OE=0, GPS_ALE = 0
NOP
MOV P0,#0FFh ; setup P0 and P1
MOV P1,#0FFh ;
MOV P2,#0E2h ; GPS_OE=0, GPS_RD = 0, GPS_CS = 0
NOP
MOV A, P0 ;
MOVX @DPTR, A ; Store the first byte
MOV A, P1 ;
INC DPTR ; data pointer ++
MOVX @DPTR, A ; store the second one
MOV P2, #0FEh ; Idle state
pop DPL
pop DPH
SETB EA ;
RET
;************************************************************
; This subroutine is used to write one data(16bit) to gp2021
; Argument:
; INPUT: R7 --> address
; R5,R3 --> MSB & LSB CHAR
; OUTPUT:
; NONE
; USAGE :
; write_gps(char add, char lo, char hi);
;************************************************************
;#define write_gps() {\
;EA = 0; \
;P0 = gps_add; \
;P2 = 0xEF; \
;P2 = 0xEE; \
;P0 = gps_lodat; \
;P1 = gps_hidat; \
;P2 = 0xE8; \
;P2 = 0xFE; \
;EA = 1;}
_write_gps:
CLR EA ; disable all int
MOV P0, R7 ; send address first
MOV P2, #0EFh ; GPS_OE=0, GPS_ALE = 1
MOV P2, #0EEh ; GPS_OE=0, GPS_ALE = 0
NOP
MOV P0, R3 ; Send LSB first
MOV P1, R5 ; Send MSB next
MOV P2, #0E8h ; GPS_OE=0, GPS_WR=0, GPS_CS=0
NOP
MOV P2, #0FEh ; Idle state
SETB EA ;
RET
; write_gps function without disable int , used in int service routine
_write_gps_noint:
MOV P0, R7 ; send address first
MOV P2, #0EFh ; GPS_OE=0, GPS_ALE = 1
MOV P2, #0EEh ; GPS_OE=0, GPS_ALE = 0
NOP
MOV P0, R3 ; Send LSB first
MOV P1, R5 ; Send MSB next
MOV P2, #0E8h ; GPS_OE=0, GPS_WR=0, GPS_CS=0
NOP
MOV P2, #0FEh ; Idle state
NOP
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; temporary function called by _get_gp2021_all
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
get_all_temp:
MOV P0, R1 ; send address first
MOV P2,#0EFh ; GPS_OE=0, GPS_ALE = 1
MOV P2,#0EEh ; GPS_OE=0, GPS_ALE = 0
MOV P0,#0FFh ; setup P0 and P1
MOV P2,#0E2h ; GPS_OE=0, GPS_RD = 0, GPS_CS = 0
NOP ;
MOV A, P0 ;
MOVX @DPTR, A ; Store the first byte
CJNE R1, #83H, get_a_temp0
MOV R4,A ; get ACCUM_STATUS_B
get_a_temp0:
MOV A, P1 ;
; INC DPTR ; data pointer ++
MOVX @DPTR, A ; store the second one
; INC DPTR ;
CJNE R1,#83H, get_a_temp1
MOV R5, A
get_a_temp1:
MOV P2, #0FEh ; Idle state
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Get measurement for CH0--CH5
; This function should be called only when TIC heppened
; Argument:
; INPUT: R6 R7 --> address pointer, MSB&LSB
; USAGE :
; get_gp2021_6ch_cntl( (int*) addr);
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_get_gp2021_6ch_cntl:
PUSH DPH
PUSH DPL
MOV DPH, R6
MOV DPL, R7 ; get xram data pointer first
ORL DPS, #10H
MOV P1,#0FFh ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; get data from 0x00 --- 0x2f , which are ch0-ch5 data
MOV R1, #CH0_CNTL ; set first address of GP2021 reg
GET_6CH0: ;
LCALL get_all_temp
INC R1 ; address of GP2021 ++
CJNE R1, #CH6_CNTL, GET_6CH0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ANL DPS, #0EFH
POP DPL
POP DPH
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Get epoch_chk for CH0--CH5
; This function should be called when TIC doesn't heppen
; Argument:
; INPUT: R6 R7 --> address pointer, MSB&LSB
; USAGE :
; get_gp2021_epochchk((int*) addr)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;( (int*) addr);
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_get_gp2021_epochchk:
PUSH DPH
PUSH DPL
MOV DPH, R6
MOV DPL, R7
ORL DPS, #10H
MOV P1, #0FFH
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; get data of epoch_check , 0x07, 0x0f, 0x17,0x1f,0x27, 0x2f
MOV R1, #07H
GET_EPOCH0:
LCALL get_all_temp
MOV A,R1
ADD A, #08H
MOV R1,A
CJNE R1, #37H, GET_EPOCH0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ANL DPS, #0EFH
POP DPL
POP DPH
RET
;*****************************************************************
;This subroutine is used to get 6 channel's accumulation data
; and store the data into the pointer dedicated by R6 & R7
; ARGUMENT:
; INPUT : R6 & R7 --> address pointer, MSB&LSB
;
; USAGE :
; get_gp2021_6ch_accum( (int*) addr)
;***********************************************
_get_gp2021_6ch_accum:
PUSH DPH
PUSH DPL
MOV DPH, R6
MOV DPL, R7 ; get xram data pointer first
ORL DPS, #10H
MOV P1,#0FFh ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; get data from 0x80---0x84, which are status regs
MOV R1, #80H
GET_8CH1:
LCALL get_all_temp
INC R1
CJNE R1, #84H, GET_8CH1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; get data from 0x84---0x9b, which are ch0-ch5 accum
MOV R1, #CH0_ACCM
GET_8CH2:
LCALL get_all_temp
INC R1
CJNE R1, #CH6_ACCM, GET_8CH2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ANL DPS, #0EFH
MOV R3,#CH0_ACCM_RST ; channel 0 ACCUM_RESET reg
NXT_CH:
CJNE R3, #CH6_ACCM_RST,CON_CH
AJMP EXT_CH
CON_CH:
MOV A,R4
JNB ACC.0, NON_RST_CH ;
MOV P0, R3 ; send address first
MOV P2, #0EFh ; GPS_OE=0, GPS_ALE = 1
MOV P2, #0EEh ; GPS_OE=0, GPS_ALE = 0
MOV P0, #0 ; Send LSB first
MOV P1, #0 ; Send MSB next
MOV P2, #0E8h ; GPS_OE=0, GPS_WR=0, GPS_CS=0
MOV P2, #0FEh ; Idle state
NON_RST_CH:
RR A ; right rotate one bit
MOV R4,A
MOV A, #04
ADD A, R3
MOV R3,A
AJMP NXT_CH
EXT_CH:
POP DPL
POP DPH
RET
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -