您当前的位置:五五电子网电子知识单元电路接口电路MAX5581接口: MAX5581快速建立DAC与PIC微控制器的接口 正文
MAX5581接口: MAX5581快速建立DAC与PIC微控制器的接口

MAX5581接口: MAX5581快速建立DAC与PIC微控制器的接口

点击数:7696 次   录入时间:03-04 11:36:41   整理:http://www.55dianzi.com   接口电路
;                                                        

www.55dianzi.com ;                    
;******************************************************************************
 radix hex               ;Default to HEX
 LIST P="18F442", F="INHX32" ;Directive to define processor and file format
 #include  ;MICroChip's Include File
;*************************************************** ***************************
;******************************************************************************
xmit    equ  06   ; Asynchronous TX is at C6
;
;******************************************************************************
;Configuration bits
; The __CONFIG directive defines configuration data within the .ASM file.
; The labels following the directive are defined in the P18F442.INC file.
; The PIC 18FXX2 Data Sheet explains the functions of the configuration bits.
; Change the following lines to suit your application.

;T __CONFIG _CONFIG1H, _OSCS_OFF_1H & _RCIO_OSC_1H
;T __CONFIG _CONFIG2L, _BOR_ON_2L & _BORV_20_2L & _PWRT_OFF_2L
;T __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
;T __CONFIG _CONFIG3H, _CCP2MX_ON_3H
;T __CONFIG _CONFIG4L, _STVR_ON_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
;T __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L
;T __CONFIG _CONFIG5H, _CPB_ON_5H & _CPD_OFF_5H
;T __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
;T __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
;T __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
;T __CONFIG _CONFIG7H, _EBTRB_OFF_7H

;******************************************************************************
;Variable definitions
; Th

www.55dianzi.com ese 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 aCC ess RAM
  ;
  temp     ;
  temp2 
  ;
  xmtreg   ;
  cntrb    ;
  cntra    ;
  bitCTR   ;

  tcount ;
  speedLbyte ;T Being used in HWSPI_speed
  ;
  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 ***


  

www.55dianzi.com 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   
; *** Port Initialization ***
    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

         movlw 0x0093     ;T C7-C0 => bit7-0
            ;T OUTPUTs: C6(TX), C5(MOSI), C3(SCLK), C2(CS)
            ;T INPUTs:C4 (MISO) and all others
    movwf TRISC       ;T TRISC bit3 Master = 0  
    bs

www.55dianzi.com f PORTC,RC2 ;T RC2 = CS\ Make CS\ high

;     *** SPI Initialization ***
  call HWSPI_init      ;T Initialize the MSSP for SPI
;     *** SPI Configuration ***
         movlw b'00000000'  ;T load W with test byte for CPOLCPHA 0,0
     ;T b'00000000' => CPOLCPHA 0,0
     ;T b'00000001' => CPOLCPHA 0,1
 & nbsp;   ;T b'00000010' => CPOLCPHA 1,0
     ;T b'00000011' => CPOLCPHA 1,1
         call HWSPI_W_configure
;     *** SPI Speed  ***
         movlw b'00000000'  ;T load W with test byte for SPI Freq

上一页  [1] [2] [3]  下一页


本文关键字:控制器  接口  接口电路单元电路 - 接口电路