Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Programing assembly with 8051 LCD and button

Status
Not open for further replies.

vudiepdh1

Junior Member level 1
Joined
Sep 30, 2009
Messages
15
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
Viet Nam
Activity points
1,379
Hi every body ! I'm newbie in 8051 field .so i start learning it with assembly. I want to programing 8051 with button and lcd(8bit mode). If i press Mode button once lcd display "mode1" press twice lcd display "mode 2" and press Exit button to exit. Im trying program but it not run ! If u did it, please help me code ! Thanks so much !
 

Before you connect LCD to 8051 try something simpler: a button (momentary switch) and an LED ..

How to poll a button that turns on an LED?
Here is an example (hardware reference: see attached picture):

Code:
ORG 0000H                ; Execution starts here


LOOP:SETB P0.3                ; Make port P0.3 as input port
       MOV C,P0.3        ; Get the button state to carry bit
       MOV P1.6,C        ; Display button state on LED
       SJMP LOOP                ; do it continuously
       END

The second example is a program that turns on the LED when the button is pressed once and turns off the LED when it is pressed again:

Code:
       ORG 0000H                ; Execution starts here
LOOP:SETB P0.3                ; Make port P0.3 as input port
       MOV C,P0.3        ; Get the button state to carry bit
       JC LOOP                ; check if button is pressed
       CPL P1.6                ; if pressed compliment the port
       JNB P0.3,$        ; Wait until the button is released
       SJMP LOOP                ; do it continuously
       END

You can add another sequence LOOP2: MOV C .. JC__ ... JNB__ ... and so on, to couninue switching the LED on and off ..

Once this is done, instead of controlling the LED, insert a CALL instruction to a sub that operates your LCD ..

Rgds,
IanP
 
  • Like
Reactions: raha_m

    raha_m

    Points: 2
    Helpful Answer Positive Rating
here is my project ! But it is not run exactly ! Please help me if u can !
 
  • Like
Reactions: raha_m

    raha_m

    Points: 2
    Helpful Answer Positive Rating
Code:
#include <sfr51.inc>
; pin p0.0 is  mode  button
; pin p0.1 is  exit button
; pin p1 -> data 
; pin p2.0 -> rs pin
; pin p2.1 -> r/w pin
; pin p2.2 > enable pin-

Flag		BIT   PSW.1   ; genearl purpose bit ..

		ORG   0000H

Main:		clr   Flag

Test_But:
		jnb 		p0.0, Test_But
		acall 	Delay_20
		jnb		p0.0, Test_But

		jb		Flag, Next1
		acall		Display1
		setb		Flag	; next time - goto display2 ..

		sjmp		But_Rel
		
Next1:
		acall		Display2
		clr		Flag

But_Rel:
		jb		p0.0, But_Rel; check if button is released ..
		sjmp		Test_But
	
; = = s u b s = = = =

send:		MOV	P1,A
		CLR	P2.0
		CLR	P2.1
		SETB	P2.2
		CLR	P2.2
		RET

; = = = = = =

display:	MOV	P1,A
		SETB	P2.0
		CLR	P2.1
		SETB	P2.2
		CLR	P2.2
		RET

; = = = = = =

initlcd: 	mov 	a,#38h
            acall send
            acall delay
            mov 	a,#0Eh 
            acall send
            acall delay
            mov 	a,#01h 
            acall send
            acall delay
            ret

; = = = = = =

display1:	acall	initlcd
		mov	a,#'M'
		acall display
		acall delay
		mov	a,#'O'
		acall	display
		acall delay
		mov	a,#'D'
		acall	display
		acall	delay
		mov	a,#'E'
		acall display
		acall delay
		mov	a,#'2'
 		acall display
		acall delay
		ret

; = = = = = =

display2:	acall initlcd
		mov	a,#'M'
		acall display
		acall delay
		mov	a,#'O'
		acall display
		acall delay
		mov	a,#'D'
		acall display
		acall delay
		mov	a,#'E'
		acall display
		acall delay
		mov	a,#'1'
		acall display
		acall delay
		ret

; = = = = = =

delay:	MOV	R3,#100

HERE1:  	MOV 	R4,#255
HERE2:  	DJNZ	R4,HERE2
		DJNZ	R3,HERE1
		RET

;----------------------20ms delay---------------------------------------

Delay_20:		PUSH		00h
			PUSH		01h
			MOV		R0, #30
Delay_20_Loop1:	MOV		R1, #255
Delay_20_Loop2:	DJNZ		R1, Delay_20_Loop2
			DJNZ		R0, Delay_20_Loop1 
			POP		01h
			POP		00h
			RET

END

I’ve modified button-de-bounce sequence, tided-up subs and left your display subroutines untouched ..
I still recon you should test the code wirh an LED first then switch to LCD display ..

Later on you can try to alter this code so the -EXIT button- is included ..

Rgds,
IanP
 
  • Like
Reactions: raha_m

    raha_m

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top