PDA

View Full Version : Assembler: please kick me in the right direction



Demon
- 23rd December 2005, 19:43
Hi,

I have assembler code that I'd like to integrate into my PIC Basic Pro application. The only problem is that I haven't touched assembler since 1980, so I'm very rusty (make that totally ignorant by now).

I'd appreciate any help in finding a tutorial to better understand this stuff. One problem I have right now is how to identify the pins. I also foresee compatibility problems, no idea what version of assembler this is in.

This is the code for an Optrex 51553 graphic LCD. I also have on hand the 2 include files at the end; the image and font definition.

Robert
:)

Demon
- 23rd December 2005, 19:46
Here's the schematic that goes with the code:

Darrel Taylor
- 23rd December 2005, 21:16
Hi Robert,

That's going to be hard. The program is written for an 8051 type processor.

Many of the 8051 directives are similar to the PIC ones, but you'll have to re-write the whole program. :(

.

Demon
- 24th December 2005, 08:01
By the tone of your reply, I take it that it's more than just correcting the command syntax and that the actual coding is affected as well...

Darn, this was the best example I had to manage an Optrex 51553 gLCD. I've scoured Google and found nothing for the SED1565 controller. I've checked out the links posted in here fo gLCDs, but they are all for other types of controllers.

That really sucks 'cause this LCD is really cool; white font over a blue backgound, with backlighting and touch screen. That, and the fact I have 5 on hand and just finally managed to assemble a PCB to receive the 0.5mm pitch flexible film connector.

Robert
:(

Demon
- 24th December 2005, 08:08
Ok, I'll give it a try.

Darrel, you wouldn't happen to have a link to 8051 syntax? That would cut down on some research time and I'd be certain of looking at the proper code. I'd hate to convert all this wrong.

Should I convert to MPASM or PM? PM is supposed to be faster, but I don't know if it supports all the commands.

Robert
:)

Demon
- 24th December 2005, 08:12
I've found a nice reference for 8051 here:
http://www.ece.umr.edu/computing/unix/software/tasking/asm/

Now I just have to figure if I need PM or MPASM...

Robert
:)

Demon
- 24th December 2005, 08:22
This is reassuring:
"PM includes an 8051-style instruction set that is more intuitive than the Microchip mnemonics. For complete information on the PICmicro Macro Assembler, see the PM.TXT file on disk."

Crossing my fingers in hopes that I have enough information to convert this.

Robert
:)

Luciano
- 24th December 2005, 09:13
Hi!
Using a Graphics-Based LCD Module
http://www.circuitcellar.com//library/details/0400/c0400cdpdf.pdf

Interfacing to a Hantronix 128 × 64 Chip-On-Glass LCD
(Basic Stamp code - SED1565 controller)
http://www.hantronix.com/down/a12864cog.pdf

Also using the SED1565 controller:
http://sandiding.tripod.com/n7110.html
http://sandiding.tripod.com/nokialcd7110.html

Merry Christmas!

Luciano

Demon
- 24th December 2005, 10:14
Thank you very much folks. I'm trying to convert the assembler as plan A, I might as well get my hands dirty. I knew I had to get back into asm, I just needed a good excuse.

8051 asm has CALL (generic), ACALL (absolute) and LCALL (long).

PM asm only has CALL and LCALL.

How would you convert the absolute calls from 8051? Can you just plunk it into a generic call and consider the job done?

Robert
:)

Luciano
- 24th December 2005, 10:27
Hi,

If your objective is to drive the
SED1565 controller, see my previous
post for the link to a Basic Stamp
code example.

If your objective is to learn assembly,
start with LEDs and buttons and then
add an Hitachi 44780 LCD Controller.

Best regards,


Luciano

Demon
- 24th December 2005, 10:51
Luciano, I did. The stamp link uses the serial interface; I'd much prefer to use the parallel interface. Unless I am mistaken, that should have faster response time. The Circuit cellar example uses C, nice stuff, but nothing I can use without learning a lot of stuff. Plus, the code I have is for a 51553 demo board, exactly like the one I have on hand.

Switching to a character LCD is not an option. That would mean basing my design on an obsolete part, not interested. Figuring out how to add a touch screen would complicate matters even more. Right now I have a solid source of gLCDs with mounted TS at an excellent price.

I'm not exactly starting assembler from scratch either. I was top of my class, only problem is that I graduated in '83. I have references for both 8051 and PM assembler, most of the commands are easy to convert. I'll just have a few questions on the exception cases.

That being said, would you happen to have an idea on how to convert the absolute call?

Luciano
- 24th December 2005, 11:36
Hi,

See this demo board:
http://www.tvielectronics.com/Products/TC51553-64_Controller.html

The TC51553 Demo board has an option to store the data in a serial eeprom.

When this option is used, the on-board ATmega16 (9.216 MHz) reads the data
from a serial eeprom and sends it to the Optrex F-51553 LCD using a
8-bit parallel interface.

