Home - Search - Members
Full Version: Scoreboard display on LCD (edsim51)
Pages: 1, 2
Reiniku
Nov 29 2010, 12:18 PM
Hello! I'm currently learning the basics of microcontrollers and was given the task of creating a scoreboard to display on the LCD (so 4 digits) and have switches to increment and decrement each displayed digit in assembly. So something like:

0000

Switch 1 and 2, decrements and increments the first digit, 3 and 4 for the second... so on and so forth.

Hitting switch 2 from this point would show: 1000

Switch 4 woudl show: 1100

Etc.

I've figure out how to output to the LCD (thanks to the edsim51 examples) so that my program shows "0000" when run, but I'm not sure how to implement the rest of my code.

I'm not asking how to be spoon fed how to do it but more like I could use some guidance. Would it be possible to use the "switch banks" on the screen to do this? There ARE 8 of them. And do I have to use interrupts to increment and decrement the counters?

If it's of any help here's the code I have written to display "0000" on the LCD:

; put data in RAM
	MOV 30H, #'0'
	MOV 31H, #'0'
	MOV 32H, #'0'
	MOV 33H, #'0'
	MOV 34H, #0; end of data marker


; initialise the display
; see instruction set for details


	CLR P1.3		; clear RS - indicates that instructions are being sent to the module

; function set	
	CLR P1.7		; |
	CLR P1.6		; |
	SETB P1.5		; |
	CLR P1.4		; | high nibble set

	SETB P1.2		; |
	CLR P1.2		; | negative edge on E

	CALL delay		; wait for BF to clear	
					; function set sent for first time - tells module to go into 4-bit mode
; Why is function set high nibble sent twice? See 4-bit operation on pages 39 and 42 of HD44780.pdf.

	SETB P1.2		; |
	CLR P1.2		; | negative edge on E
					; same function set high nibble sent a second time

	SETB P1.7		; low nibble set (only P1.7 needed to be changed)

	SETB P1.2		; |
	CLR P1.2		; | negative edge on E
				; function set low nibble sent
	CALL delay		; wait for BF to clear


; entry mode set
; set to increment with no shift
	CLR P1.7		; |
	CLR P1.6		; |
	CLR P1.5		; |
	CLR P1.4		; | high nibble set

	SETB P1.2		; |
	CLR P1.2		; | negative edge on E

	SETB P1.6		; |
	SETB P1.5		; |low nibble set

	SETB P1.2		; |
	CLR P1.2		; | negative edge on E

	CALL delay		; wait for BF to clear


; display on/off control
; the display is turned on, the cursor is turned on and blinking is turned on
	CLR P1.7		; |
	CLR P1.6		; |
	CLR P1.5		; |
	CLR P1.4		; | high nibble set

	SETB P1.2		; |
	CLR P1.2		; | negative edge on E

	SETB P1.7		; |
	SETB P1.6		; |
	SETB P1.5		; |
	SETB P1.4		; | low nibble set

	SETB P1.2		; |
	CLR P1.2		; | negative edge on E

	CALL delay		; wait for BF to clear


; send data
	SETB P1.3		; clear RS - indicates that data is being sent to module
	MOV R1, #30H	; data to be sent to LCD is stored in 8051 RAM, starting at location 30H
loop:
	MOV A, @R1		; move data pointed to by R1 to A
	JZ finish		; if A is 0, then end of data has been reached - jump out of loop
	CALL sendCharacter	; send data in A to LCD module
	INC R1			; point to next piece of data
	JMP loop		; repeat

finish:
	JMP $


sendCharacter:
	MOV C, ACC.7		; |
	MOV P1.7, C			; |
	MOV C, ACC.6		; |
	MOV P1.6, C			; |
	MOV C, ACC.5		; |
	MOV P1.5, C			; |
	MOV C, ACC.4		; |
	MOV P1.4, C			; | high nibble set

	SETB P1.2			; |
	CLR P1.2			; | negative edge on E

	MOV C, ACC.3		; |
	MOV P1.7, C			; |
	MOV C, ACC.2		; |
	MOV P1.6, C			; |
	MOV C, ACC.1		; |
	MOV P1.5, C			; |
	MOV C, ACC.0		; |
	MOV P1.4, C			; | low nibble set

	SETB P1.2			; |
	CLR P1.2			; | negative edge on E

	CALL delay			; wait for BF to clear

