Académique Documents
Professionnel Documents
Culture Documents
**
*
Voltage Display-A/D Converter
*
*
The A/D converter starts functioning once the OPTIONS and ADCTL
*
*
registers are set and an analog voltage is supplied to it.
*
*
*
*
To get the digital value read the register ADR1.
*
*
The values obtained form this register is in binary.
*
*
They should be converted to decimal before displaying on the LCD.
*
************************************************************************
**
*org $fffe
address
*fdb MAIN
*end
LCDCMD
equ
$b5f0
LCDDATA
equ
$b5f1
DMODE20X4
equ
$3c
CSRHOME
equ
$01
DCBON
equ
$0f
cursor and blinking on
CINSHOFF
equ
$06
shift off
SCSHR
equ
$14
CSRHME
equ
$02
LINE1
equ
$80
LINE2
equ
$80+$28
LINE3
equ
$80+$14
LINE4
equ
$80+$54
PORTD_DDR
equ
$1009
address
PORTC_DDR
equ
$1007
address
PORTD
equ
$1008
PORTC
equ
$1003
PORTE
equ
$100A
ADCTL
equ
$1030
OPTIONS
equ
$1039
ADR1
equ
$1031
ADR2
equ
$1032
ADR3
equ
$1033
ADR4
equ
$1034
*
*
*
*
*
*ORG $d000
TExas
port D address
port C address
port E address
ADCTL register address
OPTTIONS register address
ADR1 register address
ADR2 register address
ADR3 register address
ADR4 register address
NAME:
PE0:
vol:
fcb
fcb
fcb
'
EE 3301 Lab #8',0
'PE0 A/D=',0
'V',0
ORG $2000
jmp
MAIN
rmb
sei
lds
jsr
#$00ff
INIT_LCD
Axiom
data
SIZE
MAIN:
cursor
ldaa #$80
staa OPTIONS
jsr
short_delay
power up
ldx
#NAME
line 1
jsr
cputs
ldaa #10
while
loop: jsr
long_delay
longer
deca
bne
loop
jsr
INIT_LCD
loop1:
ldaa #$30
staa ADCTL
ldab ADR1
result in ADR1
jsr csr_to_ln1
ldx
#PE0
jsr
cputs
jsr
dis
result
jmp loop1
dis:
clra
* clear acc A
pshb
* save value in acc B
jsr
dec_to_lcd
* put the input to the screen
ldaa #'='
* load '=' sign
jsr
putc
* put '=' on the screen
pulb
* get the value of previously save
in stack
jsr
compute
* go to compute conversion value
rts
*
* Compute the input voltage from A/D reading
*
INPUT:
acc A contains the character to be checked
compute:
***********************
* FILL IN THE CODE
*
***********************
* HINTS *
* 1. Multiply the value of ADR1 by 196.
* 2. Divide the result by 10000.
* 3. Store the remainder in D regiter into the stack.
* 4. Convert the quotient to decimal and display it using 'dec_to_lcd'.
* 5. Display the decimal point (#'.') next using 'putc.'
* 6. retreive the remainder of the division from the stack into the D
register.
* 7. Convert it to decimal and display it using 'dec_to_lcd'.
* 8. Display the unit of voltage which is 'V' in this case.
* move the cursor to the start of LCD display line 1
*
csr_to_ln1:
psha
* save acc A
ldaa #LINE1
* address of the start of line 1
staa LCDCMD
* write to LCD data port
jsr
short_delay
pula
* restore acc A
rts
*
* move the cursor to the start of LCD display line 2
*
csr_to_ln2:
psha
* save acc A
ldaa #LINE2
* address of the start of line 2
staa LCDCMD
* write to LCD data port
jsr
short_delay
pula
* restore acc A
rts
*
* move the cursor to the start of LCD display line 3
*
csr_to_ln3:
psha
* save acc A
ldaa #LINE3
* address of the start of line 3
staa LCDCMD
* write to LCD data port
jsr
short_delay
pula
* restore acc A
rts
*
* move the cursor to the start of LCD display line 4
*
csr_to_ln4:
psha
* save acc A
ldaa #LINE4
* address of the start of line 4
staa LCDCMD
* write to LCD data port
jsr
short_delay
pula
* restore acc A
rts
*
*
*
*
*
putc:
staa LCDDATA
jsr
short_delay
execute the command
rts
*
*
cputs sends
*
* INPUT:
* OUTPUT:
* SIDE EFFECT:
cputs:pshx
psha
tpa
psha
loop5:ldaa
register x
beq
reached
jsr
via put_lcd
inx
jmp
end2: pula
tap
pula
pulx
rts
0,x
*
*
*
*
*
save register x
save register a
move the CCR to acc A
save CCR
acc A <-- the character pointed by
end2
put_lcd
loop5
*
Writes the data in acc A to LCD. The default line sequence
1,3,2,4 is converted
*
to 1, 2,3, 4 so that the data is properly displayed.
*
INPUT:
acc A contains the character to be displayed
*
OUTPUT:
none
*
SIDE EFFECT:
content of register CCR is modified
*
put_lcd:
pshb
* save acc B
ldab LCDCMD
* read the current character
position
cmpb #$13
* is it at the end of line 1?
beq
line2
* yes. We need to move to line 2
cmpb #$53
* is it at the end of line 2?
beq
line3
* yes. We need to move to line 3
cmpb #$27
* is it at the end of line 3?
beq
line4
* yes. We need to move to line 4
jmp
write
line2:jsr
putc
* write to LCD
jsr
csr_to_ln2
jmp
end
line3:jsr
putc
* write to LCD
jsr
csr_to_ln3
* jump to line 3
jmp
end
line4:jsr
putc
* write to LCD
jsr
csr_to_ln4
* jump to line 4
jmp
end
write:jsr
putc
* write to LCD
end: pulb
* restore acc B
rts
*
*
Initialize the LCD screen
*
INIT_LCD:
psha
* save accumulator A in stack
ldaa #DMODE20X4
* LCD display mode 20 X 4
staa LCDCMD
* write to the LCD command register
jsr
long_delay
* a delay of at least 1.65 ms required after this
command
ldaa #CSRHOME
* command to move the cursor home
staa LCDCMD
* write to LCD command register
jsr
long_delay
* a delay of at least 1.65 ms required after this
command
ldaa #DCBON
* display, cursor and blink on
staa LCDCMD
* write to LCD command register
jsr
short_delay
* this command requires only 40 us
ldaa #CINSHOFF
* cursor increment, shift off
staa LCDCMD
* write to LCD command register
jsr
short_delay
* this command requires only 40 us
ldaa #SCSHR
* shift the cursor right
staa LCDCMD
* write to LCD command register
jsr
short_delay
* this command requires only 40 us
ldaa #CSRHME
* command to move the cursor home
staa LCDCMD
* write to LCD command register
jsr
short_delay
* this command requires only 40 us
pula
* restore accumulator A
rts
*
*
Initialize port D pins 2,3,4,5 as output pins.
*
*
*
*
*
Produces a long delay.
* INPUT:
none
* OUTPUT:
none
* SIDE EFFECT:
none
*
long_delay:
psha
tpa
psha
pshx
ldx
#10000
* save acc A
* move the CCR to acc A
* save CCR
* set loop counter
loop3:dex
bne
pulx
pula
tap
pula
rts
loop3
*
*
Produces a short delay.
* INPUT:
none
* OUTPUT:
none
* SIDE EFFECT:
none
*
short_delay:
psha
tpa
psha
pshx
ldx
#50
loop4:dex
bne
loop4
pulx
pula
tap
pula
rts
* decrement counter
* branch if not 0
* restore register CCR
* restore acc A
* save acc A
* move the CCR to acc A
* save CCR
* set loop counter
* decrement counter
* branch if not 0
* restore register CCR
* restore acc A
*
The number in acc D is sent to the LCD screen as a an unsigned
decimal number
*
INPUT:
acc D contains number in the range 0 - 65535 to
be displayed
*
OUTPUT:
none
*
SIDE EFFECT:
content of registers CCR and acc D are modified
*
dec_to_lcd:
pshx
pshy
ldy
#0
number of digits
loop7:iny
ldx
#10
idiv
pshb
acc B) is saved
beq
done7
done
xgdx
acc D
jmp
loop7
done7:pula
stack
adda #'0'
jsr put_lcd
* save reg X
* and reg Y
* reg y is the counter for the
*
*
*
*
dey
bne
0
puly
pulx
rts
done7