Tuesday, May 31, 2016

8051 Program – 8-16 channel adc

; Program for Data Acquisition using ADC with 16 channel
; This can be used with any 8-16 bit ADC, with or without MUX
; channel selection on P2.0 --- P2.3: ADC Start coversion on P2.4: ADC busy on P2.5
; ADC data input at P0(lowbyte) and P1(highbyte)
; Data is output serially starting from CHANNEL1 to CHANNEL10
; Each sampling cycle is initiated by receiving 00H on serial port.
ORG 0000H
SJMP MAIN
MAIN: MOV SP,#20H
MOV SCON,#52H ;#Mode 1-8 bit uart
MOV TMOD,#21H ; # TIMER 1 IN AUTORELOAD MODE AND 0 IN 16 BIT TIMER MODE
MOV TH1,#-13D ; #2400 bit/sec buad rate
SETB TR1
CLR RI
SETB TI
MOV P2,#0FFH ; INITIALIZE
MOV A,#'S'
ACALL SEND
AGAIN: MOV SP,#20H
ACALL RECEV
CJNE A,#0H,AGAIN
; DATA SAVING SECTION
ACALL CH_1
ACALL SAVE_D1
ACALL CH_2
ACALL SAVE_D2
ACALL CH_3
ACALL SAVE_D3
ACALL CH_4
ACALL SAVE_D4
ACALL CH_5
ACALL SAVE_D5
ACALL CH_6
ACALL SAVE_D6
ACALL CH_7
ACALL SAVE_D7
ACALL CH_8
ACALL SAVE_D8
ACALL CH_9
ACALL SAVE_D9
ACALL CH_10
ACALL SAVE_D10
;DATA SENDING SECTION
ACALL SEND_D1
ACALL SEND_D2
ACALL SEND_D3
ACALL SEND_D4
ACALL SEND_D5
ACALL SEND_D6
ACALL SEND_D7
ACALL SEND_D8
ACALL SEND_D9
ACALL SEND_D10
ACALL AGAIN
; MAIN PROGRAM ENDS HERE
SAVE_D1:
ACALL START_CONV ;START CONVERSION
ACALL BANK1
MOV P0,#0FFH ; low byte
MOV R0,P0
ACALL BANK2
MOV P1,#0FFH ;high byte
MOV R0,P1
RET
SAVE_D2:
ACALL START_CONV ;START CONVERSION
ACALL BANK1
MOV P0,#0FFH ; low byte
MOV R1,P0
ACALL BANK2
MOV P1,#0FFH ;high byte
MOV R1,P1
RET
SAVE_D3:
ACALL START_CONV ;START CONVERSION
ACALL BANK1
MOV P0,#0FFH ; low byte
MOV R2,P0
ACALL BANK2
MOV P1,#0FFH ;high byte
MOV R2,P1
RET
SAVE_D4:
ACALL START_CONV ;START CONVERSION
ACALL BANK1
MOV P0,#0FFH ; low byte
MOV R3,P0
ACALL BANK2
MOV P1,#0FFH ;high byte
MOV R3,P1
RET
SAVE_D5:
ACALL START_CONV ;START CONVERSION
ACALL BANK1
MOV P0,#0FFH ; low byte
MOV R4,P0
ACALL BANK2
MOV P1,#0FFH ;high byte
MOV R4,P1
RET
SAVE_D6:
ACALL START_CONV ;START CONVERSION
ACALL BANK1
MOV P0,#0FFH ; low byte
MOV R5,P0
ACALL BANK2
MOV P1,#0FFH ;high byte
MOV R5,P1
RET
SAVE_D7:
ACALL START_CONV ;START CONVERSION
ACALL BANK1
MOV P0,#0FFH ; low byte
MOV R6,P0
ACALL BANK2
MOV P1,#0FFH ;high byte
MOV R6,P1
RET
SAVE_D8:
ACALL START_CONV ;START CONVERSION
ACALL BANK1
MOV P0,#0FFH ; low byte
MOV R7,P0
ACALL BANK2
MOV P1,#0FFH ;high byte
MOV R7,P1
RET
SAVE_D9:
ACALL START_CONV ;START CONVERSION
ACALL BANK3
MOV P0,#0FFH ; low byte
MOV R0,P0
ACALL BANK4
MOV P1,#0FFH ;high byte
MOV R0,P1
RET
SAVE_D10:
ACALL START_CONV ;START CONVERSION
ACALL BANK3
MOV P0,#0FFH ; low byte
MOV R1,P0
ACALL BANK4
MOV P1,#0FFH ;high byte
MOV R1,P1
RET
SEND:
S: JNB TI,S ;TRANSMISSION ROUTINE
CLR TI
CLR TR1
SETB TR1
MOV SBUF,A
RET
RECEV:
R: JNB RI,R ;RECEPTION ROUTINE
CLR RI
MOV A,SBUF
RET
DELAY: MOV R7,#0FFH ;DELAY REGISTER "I mSEC"
REP:
NOP
NOP
DJNZ R7,REP
MOV R7,#0H
RET
START_CONV:
CLR P2.4 ;START CONVERSION BY LOW PULSE METHOD
NOP
SETB P2.4
SETB P2.5 ; USING P2.5 AS INPUT PIN
JNB P2.5,$
JB P2.5,$ ; TC=35 uS BUSY/CONVERSION
RET
BANK1:
CLR RS0
CLR RS1
RET
BANK2:
SETB RS0
CLR RS1
RET
BANK3:
CLR RS0
SETB RS1
RET
BANK4:
SETB RS0
SETB RS1
RET
SEND_D1:
ACALL BANK2
MOV A,R0
ACALL SEND
ACALL RECEV
ACALL BANK1
MOV A,R0
ACALL SEND
ACALL RECEV
RET
SEND_D2:
ACALL BANK2
MOV A,R1
ACALL SEND
ACALL RECEV
ACALL BANK1
MOV A,R1
ACALL SEND
ACALL RECEV
RET
SEND_D3:
ACALL BANK2
MOV A,R2
ACALL SEND
ACALL RECEV
ACALL BANK1
MOV A,R2
ACALL SEND
ACALL RECEV
RET
SEND_D4:
ACALL BANK2
MOV A,R3
ACALL SEND
ACALL RECEV
ACALL BANK1
MOV A,R3
ACALL SEND
ACALL RECEV
RET
SEND_D5:
ACALL BANK2
MOV A,R4
ACALL SEND
ACALL RECEV
ACALL BANK1
MOV A,R4
ACALL SEND
ACALL RECEV
RET
SEND_D6:
ACALL BANK2
MOV A,R5
ACALL SEND
ACALL RECEV
ACALL BANK1
MOV A,R5
ACALL SEND
ACALL RECEV
RET
SEND_D7:
ACALL BANK2
MOV A,R6
ACALL SEND
ACALL RECEV
ACALL BANK1
MOV A,R6
ACALL SEND
ACALL RECEV
RET
SEND_D8:
ACALL BANK2
MOV A,R7
ACALL SEND
ACALL RECEV
ACALL BANK1
MOV A,R7
ACALL SEND
ACALL RECEV
RET
SEND_D9:
ACALL BANK4
MOV A,R0
ACALL SEND
ACALL RECEV
ACALL BANK3
MOV A,R0
ACALL SEND
ACALL RECEV
RET
SEND_D10:
ACALL BANK4
MOV A,R1
ACALL SEND
ACALL RECEV
ACALL BANK3
MOV A,R1
ACALL SEND
ACALL RECEV
RET
CH_1:
CLR P2.0
CLR P2.1
CLR P2.2
CLR P2.3
RET
CH_2:
SETB P2.0
CLR P2.1
CLR P2.2
CLR P2.3
RET
CH_3:
CLR P2.0
SETB P2.1
CLR P2.2
CLR P2.3
RET
CH_4:
SETB P2.0
SETB P2.1
CLR P2.2
CLR P2.3
RET
CH_5:
CLR P2.0
CLR P2.1
SETB P2.2
CLR P2.3
RET
CH_6:
SETB P2.0
CLR P2.1
SETB P2.2
CLR P2.3
RET
CH_7:
CLR P2.0
SETB P2.1
SETB P2.2
CLR P2.3
RET
CH_8:
SETB P2.0
SETB P2.1
SETB P2.2
CLR P2.3
RET
CH_9:
CLR P2.0
CLR P2.1
CLR P2.2
SETB P2.3
RET
CH_10:
SETB P2.0
CLR P2.1
CLR P2.2
SETB P2.3
RET
CH_11:
CLR P2.0
SETB P2.1
CLR P2.2
SETB P2.3
RET
CH_12:
SETB P2.0
SETB P2.1
CLR P2.2
SETB P2.3
RET
CH_13:
CLR P2.0
CLR P2.1
SETB P2.2
SETB P2.3
RET
CH_14:
SETB P2.0
CLR P2.1
SETB P2.2
SETB P2.3
RET
CH_15:
CLR P2.0
SETB P2.1
SETB P2.2
SETB P2.3
RET
CH_16:
SETB P2.0
SETB P2.1
SETB P2.2
SETB P2.3
RET
END



Related topics:
8051 Program - serial port autobaud   |   8051 Program - running led   |   8051 Program - 32bit multiplication   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051

No comments:

Post a Comment