Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

saving bytes

Status
Not open for further replies.

mstechca

New Member
Here is my 8051 code I am using now to print ABC to the LCD.

MOV P1,63
SETB P3.4
CLR P3.4
MOV P1,0
SETB P3.4
CLR P3.4
SETB P3.5
MOV P1,65
SETB P3.4
CLR P3.4
MOV P1,66
SETB P3.4
CLR P3.4
MOV P1,67
SETB P3.4
CLR P3.4

My clock is at about 2Khz, and this code works well. But is there any way I can somehow condense the code?

Each character or function sent seems to want 7 bytes just to display it.
and 2K flash / 7 bytes a piece = 292 characters or LCD functions maximum. Then divide by 16 since my LCD only holds 16 characters = approximately 18 screens. This excludes code used for processing data.

P3.4 is attached to the Enable pin of the LCD and P3.5 is attached to the Instruction/Data pin at P3.4
 
SETB P3.4
CLR P3.4
These 2 instructions are being continuously repeated
write them at seperate place and use a call command to call them wheneevr required
If your data is predetermined store it in data memory and then use a loop to where you will move the data from the desired memory (pointed by a counter) to the P1 register
 
instruite said:
SETB P3.4
CLR P3.4
These 2 instructions are being continuously repeated
write them at seperate place and use a call command to call them wheneevr required
If your data is predetermined store it in data memory and then use a loop to where you will move the data from the desired memory (pointed by a counter) to the P1 register
I am not 8051 expert, but I don't think that placing these to instructions in sub-program is a good idea. It will require return stack place, and also Call/Return will take more time to proces. I would use Macro instead (if your IDE supports it).
 
Using macro's doesn't save any space, it simply inserts the macro code everytime it's used.

It's normal to write a subroutine to do such tasks as displaying a character on the LCD - which is how my PIC routines are done, something like this, to display a capital A on the LCD:

Code:
movlw 'A'
call LCD_Print

Where LCD_Print would be the name of the subroutine that displays the connets of W on the LCD. You should be able to do something similar on any processor?.
 
What I ment was, that it doesn't pay-off when only TWO instructions are placed in a sub-routine (And sometimes CALL instruction is as big as two normal instructions!).

Macros simplifie life, they don't save space tought...
 
thanks.

I'm actually not using a specific 8051 IDE. I'm using QuickBasic to directly drive the machine codes into the uC.
 
mstechca said:
thanks.

I'm actually not using a specific 8051 IDE. I'm using QuickBasic to directly drive the machine codes into the uC.

Are you hand assembling it?, or do you have an assembler? - the IDE refered to the assembler, not the programmer.
 
I was hand-assembling it, but now I made myself a quick compiler with QuickBasic which I now use. Maybe I should provide it.
 
mstechca said:
I was hand-assembling it, but now I made myself a quick compiler with QuickBasic which I now use. Maybe I should provide it.

I'm presuming assemblers (which is what you meant, not a compiler!) are freely available?, why not just download one?.

It obviously explains why your code looked 'strange', because you were hand assembling it - I've not done that since the 70's :lol:
 
Status
Not open for further replies.

Latest threads

Back
Top