The Data Transfer of the Optrex F-51553 LCD is selectable serial
or 8-bit parallel. If your data is stored in a serial eeprom the
use of the parallel interface is not going to make a big speed difference.

* * *

Write a library for a Graphic LCD is a complex and challenging task.
Doing that in assembly is going to be difficult and time-consuming.

The assembly code you have posted is just a simple demo.

Some of the functions of a Graphic LCD library are:

- Clear display
- Set/Reset single pixels
- Draw lines
- Draw boxes
- Draw circles
- Write text with different styles and sizes
- Show a picture
- ....

Example:

CIRCLE x,y,r,c

x = Starting horizontal location
y = Starting vertical location
r = Radius of the circle
c = Color of the circle

* * *

I wish you a Merry Christmas and a great success with your assembly project.

Best regards,

Luciano

Darrel Taylor
- 24th December 2005, 12:57
would you happen to have an idea on how to convert the absolute call?
The easiest way is probably to use the L?CALL macro. That way, no matter where the destination is, the correct page bits will be set.


L?CALL destination

.

Demon
- 24th December 2005, 17:10
Luciano, I have that document. That is the one I am using to manage the 4-wire touch screen circuit.

I am using the schematic for the Optrex demo board from Apollo Display as a base for the LCD circuit. The charge pump circuitry is probably identical, I didn't bother comparing. Since I got the gLCDs from Apollo, I'm going to use their schematic, I also find it a bit easier to read.

I have no doubt that writing a library for a gLCD is complex, but I'm not doing that, I'm just modifying a working example. If I was able to progam software for banks, credit cards and utility companies for 20 years, it's not unrealistic to believe that I can convert an assembler program. As it is, I understand 90% of what is happening within this code.

As for the complexity of using all the functions of a graphic LCD, I never said I was going to use them.


Thanks for answering my question Darrel, much appreciated!

Demon
- 24th December 2005, 17:44
I've Googled, but I can't find a place with nice PM assembler code. I'm particularly interested in how the I/O pins are addressed.

How to move a byte to a port:
mov P1,a ;set output data

How to reset a particular pin:
clr P3.2 ;CS = 0

Robert
:)

Demon
- 24th December 2005, 17:58
I finally found a nice example here:
http://picbasic.com/resources/articles/brainart.htm


setb rp0 ;change to register page 1
mov trisb,#00001111b ;make the bottom 4 bits on PortB inputs and the top 4 outputs
clrb rp0 ;change back to register page 0
;
clrb portb.4 ;start with output low and LED off
;
loop jnb portb.0,loop ;jump to loop if switch on PortB.0 is low
jnb portb.1,loop ;jump to loop if switch on PortB.1 is low
;
; if we got here then both switches are high
;
setb portb.4 ;set output high to turn on LED


Robert
:)

Demon
- 24th December 2005, 18:41
Ok, I've researched each instruction and these 5 have no direct translations:

PUSH, push direct byte onto stack
POP, pop direct byte from stack
MUL, multiply
ADDC, add into accumulator
MOVC, move code byte to accumulator

I wouldn't be surprised if the equivalent PIC Macro instructions are staring me in the face, but I don't want to start guessing. Here is some code to show the context the commands are used in:

; write an ASCII character to the display
; The font file starts at ascii 32 (blank). The default font is 8x8 pixels
; INPUTS - character in register A
write_char:
push dph
push dpl
clr c
subb a,#32 ;ascii font with blank
mov b,#8 ;multiply by 8 (8 bytes/char)
mul ab
add a,#low(font) ;add to font table address
mov dpl,a
mov a,b
addc a,#high(font)
mov dph,a
mov r0,#8 ;8 bytes/char
wbyte: clr a
movc a,@a+dptr
acall write_data
inc dptr
djnz r0,wbyte
pop dpl
pop dph
ret

8051 assembler reference here:
http://www.ece.umr.edu/computing/uni...e/tasking/asm/

PIC Macro assembler reference:

Robert
:)

Darrel Taylor
- 24th December 2005, 20:34
Robert,

The PUSH and POP were apparently used to save 2 variables that were used in the write_char: routine. You can just use separate variables to temporarily store the two bytes, instead of trying to use the stack.

MUL can be replaced with the MUL?BBB or MUL?BBW macro.

For the addc and movc, you can either manipulate the EEADDR, EECON and EEDATA registers manually, or you could break out of ASM and use the READCODE statement to get the byte first, then do the ADDWF or MOVWF.

HTH,
Darrel

Demon
- 24th December 2005, 23:40
Like this?


dph data 42h <--- add this line with existing DATA statement
dpl data 43h <--- add this line with existing DATA statement


write_char:
push dph <--- delete this line
push dpl <--- delete this line
...
mov dpl,a
...
mov dph,a
...
pop dpl <--- delete this line
pop dph <--- delete this line
ret

Robert
:)

Demon
- 24th December 2005, 23:50
"MUL can be replaced with the MUL?BBB or MUL?BBW macro."

Darrel, can you point me to some reference on macros? I Googled but did not find anything relevant (that I could see).

The MeLabs PM manual didn't have any mention for 'mul' or 'bbb'.

Robert
:)

Darrel Taylor
- 25th December 2005, 00:07
I was thinking something more like this...

dph_save VAR BYTE
dpl_save VAR BYTE

ASM
write_char:
MOVE?BB dph, _dph_save
MOVE?BB dpl, _dpl_save

push dph <--- delete this line
push dpl <--- delete this line
...

...
pop dpl <--- delete this line
pop dph <--- delete this line

MOVE?BB _dph_save, dph
MOVE?BB _dpl_save, dpl
return

...

ENDASM


And, here's a little more info on the MOVE macro's
http://www.picbasic.co.uk/forum/showthread.php?p=2009

.

Demon
- 25th December 2005, 20:49
What type of variables are the variables a, b and c considered? My first quess would have been a work register, but I'd like to be sure.

Since there are only 2 variables in the equation, the new command should be MUL?xx, right?

(available letters seen in your reply to PIC Beginner in other thread)

Robert
:)

Darrel Taylor
- 25th December 2005, 22:50
This page describes the 8051 registers, but the whole site is pretty good too.
http://www.8052.com/tutbregs.phtml#R%20Registers

The MUL?xxx macro usually has 3 paramaters, the third one is the result of multiplying the first two.

For instance, if you had the following variables ...
A VAR BYTE
B VAR BYTE
Y VAR BYTE
Z VAR WORD
THEN ...


this ASM macro is same as this PBP statement
--------------------- -------------------------
MUL?BBB _A, _B, _Y Y = A * B
MUL?BBW _A, _B, _Z Z = A * B
MUL?BWW _A, _Z, _Z Z = A * Z


And, you can see that often it's easier to just jump out of ASM and handle it in Basic.

------------------
If you do use the MUL? macros, there's something else you have to do to get them to work. Since, they are from the PBPPIC14.MAC file, they don't automaticaly get included with the project. So you have to Trick PBP into thinking it needs those macros.

This bit of code doesn't use any Program space since the ifdef keeps it from being compiled. But PBP sees the statements and includes any macros that are associated with them.

@ ifdef DoNotCompile ' Macro to include
R0.LowByte = R0.LowByte * R0.LowByte ' MUL?BBB
R0 = R0.LowByte * R0.LowByte ' MUL?BBW
R0 = R0.LowByte * R0 ' MUL?BWW
@ endif


But then, If you do it in Basic, you don't have to worry about it.

Merry X-Mas,
Darrel

Demon
- 26th December 2005, 04:07
I'm going with basic for the multiplication. Only problem is that table 4.1 in this document is confusing:
http://xess.com/manuals/asm51.pdf

The entry for MUL is:

B x A --> B,A

Ok, so what does that mean? The result is placed in both A and B? In addition, the result is accumulated in the first variable. I expected something similar, either in the first, or in the second, but not both. Obviously I'm misunderstanding something here.

I tried finding Note 7, but I can't see it anywhere.

Robert
:)

Luciano
- 26th December 2005, 10:13
Intel 8051

(The result is sixteen-bit)

Multiplies the unsigned value of the Accumulator by the unsigned value of
the "B" register. The least significant byte of the result is placed in the
Accumulator and the most-significant-byte is placed in the "B" register.


---------------------------------------------


MCS 51 Microcontroller Family User's manual. (15 MB file).
(Original data-book scanned).
See PDF page 90
ftp://download.intel.com/design/MCS51/MANUALS/27238302.pdf

* * *

8051 Instruction Set (300K file).
See PDF page 50
http://batronix.com/pdf/befehle.pdf

* * *

80C51 family programmer’s guide and instruction set. (270K file)
See PDF page 43
http://www.logiccell.com/~jean/8051/3082.pdf

* * *

Demon
- 1st January 2006, 20:27
Thanks for all the replies.

I still have to control individual characters, contrast and the touch screen, but I got it to work. I printed xF0 across the entire LCD, to make it easy to see output. I have the LCD on inverse in this example, the top of the line should be high, not the bottom.

The Hantronix code is incomplete for an Optrex LCD, you have to scour through the Optrex code and add missing control codes. Once I get the characters to come out properly, I'll see about putting out a bitmap.

One idea I'm toying with is rotating the LCD and printing in portrait instead of landscape mode. There are applications where I want a vertical LCD instead of horizontal (like a list of single-word commands).

I'll post the code once I've sufficiently changed it and made it my own. I don't want to be bothered with Hantronix and copyright laws.

Robert
:)

Demon
- 2nd January 2006, 19:31
There you go:

http://www.picbasic.co.uk/forum/showthread.php?p=16269

Robert
:)