lcd control in assembly

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

lcd control in assembly

Jump to solution
3,274 Views
okn
Contributor I
Hello!

I'm writing a code on assembly which will display on LCD, model HD44780 something, but I've faced the problem which I can't solve...
I am writing to program MC68HC908QB8, version of CodeWarrior IDE: 5.7.0.
When I debug it CW displays the error:

L1119: Vector allocated at absolute address 0xFFFE overlaps with sections placed in segment .absSeg1"


Ok, the code:

main.asm file:
INCLUDE 'derivative.inc'
INCLUDE 'lcd1.inc'

; export symbols
XDEF _Startup, main

XREF __SEG_END_SSTACK ; symbol defined by the linker for the end of the stack

; variable/data section
MY_ZEROPAGE: SECTION SHORT ; Insert here your data definition

; code section
MyCode: SECTION
main:
_Startup:
LDHX #__SEG_END_SSTACK ; initialize the stack pointer
TXS
CLI ; enable interrupts

mainLoop:

LCD: EQU PTB

org $F800

START MOV #$3B, CONFIG1
JSR LCD4SET
LDHX #TEXT1
JSR LINIA14
BRA $

TEXT1: dc.b "SOMETHING"

org $FFFE
DC.W START

NOP

feed_watchdog
BRA mainLoop



lcd1.inc file:
E: equ 6
RS: equ 4
RW: equ 5

ImpulsE: macro
BSET E,LCD
BCLR E,LCD
endm

LCD4SET: BCLR E,LCD
MOV #$7F, LCD+4
LDA #150
JSR L_CZEKA
MOV #$03, LCD
ImpulsE
LDA #41
JSR L_CZEKA
ImpulsE
LDA #1
JSR L_CZEKA
ImpulsE
MOV #$02,LCD
ImpulsE
LDA #$28
JSR LCD4WRR
LDA #$0C
JSR LCD4WRR
LDA #$06
JSR LCD4WRR
RTS

LINIA14 LDA #$80
BRA LINIA_4
LINIA_4 JSR LCD4WRR

LCD4WRD JSR LCD4BF
PSHA
NSA
AND #$0F
STA LCD
BSET RS,LCD
ImpulsE
PULA
AND #$0F
STA LCD
BSET RS,LCD
ImpulsE
RTS

LCD4WRR JSR LCD4BF
PSHA
NSA
AND #$0F
STA LCD
ImpulsE
PULA
AND #$0F
STA LCD
ImpulsE
RTS

LCD4BF MOV #$70,LCD+4
BSET RW,LCD
BCLR RS,LCD
BSET E,LCD
BRSET 3,LCD,* ////////!!!! originally it should be BRSET 3,LCD,$ but the debugger
///////!!!! wrote that there's the error at the end of expression so I've changed it...
BCLR E,LCD
ImpulsE
MOV #$7F, LCD+4
RTS

L_CZEKA AIS #-2
STA 1,SP


Anyone know whats the problem and can explain me how it should be written? Thx in advance!
Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
1,070 Views
CompilerGuru
NXP Employee
NXP Employee
Mixing absolute sections (ORG) with relocatable ones not strictly illegal, tough a bit unusual, at least with code.
Anyway, the problem the linker is reporting is that the reset vector location at 0xFFFE is twice defined, once in the shown assembly module:
org $FFFE
DC.W START

And (very probably) a second time in the not shown linker parameter file (*.prm), probably as VECTOR directive (either VECTOR 0, or VECTOR ADDRESS 0xFFFE).
So to get it building, remove one of the two definitions.

Daniel

View solution in original post

0 Kudos
Reply
4 Replies
1,070 Views
bigmac
Specialist III
Hello,
 
You will need to decide whether you are going to write relocatable code, or absolute assembly code.  Currently, it is an incompatible mix of the two.  Your ORG statements (absolute assembly) would appear problematic.  An additional problem is the way you are interleaving code and data.
 
If you are going to use relocatable code -
  1. Remove the ORG statements
  2. Remove the start vector data (DC.W  START) - the PRM file should identify the start location.
  3. Re-position the TEXT1 data to outside of your MainLoop.
  4. The BRA * statement (corrected from BRA $) will be a problem because the code will not progress beyond this point.
  5. With CW assembler, use BRSET 3,LCD,* instead of BRSET 3,LCD,$
These are the obvious errors that will affect program flow, and the assembly and linking process.  I have not examined your LCD routines in detail.  The final two lines in your post would appear to be spurious, since the sub-routine is obviously incomplete.
 
Regards,
Mac
 
