Afterwards, a series of wait sequences, pairing with writing to the

Laboratory Experiment #10:
LCD Display
Ari Mahpour
Pei-Chun Chen
ECE 425 Lab
Contents
Abstract ........................................................................ 3
Procedure ..................................................................... 3
Results and Interpretation ........................................... 4
Conclusion .................................................................... 5
Attached Code .............................................................. 6
Pictures ....................................................................... 10
Abstract
In this laboratory experiment, the students are required to effectively communicate
with the Liquid Crystal Display (LCD), via the Motorola 68HC12, and display their names on the
screen. This experiment requires the knowledge in understanding data sheets and the assembly
programming aspect.
Procedure
This laboratory experiment was rather straight forward. Most of the code was provided
by the laboratory manual specifications along with the flow chart. The student was merely
required to organize the data and put all of the provided code snippets together.
The laboratory experiment called for several operations to be performed prior to writing
out the data on to the LCD. Firstly, both PORTH and PORTT had to be set up properly. This mean
the bi-directionality of the ports had to be set prior to accessing the information that was being
passed through them.
Afterwards, a series of wait sequences, pairing with writing to the LCD, had to be
performed. The first delay was to be 15ms, then a write. The second delay had to be 4.1 ms
then a write. The third had to be 100 us, then a write. The fourth had to be a 4.1 ms delay and
then a write. The fifth and sixth had to be a 40 us delay then a write. Lastly, the seventh delay
had to be a 1.64ms delay and then a write. After these sequences, we then ran a subroutine
which ran through other subroutines which wrote to the LCD. The second line required waiting
only another 40 us of delay time but then writing $C0 to the LCD to toggle the cursor position
to get to the next line..
Results and Interpretation
Since the laboratory experiment’s instructions were so clear cut it was hard not to get
this correct in the first shot. Nevertheless, we managed to do incur errors right off the bat.
After continuous checking and rechecking of out code, we decided to switch to a different set
up. With the alternate setup configured, our code worked flawlessly without any change to the
pre-lab.
We were convinced that our Motorola 68HC12 unit was defective and requested that it
were to be repaired immediately. Upon inspecting our wiring, we soon found out it was faulty
on our part. The wiring had been configured incorrectly and as soon as it was reset to the
proper design everything worked fine. It was an important lesson to us to remember that we
must always double and triple check our wiring before determining whether our circuit board is
faulty.
Conclusion
This laboratory experiment did not require much effort with respect to coding but it was
it a very important part to a course such as ours. Most students would believe that a laboratory
experiment such as this one would not be a productive use of time but it is a very real world
application for electrical engineers and software engineers alike. It is incredibly common in the
industry for employees to be directed to implement another person’s code or design. In a fast
growing market there is no time for each person to develop their own designs or programs
from scratch. People must work together to create a modularized component or code.
This laboratory experiment was a very practical application to the work field such that it
requires the student to implement a modularized solution for its consumers. The student was
required to take the code from the original coder, understand it, and be able to put the pieces
together to make a cohesive structure that could perform the tasks at hand. In our personal
opinion, this laboratory experiment was the most integral experiment to real world applications
for today. The skills that we learned here can be taken with us into the industry for years to
come.
Attached Code
*************
*
*
* Variables *
*
*
*************
DDRH
DDRH_INI
LCD_CTRL
DDRT
DDRT_INI
LCD_DATA
E
RS
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
$0025
$FF
$0024
$00AF
$FF
$00AE
$04
$01
ORG
$800
; PORTH
; PORTT
; Enable Signal
; Command/Data I/O
* Rather than changing the TIME value when jumping through routines,
* three seperate values were created. Though this prevents modularity,
* it makes programming the application a lot easier and less prone to errors.
TIME15MS
FCB
!160
; 16ms wait, in VD1
TIME4MS
FCB
!6
; 6ms wait, in VD2
TIMEUS
FCB
!2
; 2ms wait, in VD3
MSG1
FCB
"LINE1",$0
MSG2
FCB
"LINE2",$0
****************
*
*
* Main Program *
*
*
****************
ORG
LDAA
STAA
LDAA
STAA
$900
#DDRH_INI
DDRH
#DDRT_INI
DDRT
BSET
BSET
LCD_CTRL, %00000000 ; Clear PORTH and PORTT
LCD_DATA, %00000000
JSR
MOVB
BSET
BCLR
VAR_DELAY1
#$38,LCD_DATA
LCD_CTRL,E
LCD_CTRL,E
; Set PORTH BiDi's
; set PORTT BiDi's
; Wait for more than 15 ms
; Send $38 to LCD
JSR
MOVB
BSET
BCLR
VAR_DELAY2
#$38,LCD_DATA
LCD_CTRL,E
LCD_CTRL,E
; Wait for more than 4.1 ms
; Send $38 to LCD
JSR
MOVB
BSET
BCLR
VAR_DELAY3
#$38,LCD_DATA
LCD_CTRL,E
LCD_CTRL,E
; Wait for more than 100 us
; Send $38 to LCD
JSR
LDAA
JSR
VAR_DELAY2
#$38
LCD_WRITE
; Wait for more than 4.1 ms
; Send $38 to LCD
LDAA
JSR
#$0C
LCD_WRITE
; Wait for more than 40 us
; Send $0C to LCD
MOVB
BSET
BCLR
#$01,LCD_DATA
LCD_CTRL,E
LCD_CTRL,E
; Wait for more than 40 us
; Send $01 to LCD
JSR
MOVB
BSET
BCLR
VAR_DELAY3
#$06,LCD_DATA
LCD_CTRL,E
LCD_CTRL,E
JSR
MESSAGE1
; Wait for more than 1.64 ms
; Send $06 to LCD
; Send message to LCD
* Send out second line
* We need to traverse to the next line which is $40
* We must also set the cursor position which is $80
* Therefore: $40 + $80 = $C0 (This is what we send out)
BCLR
LCD_CTRL,RS
MOVB
BSET
BCLR
#$C0,LCD_DATA
LCD_CTRL,E
LCD_CTRL,E
; Wait for more than 40 us
; Send $C0 to LCD
JSR
SWI
MESSAGE2
; Send message to LCD
***************
*
*
* Subroutines *
*
*
***************
* Message Subroutines
* For simplicity sake two seperate methods were made for each message
MESSAGE1:
JSR
LCD_ADDR
LDX
#MSG1
L3M1:
LDAA
0,X
BEQ
OUTMSGM1
JSR
LCD_WRITE
INX
BRA
L3M1
OUTMSGM1
RTS
MESSAGE2:
L3M2:
OUTMSGM2
JSR
LDX
LDAA
BEQ
JSR
INX
BRA
RTS
*LCD Address Subroutine
LCD_ADDR:
BCLR
STAA
BSET
NOP
NOP
BCLR
LDAA
L4:
DBNE
BSET
RTS
* LCD Write Subroutine
LCD_WRITE:
STAA
BSET
NOP
BCLR
LDAA
L2:
DBNE
RTS
LCD_ADDR
#MSG2
0,X
OUTMSGM2
LCD_WRITE
L3M2
LCD_CTRL,RS
LCD_DATA
LCD_CTRL,E
LCD_CTRL,E
#!110
A,L4
LCD_CTRL,RS
;40us delay for LCD
;data operation
LCD_DATA
LCD_CTRL,E
LCD_CTRL,E
#!110
A,L2
;delay 40us
* VAR Delay subroutines
* See compiler directives for reasoning behind 3 different VAR_DELAY's
VAR_DELAY1:
LDAB
#!200
;1 cycle
L1D1:
NOP
;1 cycle
DBNE
B,L1D1
;3 cycle
DEC
TIME15MS
;4 cycle
BNE
VAR_DELAY1
;3 cycle
RTS
;5 cycle
VAR_DELAY2:
L1D2:
VAR_DELAY3:
L1D3:
LDAB
NOP
DBNE
DEC
BNE
RTS
#!200
LDAB
NOP
DBNE
DEC
BNE
RTS
#!200
B,L1D2
TIME4MS
VAR_DELAY2
B,L1D3
TIMEUS
VAR_DELAY3
;1 cycle
;1 cycle
;3 cycle
;4 cycle
;3 cycle
;5 cycle
;1 cycle
;1 cycle
;3 cycle
;4 cycle
;3 cycle
;5 cycle
Pictures