กก |
Project Maintainer: Yu Lu |
![]() |
|
|
|
|
|
|
|
|
#define MCNTRL 0x7E00 /*Main control register */
#define CCONF 0x7E01 /*Clk. config. register */
....
#define RXS3 0x7E3E /*RX status register 3 */
#define RXC3 0x7E3F /*RX command register 3 */
write to USBN9603 in C like this:
void write_usb(unsigned int usbadr, char dta);
read from USBN9603 in C like this:
char read_usb(unsigned int usbadr);
These two functions are implemented in ASM language in order for fast access.
;***************************************************************
; This subroutine is used to access USBN9603 regs , read
; USAGE: char read_usb(unsigned int usbadr);
; Argument :
; INPUT: R6&R7: address of USBN9603's reg
; OUTPUT: R7: value of that reg
;***************************************************************
_read_usb:
      PUSH DPH
      PUSH DPL
     
      MOV DPH, R6
      MOV DPL, R7
      MOVX A, @DPTR
      MOV R7,A
     
      POP DPL
      POP DPH
      RET
;***************************************************************
; This subroutine is used to access USBN9603 regs ,write
; USAGE: write_usb(unsigned int usbadr, char dta);
; Argument :
; INPUT:
; R6&R7: address of USBN9603's reg
; R5 : value to be written
; OUTPUT:
; none;
;***************************************************************
_write_usb:
      PUSH DPH
      PUSH DPL
     
      MOV DPH, R6
      MOV DPL, R7
      MOV A,R5
      MOVX @DPTR, A
     
      POP DPL
      POP DPH
      RET
void write_gps(char add, char lo, char hi);
Read from GP2021 in C like below:
void read_gps(char add, unsigned int* datadd);
These two functions are also implemented in ASM language in order for fast access.
;************************************************************
; 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);
;************************************************************
_read_gps:
      CLR EA ; disable all int
     
      MOV DPH, R4 ; set the data pointer
      MOV DPL, R5 ;
     
      MOV P0, R7 ; 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 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
      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);
;************************************************************
_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
      MOV P0, R3 ; Send LSB first
      MOV P1, R5 ; Send MSB next
      MOV P2, #0E8h ; GPS_OE=0, GPS_WR=0, GPS_CS=0
      MOV P2, #0FEh ; Idle state
      SETB EA ;
      RET
To provide the ISP function, I designed the schematic as below: