Voltage Reader
This project is based on Motorola Microcontroller M68HC11A8. The system Voltage
Reader is used to read the analog voltage in different devices connected to the
controller and display the corresponding digital value.
To simulate this circuit, initially activate Mixed Mode simulator from the
Schematic Editor window. Simulation can be performed by selecting Transient
analysis from Simulation menu.
This project includes microcontroller M68HC11A8, LCD driver (HD44780U), 2-line
LCD display unit, analog voltage sources.
In this project instead of different devices, analog voltage sources are
connected to each pin of the ADC port (PORTE) of Microcontroller M68HC11A8. The
voltage sources connected have different predefined voltage set to it. A LCD
display unit is interfaced with the controller through LCD driver at PORTC. The
controller reads any one of the analog pin, the inbuilt ADC in microcontroller
convert value to corresponding digital value. The digital value is then given to
LCD driver there after it is displayed in LCD display unit.
The source code written either in C or Assembly language can be viewed from the
code editor window.
The program is as shown:
START: LDX REGBAS
LDS #0XFF ; INITIALIZE STACK
LDAA #0XFF ; SET PORT C FOR OUTPUT
STAA 0X1007
LDAA #0X00 ; CLEAR PORTS A C & DDRC
STAA 0X1003
STAA 0X1000
STAA 0X1007
LDAA #0XFF ; SET PORT C FOR OUTPUT
STAA 0X1007
LDAA #56 ; FUNCTION SET
BSR COMMAND
LDAA #0X0C ; DISPLAY ON
BSR COMMAND
LDAA #0X06 ; CURSER MOVE
BSR COMMAND
LDAA #0X80 ; FIRST LINE
BSR COMMAND
LDAA #'E' ; WRITE CHARACTER
BSR DISPLAY
LDAA #'D' ; WRITE CHARACTER
BSR DISPLAY
LDAA #'W' ; WRITE CHARACTER
BSR DISPLAY
LDAA #'I' ; WRITE CHARACTER
BSR DISPLAY
LDAA #'N' ; WRITE CHARACTER
BSR DISPLAY
LDAA #'X' ; WRITE CHARACTER
BSR DISPLAY
LDAA #'P' ;WRITE CHARACTER
BSR DISPLAY
LDAA #0X01
BSR COMMAND
LDAA #0XFF
STAA CH
AGAIN: BSR ADC
LDAA ADR1 ;READ A/D RESULT 1
BSR CONVERT
BSR ADC
LDAA ADR2 ;READ A/D RESULT 2
BSR CONVERT
BSR ADC
LDAA ADR3 ;READ A/D RESULT 3
BSR CONVERT
BSR ADC
LDAA ADR4 ;READ A/D RESULT 4
BSR CONVERT
JMP AGAIN
WAI
ADC: INC CH
LDAA #0X08
CMPA CH
BNE DO
CLR CH
DO: BSR LCD
LDAA CH
ADDA #0X30 ;WRITE CHARACTER
BSR DISPLAY
CLR PORTB ;INIT PORT B
LDAA #0B11000000 ;A/D POWER UP
STAA OPTION
JSR DELAY
LDAB #0B00110000 ;CONTINUOUS:MULTI:PE0 INIT A/D
LDAA CH
ABA
STAA ADCTL
BACK: BRCLR 0X0030,X #0B10000000 GO
BRA BACK
GO: RTS
LCD: LDAA #0X80 ;FIRST LINE
BSR COMMAND
LDAA #'D' ;WRITE CHARACTER
BSR DISPLAY
LDAA #'E' ;WRITE CHARACTER
BSR DISPLAY
LDAA #'V' ;WRITE CHARACTER
BSR DISPLAY
LDAA #'I' ;WRITE CHARACTER
BSR DISPLAY
LDAA #'C' ;WRITE CHARACTER
BSR DISPLAY
LDAA #'E' ;WRITE CHARACTER
BSR DISPLAY
LDAA #' ' ;WRITE CHARACTER
BSR DISPLAY
RTS
COMMAND: STAA 0X1003 ;OUT PUT THE COMMAND
LDAA #0X20 ;SET ENABLE PIN
STAA 0X1000
BSR DELAY ;DELAY
LDAA #0X00 ;CLEAR ENABLE
STAA 0X1000
RTS ; RETURN
DISPLAY: STAA 0X1003 ;OUTPUT THE VALUE TO PORT C
LDAA #0X30 ;SET THE ENABLE & RS PIN
STAA 0X1000
JSR DELAY ;DELAY
LDAA #0X10 ;CLEAR ENABLE
STAA 0X1000
RTS ; RETURN
CONVERT: STAA HEX ;HEX TO DECIMAL CONVERSION
LDAB #0X30
STAB ONE
STAB TEN
STAB HUN
DO1: CLC
SUBA #100
BCC LOOP1
BRA GO1
LOOP1: INC HUN
BRA DO1
GO1: ADDA #100
GO2: CLC
SUBA #10
BCC LOOP2
BRA GO3
LOOP2: INC TEN
BRA GO2
GO3: ADDA #10
ADDA ONE
STAA ONE
LDAA #0XC3 ;NEXT LINE
BSR COMMAND
BSR DELAY
LDAA HUN
BSR DISPLAY
LDAA TEN
BSR DISPLAY
LDAA ONE
BSR DISPLAY
LDAA #'V'
BSR DISPLAY
RTS
DELAY: LDAB #0X0E ;LOAD ACC. B
WAIT_L: DECB ;DECREMENT ACC. B
CMPB #0X00 ;COMPARE B=0
BNE WAIT_L ;LOOP IF NOT EQ
RTS ;RETURN
The source code in the
code editor window
has to be
compiled
after making any modifications
(editing).
Also the code can be
debugged
during
simulation.