Total members 11895 |It is currently Tue Dec 03, 2024 6:54 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Code:


;SUCCESSIVE APPROXIMATION ADC
TITLE 
"SAR ADC"
list =16f877
include <p16f877.inc>
BANK0 macro
bcf STATUS
,RP0
bcf STATUS
,RP1
endm

BANK1 macro
bsf STATUS
,RP0
bcf STATUS
,RP1
endm

BANK2 macro
bcf STATUS
,RP0
bsf STATUS
,RP1
endm

BANK3 macro
bsf STATUS
,RP0
bsf STATUS
,RP1
endm

COUNTER EQU 0x20
RESULT EQU 0x21
MASK EQU 0x22
DELAY_TIME EQU 0x23
COMP EQU 4
TEMP EQU 0x24
; ******
ORG 0
NOP
GOTO START
;****

MAIN ROUTINE
ORG 0x20
START CALL INIT 
;INITIAbISE PORTS
REPEAT MOVLW 8 
;COUNTER 0
MOVWF COUNTER
;
MOVLW 0x80 ;SET MASK.
MOVWF MASK;
MOVWF RESULT ;SET INIT RESULT



NEXT MOVF RESULT
,;GET CJRRENT RESULT VALUE
IORWF MASK
,;SET NEXT MSB
MOVWF PORTD 
;AND OUTPUT
CALL DELAY 
;ALLOW TIME TO SETTLE
BTFSS PORTA
,COMP ;TEST COMP OUTPUT
CALL SETBIT 
;IF SETCALL SETBIT
BTFSC PORTA
,COMP ;TEST COMP BIT
CALL CLEARBIT 
;ELSE CLEAR BIT
BCF STATUS
,;CLEAR CARRY FLAG
RRF MASK 
;SET NEXT MSB
MOVLW 1 
;SET DECREb€NT
SUBWF COUNTER 
;AND DECREMENT
BTFSS STATUS
,;TEST FOR LAST BIT
GOTO NEXT 
;AND DO NEXT BIT IF NOT
GOTO REPEAT 
;ELSE REPEAT
;****
SETBIT MOVWF RESULT
RETURN
CLEAR BIT
CLEARBIT
 COMF MASK
,WGET CURRENT MASK AND INVERT
 ANDWF RESULT
; AND CLEAR CURRENT BIT
 
RETURN 
PORT INITIALISATION
INIT BANK1 
set to bank1 
CLRF TRISD
SET PORT D TO OUTPUT
MOVLW 06
MAKE PORT A DIGITAL
MOVWF ADCON1
BSF TRISA
,; AND BIT A4 to INPUT
BANK0
BACK TO BANK 0
RETURN 
DELAY ROUTIN
DELAY MOVWF TEMP 
SAVE  W
      MOVLW 0x80
set delay time
      MOVWF DELAY_TIME
      
WAIT  INCFSZ DELAY_TIME 
COUNT DOWN
      GOTO WAIT
      MOVF TEMP
,W
      
RETURN 
      
END
      




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : SUCCESSIVE APPROXIMATION ANALOGUE TO DIGITAL CONVERSION
 ramp Counter ANALOGUE TO DIGITAL CONVERSION (ADC)     -  
 The Digital to Analogue converter DAC writer     -  
 digital watermark on image     -  
 .dll conversion     -  
 Type Conversion     -  
 Number Conversion     -  
 please get me the following Delphi to Java conversion     -  
 conversion from binary to decimal numbers as string     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com