delay:
	MOV R0, #50
	DJNZ R0, $
	RET


ExperimenterUK
Nov 29 2010, 2:21 PM
You should start by putting you display code into subroutines.
One to initialise and a second to display the string at 30h

There is no need to use interrupts yet.
Poll (read repeatedly) the 8 buttons in turn,
it will be easiest to wait until a key is pressed and released.

The method is quite simple.
If an up key is pressed, increment the value unless it is already at '9'.
If a down key is pressed, decrement the value unless it is already at '0'.
Every time a key press is found, refresh the display.


Would it be possible to use the "switch banks" on the screen to do this?
There ARE 8 of them.

Reiniku


Sorry, don't know what they are.


majoka
Nov 29 2010, 2:36 PM
hi Reiniku
can u give more info on ur project
what ur idea
how much u done whats next u want where ur getting problem
need some detail here

Reiniku
Nov 29 2010, 2:54 PM
The original idea was proposed as:

"The idea is to display the count on the LCD display. Using switches, a user can increment and decrement a counter. After every press of a switch, the subsequent count can be seen on the LCD display. There are 4 counters that have to be seen on the LCD. Use two switches per one counter: first switch as incrementer, second as decrementer."

So far all I have is the digits displayed on the LCD. I'm very very new at assembly so I'm not really sure how to continue.

I have the code written listed above. I'm fortunate since this is all done on edsim51 to simulate 8051.
majoka
Nov 29 2010, 3:06 PM
hi Reiniku
ru bound to do it asm if not then why not in c
that is easy as compare to asm
u can use interrupts to counts
increment and decrements
let say to take a start u need an external interrupts
download this book and read its interrupt chapter
ita a mazidi book
1) http://ifile.it/l3t8e4k/The_8051_Microcontroller_and_Embedded_Systems_Using_Assembly_and_C-2nd-ed_BY_Mazidi.rar

or

2) http://ifile.it/l3t8e4k
Reiniku
Nov 29 2010, 3:21 PM
I'm bound to asm by the project's guidelines to familiarize myself with hardware interaction. I will go and read the chapter as you have suggested.
majoka
Nov 29 2010, 11:33 PM
hi Reiniku
here is a sample code i comment it properly for ur easy understanding
lcd is in 4- bit mode
external interrupts r used also as a sample
when an interrupt occur a register increment
this increment is displayed on lcd too
Proteus file is included
Reiniku
Nov 30 2010, 12:01 AM
Hello! Thank you for the sample code. I am reading through it right now to get an understanding and I am attempting to run it in the edsim51 simulation but it does not recognize "db" as part of its instruction set. Is this abnormal? Sorry for the trouble.

It says:

Syntax Error - DB statement - DB " HELLO WORLD ",0H

when attempting to assemble.
majoka
Nov 30 2010, 12:11 AM
hi Reiniku
oho ur using edsim51
but i make it in keil
why ur not using keil
Reiniku
Nov 30 2010, 12:13 AM
It's part of the supplied tools given by my intrsuctor with its manual. The whole class is to use edsim51 so we are streamlined and can compare code on our different projects as we progress.

The problem is that we were instructed to use this but not HOW to use it, so I've been lost for quite a bit.

It does recognize db when used in this manner

LEDcodes:	; | this label points to the start address of the 7-segment code table which is 
		; | stored in program memory using the DB command below
	DB 11000000B, 11111001B, 10100100B, 10110000B, 10011001B, 10010010B, 10000010B, 11111000B, 10000000B, 10010000B
majoka
Nov 30 2010, 12:28 AM
db is called define byte
it is used to store the define data in ROM
as in example i store "helllow world"
see the manual of edsim51 for assistant
i hope syntax will be different
Reiniku
Nov 30 2010, 12:39 AM
It detects the code

LEDcodes:       ; | this label points to the start address of the 7-segment code table which is 
                ; | stored in program memory using the DB command below
        DB 11000000B, 11111001B, 10100100B, 10110000B, 10011001B, 10010010B, 10000010B, 11111000B, 10000000B, 10010000B


as valid but not the code in the .asm file.

Notes and instruction sets are available here:

http://www.edsim51.com/8051Notes/index.html

But do not specifically define db.
majoka
Nov 30 2010, 1:58 AM
hi Reiniku
if the above sytax accept ur asm file then it should accept it also
see the help of software


DB 0x01B, 0x10B, 0x30B, ... etc


u can write a hello word in the above format and try again
Ajay Bhargav
Nov 30 2010, 3:54 AM
if 0x style data doesnt work.. use

;For Hex
DB 01H, 10H, 30H ;and so on..

;For binary
DB 0b00000001, 0b01010010, ;and so on...

;For decimal
DB 1, 20, 30, 40


I suggest you to check user guide of compiler or assembler you are using for more information.
Reiniku
Nov 30 2010, 9:11 AM
I might be a bit confused, my apologies.

How do I go about writing

str_enter:
db "   hello world  ",0h

str_enter1:
db "C1= ",0h

str_enter2:
db "C2= ",0h


Using the syntax given above?
majoka
Nov 30 2010, 1:00 PM
hi Reiniku
u will write it in ascii characters
str_enter:
db 68h,65h,6ch,6ch,6fh,20h,77h,6fh,72h,6ch,64h,0h
and same can be written in binary
Reiniku
Nov 30 2010, 1:08 PM
I see, thank you! I have changed all 3 lines to be written in ascii characters and it assembled without errors but nothing shows on the LCD when I run the simulation. Edsim51 says that the lcd module is (HD44780).
majoka
Nov 30 2010, 1:13 PM
hi Reiniku
check that hex file with proteus
hex file that u create load that in Proteus ans see that is any thing comes on lcd or not
Reiniku
Nov 30 2010, 1:19 PM
I loaded the hex file into edsim and it assembled but sitll no LCD display. I do not have Proteus available to me.
ExperimenterUK
Nov 30 2010, 2:24 PM


I might be a bit confused

Reiniku


How bytes and strings are defined is very confusing because it varies a lot from
compiler to compiler.


How do I go about writing

db " hello world ",0h

Reiniku



This method should be acceptable as well.
db ' h','e','l','l','o',0

In your first post you had display code which was working and was all you needed.
Perhaps you should just use that and move onto the rest of the task.
Reiniku
Nov 30 2010, 3:50 PM
The sample that Majoka provided seemed very interesting and used interrupts to increment the counters. I was hoping to get it working so that I could learn from it thoroughly.

My initial post with the display code does only display a set value (in this case '0') and I have no idea how to create a way to increment or decrement the value.
ExperimenterUK
Nov 30 2010, 6:17 PM


The sample that Majoka provided seemed very interesting and used interrupts to increment the counters. I was hoping to get it working so that I could learn from it thoroughly.

Reiniku


I'm sure you would learn a lot from this code, but it may take time to get it
converted to suit Edsim, and then you will need to make a lot of changes to suit your task.



My initial post with the display code does only display a set value (in this case '0') and I have no idea how to create a way to increment or decrement the value.

Reiniku


Just increment or decrement a single memory location, there are a few ways but
INC 30h is the simplest, where 30h is an address.

Try to use address other that 30h,31h,32h,33h for your memory as you may get confused
with the ascii digits 0,1,2,3 which are also 30h,31h,32h,33h.



Reiniku
Nov 30 2010, 6:32 PM
That works great! I can put inc or dec on the code and increment and decrement the value at those address locations.

How would I go about doing this while edsim is already running and increment/decrement the value on the fly?
majoka
Nov 30 2010, 11:27 PM
hi Reiniku
how u change that DB format i download edsim its looking like nice graphics

How would I go about doing this while edsim is already running and increment/decrement the value on the fly?


select two pins for push buttons as signal on push buttons becomes low then increment or decrement as u want
during run time send a low signal to pin ans see is it do that or not

u can download Proteus if u want
1) http://ifile.it/1aov2lf
2) http://ifile.it/1aov2lf/Proteus%207.6%20sp0.rar
and portable version also here
http://www.8051projects.net/forum-t39541-0.html
Reiniku
Nov 30 2010, 11:30 PM
I had changed db values as you mentioend in a previous post:

"str_enter:
db 68h,65h,6ch,6ch,6fh,20h,77h,6fh,72h,6ch,64h,0h"
majoka
Dec 1 2010, 12:31 AM
ok dear
i never use edsim
how to configure lcd pins in that software
as in asm code pins of lcd r connected to p2
how will do setting in edsim
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Rickey's World © 2003 - 2007