0 Kudos
Reply
1,071 Views
CompilerGuru
NXP Employee
NXP Employee
Mixing absolute sections (ORG) with relocatable ones not strictly illegal, tough a bit unusual, at least with code.
Anyway, the problem the linker is reporting is that the reset vector location at 0xFFFE is twice defined, once in the shown assembly module:
org $FFFE
DC.W START

And (very probably) a second time in the not shown linker parameter file (*.prm), probably as VECTOR directive (either VECTOR 0, or VECTOR ADDRESS 0xFFFE).
So to get it building, remove one of the two definitions.

Daniel
0 Kudos
Reply
1,070 Views
okn
Contributor I
Thanks a lot for your help.

So I've modified the code a little:

main.asm file:

INCLUDE 'derivative.inc'
INCLUDE 'lcd1.inc'


XDEF _Startup, main
XREF __SEG_END_SSTACK

; variable/data section
MY_ZEROPAGE: SECTION SHORT

MyCode: SECTION
main:
_Startup:
LDHX #__SEG_END_SSTACK ; initialize the stack pointer
TXS
CLI ; enable interrupts

mainLoop:

LCD: EQU PTB

START MOV #$3B, CONFIG1
JSR LCD4SET
LDHX #TEXT1
JSR LINIA14
BRA $

TEXT1: dc.b "something"

NOP

feed_watchdog
BRA mainLoop


lcd1.inc file:

E: equ 6
RS: equ 7
;RW: equ 5

ImpulsE: macro
BSET E,LCD
BCLR E,LCD
endm

LCD4SET: BCLR E,LCD
MOV #$7F, LCD+4
LDA #150
JSR L_CZEKA
MOV #$03, LCD
ImpulsE
LDA #41
JSR L_CZEKA
ImpulsE
LDA #1
JSR L_CZEKA
ImpulsE
MOV #$02,LCD
ImpulsE
LDA #$28
JSR LCD4WRR
LDA #$0C
JSR LCD4WRR
LDA #$06
JSR LCD4WRR
RTS

LINIA14 LDA #$80
BRA LINIA_4
LINIA24 LDA #$c0
LINIA_4 JSR LCD4WRR
L_ZNAK LDA ,X
BEQ ENDL4
JSR LCD4WRD
AIX #1
BRA L_ZNAK
ENDL4 RTS

LCD4WRD JSR LCD4BF
PSHA
NSA
AND #$0F
STA LCD
BSET RS,LCD
ImpulsE
PULA
AND #$0F
STA LCD
BSET RS,LCD
ImpulsE
RTS

LCD4WRR JSR LCD4BF
PSHA
NSA
AND #$0F
STA LCD
ImpulsE
PULA
AND #$0F
STA LCD
ImpulsE
RTS



LCD4BF MOV #$70,LCD+4
;BSET RW,LCD
BCLR RS,LCD
BSET E,LCD
BRSET 3,LCD,*
BCLR E,LCD
ImpulsE
MOV #$7F, LCD+4
RTS


L_CZEKA AIS #-2
STA 1,SP
L_CZAS LDA #133
STA 2,SP
DBNZ 2,SP,*
DBNZ 1,SP,L_CZAS
AIS #2
RTS


And... yes it did compile and I've loaded the program to my uC but I can't see the result: it doesn't work. Do you think that it might be the software problem or hardware?
0 Kudos
Reply
1,070 Views
bigmac
Specialist III
Hello,
 
If you wish others to review the code you are using, you will need to make the operation of the code much clearer to the reader.
 
The most glaring omission in your post is the complete lack of comments to explain your intent.  As a minimum, I would suggest the basic function of each sub-routine to be identified (as a single phrase), and also include the data it expects to receive, and the data it makes available to the rest of the program (if any).  This is particularly important for assembly programs that are not "self documenting".  I would also suggest any numeric constants to be identified as to what they represent.  For example, if a value is an LCD command byte, say what particular command it represents.  The addition of comments will also help you to understand what you did when reading the code at some time in the future.
 
The other major issue is the confusion caused by lack of indentation, again more important for assembly than C code.  If the indentation disappears when you "paste" the text into the post, you will need to add it by hand.  Use either the "Insert Source code" button, or select Courier New as the font, to allow clear indentation.  Without indentation, as well as making the code difficult to read, you do not give the oportunity for your assembly code to be pasted to a text file and tested, without a lot of additional effort by the reader.
 
Finally, a minor point - the code is somewhat easier to read if not "bolded".
 
I realise this doesn't solve your current problem, but if you make your code easy to follow, it is less likely to be put in the "too hard basket".
 
Regard,
Mac
 
0 Kudos
Reply