voltmeter simulation in proteus using assembly language for 8051
Voltmeter Simulation in Proteus using Assembly Language for 8051
This is voltmeter simulation in Proteus circuit simulation software. This voltmeter has a range of 0-2.56V. Atmel's 8 bit microcontroller AT89C51 is used in the project. The program code is written in Assembly language. As AT89C51 has no internal ADC, so therefore, a serial ADC IC ADC0831 is used. The result is shown on a 16x2 LCD.
Working
The output voltage from the RV1 potentiometer can be varied from 0-2.56V by turning its knob. This voltage is fed to the ADC's VIN(+) pin and also displayed by the Proteus voltmeter on the right most part of the image. The reference voltage of the ADC is set to 2.56V, therefore it can not measure voltages higher than 2.56V. If we use a series voltage divider network at the ADC VIN(+) input, we will be able to measure voltages higher than 2.56V. The analog voltage value is converted to a digital value by the ADC and read by the AT89C51 microcontroller serially using CLK and DO pins. This digital value is converted to ASCII characters by the microcontroller and displayed on a 16x2 LCD. This loop continues indefinitely.
Assembly Language Code
CS BIT P2.0
SCLK BIT P2.1
DOUT BIT P2.3
ORG 00H
MOV A,#38H ;INIT. LCD 2 LINES, 5X7 MATRIX
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#0CH ;display on, cursor on
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#01 ;clear LCD
ACALL COMNWRT ;call command subroutine
MAIN:
SETB CS ;conversion start
CLR SCLK ;configure SCLK as output
SETB DOUT ;configure DOUT as input
CLR CS
SETB SCLK ;one cycle skip as 9 pulses to get data out
ACALL DELAY
CLR SCLK
ACALL DELAY
MOV R3,#8;counter for reading 8 bits from ADC
READ:
SETB SCLK
ACALL DELAY
CLR SCLK
ACALL DELAY
MOV C,DOUT
RLC A
DJNZ R3,READ
SETB CS
MOV P1,A
ACALL DELAY ;give LCD some time
MOV A,#06H ;shift cursor right
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#84H ;cursor at line 1, pos. 4
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
ACALL HEX2ASSCI
MOV A,R4
ACALL DATAWRT ;call display subroutine
MOV A,#'.'
ACALL DATAWRT ;call display subroutine
MOV A,R5
ACALL DATAWRT ;call display subroutine
MOV A,R6
ACALL DATAWRT ;call display subroutine
MOV A,#' '
ACALL DATAWRT ;call display subroutine
MOV A,#'V'
ACALL DATAWRT ;call display subroutine
SJMP MAIN
COMNWRT: ;send command to LCD
MOV P3,A ;copy reg A to port 1
CLR P0.0 ;RS=0 for command
CLR P0.1 ;R/W=0 for write
SETB P0.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P0.2 ;E=0 for H-to-L pulse
RET
DATAWRT: ;write data to LCD
MOV P3,A ;copy reg A to port 1
SETB P0.0 ;RS=1 for data
CLR P0.1 ;R/W=0 for write
SETB P0.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P0.2 ;E=0 for H-to-L pulse
RET
HEX2ASSCI:
MOV A,P1
MOV B,#10
DIV AB
ORL B,#30H
MOV R6,B
MOV B,#10
DIV AB
ORL B,#30H
MOV R5,B
ORL A,#30H
MOV R4,A
RET
DELAY:
MOV R1,#50
HERE2:MOV R2,#250
HERE:DJNZ R2,HERE
DJNZ R1,HERE2
RET
END
SCLK BIT P2.1
DOUT BIT P2.3
ORG 00H
MOV A,#38H ;INIT. LCD 2 LINES, 5X7 MATRIX
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#0CH ;display on, cursor on
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#01 ;clear LCD
ACALL COMNWRT ;call command subroutine
MAIN:
SETB CS ;conversion start
CLR SCLK ;configure SCLK as output
SETB DOUT ;configure DOUT as input
CLR CS
SETB SCLK ;one cycle skip as 9 pulses to get data out
ACALL DELAY
CLR SCLK
ACALL DELAY
MOV R3,#8;counter for reading 8 bits from ADC
READ:
SETB SCLK
ACALL DELAY
CLR SCLK
ACALL DELAY
MOV C,DOUT
RLC A
DJNZ R3,READ
SETB CS
MOV P1,A
ACALL DELAY ;give LCD some time
MOV A,#06H ;shift cursor right
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#84H ;cursor at line 1, pos. 4
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
ACALL HEX2ASSCI
MOV A,R4
ACALL DATAWRT ;call display subroutine
MOV A,#'.'
ACALL DATAWRT ;call display subroutine
MOV A,R5
ACALL DATAWRT ;call display subroutine
MOV A,R6
ACALL DATAWRT ;call display subroutine
MOV A,#' '
ACALL DATAWRT ;call display subroutine
MOV A,#'V'
ACALL DATAWRT ;call display subroutine
SJMP MAIN
COMNWRT: ;send command to LCD
MOV P3,A ;copy reg A to port 1
CLR P0.0 ;RS=0 for command
CLR P0.1 ;R/W=0 for write
SETB P0.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P0.2 ;E=0 for H-to-L pulse
RET
DATAWRT: ;write data to LCD
MOV P3,A ;copy reg A to port 1
SETB P0.0 ;RS=1 for data
CLR P0.1 ;R/W=0 for write
SETB P0.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P0.2 ;E=0 for H-to-L pulse
RET
HEX2ASSCI:
MOV A,P1
MOV B,#10
DIV AB
ORL B,#30H
MOV R6,B
MOV B,#10
DIV AB
ORL B,#30H
MOV R5,B
ORL A,#30H
MOV R4,A
RET
DELAY:
MOV R1,#50
HERE2:MOV R2,#250
HERE:DJNZ R2,HERE
DJNZ R1,HERE2
RET
END
Comments
Post a Comment