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.

Interfacing 8255, LCD and 8051

Status
Not open for further replies.

Berkoj

Newbie level 5
Joined
Dec 13, 2011
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,397
I'm interfacing an LCD to an 8051 microcontroller through a PPI 8255 chip.
The port 0 of the Microcontroller is connected to the AD0..AD7 pins of the 8255.
Port B of the 8255 is connected to the LCD with handshaking on Port C (0-2).
I will appreciate it a lot if someone can assist me in getting assembly language
codes to display characters on the LCD.

74ls373 multiplexer is also included in the circuit, connected to the 8255 via the A0-A1
pins and the microcontroller's port 0.

THanks in Advance
 

Thanks, BigDog... I realised that most of those tutorials use circuits in which the LCD is
directly connected to the Microcontroller. However, I do not know how the introduction
of the 8255 will affect the programming. What are some of the possible tricks or methods
I can use to achieve the same purpose? How do I enable a particular port on the 8255 to
output a required display on the LCD?
 

I use Port Expanders from time to time on projects, not the 8255 which has seen better days, but devices which use SPI or I2C.

I recommend writing routines with allow you to write/read a byte from any of the ports, PORTA, PORTB or PORTC, then using these routines build your LCD Library.

Always, break your project down into manageable pieces instead of swallowing it whole. You'll find it is not difficult to move a byte to and from a PORT on the 8255 PPI.

The main task in to configure the control register of the 8255.

Some examples and tutorials to get you started:

8255 Interfacing Example

8051 Hardware Interfacing

**broken link removed**


One issue to watch out for is that proper initialization of the LCD is crucial, attention to the required delays is very important for the LCD to function properly.

BigDog
 

Big Dog....Thanks for your replies. I've gone through the information on those sites. For an initialization of the LCD, where it is directly connected to the MCU, I've been able to do. However, initializing it with the introduction of the 8255 is my problem now.The information was helpful but I didn't get anything to help me with assembly language programming. The most useful of the information I had, had it's codes written in C. I'd appreciate some assistance in assembly language. Thanks again.
 

you have connected P0 to AD0...AD&. and also P0 lines to A0 and A1.

this is not possible.

either you connect the 8255 as external data memory or connect them as a port .
 

I don't get your point well, srizbf. Please help me understand... which A0 and A1 are u referring too?
 

I have attached a proteus illustration of my description and a code which displays some information on the lcd when hard wired, but not when simulated in Proteus. Is there anything wrong with the schematic or the code? Proteus.jpg

Code:
	ORG	0000H
	sjmp	start
	
	org 30h
SEC	EQU	00H
SEC_A	EQU	01H
MIN	EQU	02H
MIN_A	EQU	03H
HRS	EQU	04H
HRS_A	EQU	05H
DAY	EQU	06H
DATE	EQU	07H
MONTH	EQU	08H
YEAR	EQU	09H
Areg	EQU	0AH
Breg	EQU	0BH
Creg	EQU	0CH
SEC_RAM	EQU	0EH
MIN_RAM	EQU	10H
HRS_RAM	EQU	12H
DAY_RAM	EQU	14H
DATE_RAM EQU	15H
MONTH_RAM EQU	16H
YEAR_RAM EQU	17H
	

start:	
	acall	tdelay
	;acall	tdelay
	mov	r0,#Areg
	mov	a,#20h	;010, in D6-D4,turn on osc.
	movx	@r0,a	;send to A
	acall	tdelay
	;setting Timer mode
	mov	r0,#Breg
	mov	a,#82h	;BCD,24h, no update
	movx	@r0,a
	acall	tdelay
	;setting the TIME
	mov r0,#SEC
	mov a,#50h
	movx @r0,a
	acall	tdelay
	mov r0,#MIN
	mov  a,#16h
	movx @r0,a
	acall	tdelay
	mov  r0,#HRS
	mov  a,#12h
	movx @r0,a
	acall tdelay
	mov r0,#date
	mov a,#30H
	movx @r0,a
	acall tdelay
	mov r0,#month
	mov a,#12H
	movx @r0,a
	acall tdelay
	mov r0,#YEAR
	mov a,#11h
	movx @r0,a
	acall tdelay
	mov r0,#Breg
	mov a,#02h
	movx @r0,a
	
	
	



repeat:	
	lcall	init8255
	lcall 	LCDinit
	lcall	fistrowpos1
	
	lcall	LCD_String
	;acall 	delay
	
	;lcall	fistrowpos1
	;;acall	LCD_String1
	;acall	delay
	;lcall	fistrowpos1
	;acall	LCD_String2
	;acall	delay
	;lcall	fistrowpos1
	;acall	LCD_String3
	;acall	delay
	
	
	
	lcall	start_ADC
	lcall	hextoascii1
	;lcall 	slinePos1
	;clr	rs0
	;setb	rs1
	lcall	rs_set
	mov	a,r4
	lcall LCD_senddata
	lcall	rs_set
	mov	a,r5
	lcall LCD_senddata
	lcall	rs_set
	mov	a,r6
	lcall	LCD_senddata
	;lcall	delay
	;lcall	delay
	;
rep:	LCALL	slinepos1
	
	mov r0,#HRS
	movx	a,@r0
	
	mov r1,#HRS_RAM
	movx @r1,a
	lcall Asciiconv
	lcall rs_set
	mov a,20h
	lcall LCD_senddata
	lcall rs_set
	mov a,21h
	lcall LCD_senddata
	lcall rs_set
	mov a,#':'
	lcall LCD_senddata
	;
	;lcall rs_set
	mov r0,#MIN
	movx	a,@r0
	mov r1,#MIN_RAM
	movx @r1,a
	lcall Asciiconv
	lcall rs_set
	mov a,20h
	lcall LCD_senddata
	lcall rs_set
	mov a,21h
	lcall LCD_senddata
	lcall rs_set
	mov a,#':'
	lcall LCD_senddata
	;lcall rs_set
	;
	mov r0,#SEC
	movx	a,@r0
	mov r1, #SEC_RAM
	movx @r1,a
	lcall Asciiconv
	lcall rs_set
	mov a,20h
	lcall LCD_senddata
	lcall rs_set
	mov a,21h
	lcall LCD_senddata
	lcall delay
	;lcall delay
	;
	;
	LCALL	slinepos1
	mov r0,#DATE
	movx	a,@r0
	mov r1,#DATE_RAM
	movx @r1,a
	lcall Asciiconv
	lcall rs_set
	mov a,20h
	lcall LCD_senddata
	lcall rs_set
	mov a,21h
	lcall LCD_senddata
	lcall rs_set
	mov a,#':'
	lcall LCD_senddata
	;
	;lcall rs_set
	mov r0,#MONTH
	movx	a,@r0
	mov r1,#MONTH_RAM
	movx @r1,a
	lcall Asciiconv
	lcall rs_set
	mov a,20h
	lcall LCD_senddata
	lcall rs_set
	mov a,21h
	lcall LCD_senddata
	lcall rs_set
	mov a,#':'
	lcall LCD_senddata
	;lcall rs_set
	;
	mov r0,#YEAR
	movx	a,@r0
	mov r1, #YEAR_RAM
	movx @r1,a
	lcall Asciiconv
	lcall rs_set
	mov a,20h
	lcall LCD_senddata
	lcall rs_set
	mov a,21h
	lcall LCD_senddata
	;lcall delay
	;
	lcall fistrowpos8
	lcall  temp_disp
	lcall rs_set
	mov a,#'D'
	lcall LCD_senddata
	lcall rs_set
	mov a,#'e'
	lcall LCD_senddata
	;lcall delay
	lcall rs_set
	mov a,#'g'
	lcall LCD_senddata
	lcall delay
	ljmp	rep
	
slinePos1:
	lcall	rs_clr
	mov	dptr,#2001h
	mov	a,#0c0h
	movx	@dptr,a
	;MOV	P4,#0CFH	; Second line, last character
	;			; address (4FH)
	lcall	e_set
	lcall	e_clr	
	;SETB	P1.2		; E=1
	;CLR	P1.2		; E=0
	MOV	R0,#20		; Delay 2ms
	LCALL	DEL
	ret
tdelay:
	mov	tmod,#01h
	mov	tl0,#00h
	mov	th0,#0f0h
	setb	tr0
back2:	jnb	tf0,back2
	clr	tr0
	clr	tf0
	ret
Asciiconv:
          mov b,a
          swap a
          anl a,#0fh
          orl a,#30h
          mov 20h,a
          mov a,b
          anl a,#0fh
          orl a,#30h
          mov 21h,a
          ret
 temp_disp:         
	lcall	start_ADC
	lcall	hextoascii1
	;lcall 	slinePos1
	;clr	rs0
	;setb	rs1
	lcall	rs_set
	mov	a,r4
	lcall LCD_senddata
	lcall	rs_set
	mov	a,r5
	lcall LCD_senddata
	lcall	rs_set
	mov	a,r6
	lcall	LCD_senddata
	ret
          


init8255:
	; R/W=0 > Write
	mov	dptr,#2003h
	mov	a,#80h
	movx	@dptr,a
	ret
LCDinit:	
	
	lcall	rs_clr 
	;CLR	P1.0		; RS=0 > Control operation
	lcall	rw_clr
	;CLR	P1.1	
	mov	dptr,#2001h
	mov	a,#38h
	movx	@dptr,a
	;MOV	P4,#38H		; DL=1 > 8-bit interface
	lcall	e_set
	lcall	e_clr
	;SETB	P1.2		; E=1
	;CLR	P1.2		; E=0
	MOV	R0,#50		; Delay 5ms
	LCALL	DEL
	
	lcall	e_set
	lcall	e_clr
	;SETB	P1.2		; E=1
	;CLR	P1.2		; E=0
	MOV	R0,#20		; Delay 2ms
	LCALL	DEL
	
	lcall	e_set
	lcall	e_clr
	;SETB	P1.2		; E=1
	;CLR	P1.2		; E=0
	MOV	R0,#20		; Delay 2ms
	LCALL	DEL
	
	mov	dptr,#2001h
	mov	a,#0Fh 
	movx	@dptr,a
	;MOV	P4,#0FH		; D=1 > Display ON
;				; C=1 > Cursor ON
;				; B=1 > Blink the character
				; at the cusor position
	lcall	e_set
	lcall	e_clr			
	;SETB	P1.2		; E=1
	;CLR	P1.2		; E=0
	MOV	R0,#20		; Delay 2ms
	LCALL	DEL
	mov	dptr,#2001h
	mov	a,#06h
	movx	@dptr,a
	;MOV	P4,#06H		; I/D=1 > Increment the cursor
	;			; (move to the right)
	;			; S=0 > The display is not shifted
	lcall	e_set
	lcall	e_clr
	;SETB	P1.2		; E=1
	;CLR	P1.2		; E=0
	MOV	R0,#20		; Delay 2ms
	LCALL	DEL
;
	mov	dptr,#2001h
	mov	a,#01h
	movx	@dptr,a
	;MOV	P4,#01H		; Clear display
	lcall	e_set
	lcall	e_clr
	;SETB	P1.2		; E=1
	;CLR	P1.2		; E=0
	MOV	R0,#20		; Delay 2ms
	LCALL	DEL
	ret
fistrowpos1:

	;SETB	P1.0		; RS=1 > Data operation
	lcall	rs_clr
	;CLR	P1.0		; RS=0 > Control operation
	mov	dptr,#2001h
	mov	a,#80H
	movx	@dptr,a
	;MOV	P4,#8FH		; First line, last character
				; address (0FH)
	lcall	e_set
	lcall	e_clr
	MOV	R0,#20		; Delay 2ms
	LCALL	DEL			
	ret
fistrowpos8:

	;SETB	P1.0		; RS=1 > Data operation
	lcall	rs_clr
	;CLR	P1.0		; RS=0 > Control operation
	mov	dptr,#2001h
	mov	a,#8aH
	movx	@dptr,a
	;MOV	P4,#8FH		; First line, last character
				; address (0FH)
	lcall	e_set
	lcall	e_clr
	MOV	R0,#20		; Delay 2ms
	LCALL	DEL			
	ret
		
		;
LCD_String1:	push	dpl
		push	dph
		mov	dptr,#S10_s
		mov	50h,dpl
		mov	51h,dph

LCDstring1:	mov	dpl,50h
		mov	dph,51h
		CLR	A
		movc	a,@a+dptr
		mov	34h,a
		jz	exit1
		inc	dptr
		MOV 50H,DPL
		MOV 51H,DPH
		;lcall	rs_set
		;MOV	A,34H
		lcall LCD_Senddata1
		ajmp	LCDstring1
exit1:		
		pop	dph
		pop	dpl
		ret

		;
LCD_String2:	push	dpl
		push	dph
		mov	dptr,#Minutes1_s
		mov	50h,dpl
		mov	51h,dph

		
LCDstring2:	mov	dpl,50h
		mov	dph,51h
		CLR	A
		movc	a,@a+dptr
		mov	34h,a
		jz	exit2
		inc	dptr
		MOV 50H,DPL
		MOV 51H,DPH
		;lcall	rs_set
		;MOV	A,34H
		lcall LCD_Senddata1
		ajmp	LCDstring2
exit2:		
		pop	dph
		pop	dpl
		ret
		;
		;
LCD_String3:	push	dpl
		push	dph
		mov	dptr,#Minutes10_s
		mov	50h,dpl
		mov	51h,dph

LCDstring3:	mov	dpl,50h
		mov	dph,51h
		CLR	A
		movc	a,@a+dptr
		mov	34h,a
		jz	exit3
		inc	dptr
		MOV 50H,DPL
		MOV 51H,DPH
		;lcall	rs_set
		;MOV	A,34H
		lcall LCD_Senddata1
		ajmp	LCDstring3
exit3:		
		pop	dph
		pop	dpl
		ret
		;		
		;
LCD_String4:	push	dpl
		push	dph
		mov	dptr,#hour1_s
		mov	50h,dpl
		mov	51h,dph

LCDstring4:	mov	dpl,50h
		mov	dph,51h
		CLR	A
		movc	a,@a+dptr
		mov	34h,a
		jz	exit4
		inc	dptr
		MOV 50H,DPL
		MOV 51H,DPH
		;lcall	rs_set
		;MOV	A,34H
		lcall LCD_Senddata1
		ajmp	LCDstring4
exit4:		
		pop	dph
		pop	dpl
		ret
		
		;		
		;
LCD_String5:	push	dpl
		push	dph
		mov	dptr,#hour10_s
		mov	50h,dpl
		mov	51h,dph

LCDstring5:	mov	dpl,50h
		mov	dph,51h
		CLR	A
		movc	a,@a+dptr
		mov	34h,a
		jz	exit5
		inc	dptr
		MOV 50H,DPL
		MOV 51H,DPH
		;lcall	rs_set
		;MOV	A,34H
		lcall LCD_Senddata1
		ajmp	LCDstring5
exit5:		
		pop	dph
		pop	dpl
		ret
	
	
		
	
	;;;;;;;;;;;;;;;;;;;;;;;;;
	mov	dptr,#2001h
	mov	a,#'B'
	movx	@dptr,a
	;MOV	P4,#'B'		; Display 'B'
	lcall	e_set
	lcall	e_clr
	;SETB	P1.2		; E=1
	;CLR	P1.2		; E=0
	LCALL	T_BF

;
	mov	dptr,#2001h
	mov	a,#'D'
	movx	@dptr,a
	;MOV	P4,#'D'		; Display 'D'
	lcall	e_set
	lcall	e_clr	
	;SETB	P1.2		; E=1
	;CLR	P1.2		; E=0
	LCALL	T_BF
	;
	mov	dptr,#2001h
	mov	a,#'E'
	movx	@dptr,a
	;MOV	P4,#'D'		; Display 'D'
	lcall	e_set
	lcall	e_clr	
	;SETB	P1.2		; E=1
	;CLR	P1.2		; E=0
	LCALL	T_BF
	;
	mov	dptr,#2001h
	mov	a,#'f'
	movx	@dptr,a
	;MOV	P4,#'D'		; Display 'D'
	lcall	e_set
	lcall	e_clr	
	;SETB	P1.2		; E=1
	;CLR	P1.2		; E=0
	LCALL	T_BF
;
	;sjmp	$
LCD_Senddata:
	;lcall	rs_set
	mov	dptr,#2001h
	;mov	a,#'A'
	movx	@dptr,a
	;MOV	P4,#'A'		; Display 'A'
	lcall	e_set
	lcall	e_clr
	;SETB	P1.2		; E=1
	;CLR	P1.2		; E=0
	LCALL	T_BF
	ret
LCD_Senddata1:
	lcall	rs_set
	mov	dptr,#2001h
	;mov	a,#'A'
	mov	a,34h
	movx	@dptr,a
	;MOV	P4,#'A'		; Display 'A'
	lcall	e_set
	lcall	e_clr
	;SETB	P1.2		; E=1
	;CLR	P1.2		; E=0
	LCALL	T_BF
	ret
delay:	
	;setb	rs0
	;setb	rs1
	Mov r0,#08h
in2:	mov r1,#00h
in1:	mov r2,#00h
again:	djnz r2,again
	djnz r1,in1
	djnz r0,in2
	;clr	rs0
	;clr	rs1
	ret

e_clr:
	mov	dptr,#2003h
	mov	a,#00h
	movx	@dptr,a
	ret
e_set:
	mov	dptr,#2003h
	mov	a,#01h
	movx	@dptr,a
	ret
rw_clr:mov	dptr,#2003h
	mov	a,#02h
	movx	@dptr,a
	ret
rw_set:
	mov	dptr,#2003h
	mov	a,#03h
	movx	@dptr,a
	ret
rs_clr:
	mov	dptr,#2003h
	mov	a,#04h
	movx	@dptr,a
	ret
rs_set:
	mov	dptr,#2003h
	mov	a,#05h
	movx	@dptr,a
	ret
	
DEL:	PUSH	ACC		; Save ACC
DEL1:	MOV	A,#2FH
DEL2:	DJNZ	ACC,DEL2
	DJNZ	R0,DEL1
	POP	ACC		; Restore ACC
	RET
;
T_BF:	
	mov	dptr,#2001h
	mov	a,#0FFH
	movx	@dptr,a
	;MOV	P4,#0FFH	; Input port
	lcall	rs_clr
	;CLR	P1.0		; RS=0 > Control operation
	lcall	rw_set
	;SETB	P1.1		; R/W= > Read
T_BF1:	lcall	e_set
	;SETB	P1.2		; E=1
	mov	dptr,#2001h
	movx	a,@dptr
	;MOV	ACC,P4		; Read BF
	lcall	e_clr
	;CLR	P1.2		; E=0
	JB	ACC.7,T_BF1
	lcall	rs_set
	;SETB	P1.0		; RS=1 > Data operation
	lcall	rw_clr
	;CLR	P1.1		; R/W=0 > Write
	RET
	
hextoascii:
		
;*******************************************************************************
;           Returns the ASCII codes from the nibbles of a byte stored in the Acc.
;           After being called the high nibble is in the Acc and the low nibble 
;           is in the B register.
;
;
;          ;usage:
;
;          mov a, #byte
;          CALL nibble
;
;          ;returns
;          ;A= high nibble
;          ;B= low nibble
;*******************************************************************************

nibble:
            mov	 a,30h
            mov   b,a          ; b=a        ; stores Acc in B
            anl   a,#0f0h      ; a=xxxx0000    ; A && #f0h (get the high nibble)
            swap  a            ; a=0000xxxx    ; swap nibbles
            orl   a,#30h       ; a=0011xxxx    ; add #30h, if nibble is
            push acc           ; 0-9 we have the ASCII value
            push b             ; stores A and B
            mov b, #3ah        ; stores #3ah in B
            div ab             ; divide A/#3ah
            jz recupera1      ; if zero, nibble < #0Ah
nibble1_ok:
            pop b              ; recover B
            pop acc            ; recover A
            add a, #07h        ; adds #07h to get ASCII of A-F
            xch a,b
            jmp nibble2
recupera1:
            pop b            ; stores B
            pop acc            ; stores A
            xch a,b
nibble2:
            anl   a,#0fh        ; a=0000xxxx    ; A && #0fh (get low nibble)
            orl   a,#30h        ; a=0011xxxx    ; add #30h, if nibble is
            push acc            ; 0-9 we have the ASCII value
            push b            ; stores A and B
            mov b, #3ah            ; stores #3ah in B
            div ab            ; divide A/#3ah
            jz recupera2        ; if zero, nibble < #0Ah
            pop b            ; recover B
            pop acc            ; recover A
            add a, #07h        ; adds #07h to get ASCII of A-F
            xch a,b
            mov 32h,a
            mov 33h,b
            ret                ; return to main routine
recupera2:
            pop b            ; recover B
            pop acc            ; recover A
            xch a,b
            mov 32h,a
            mov 33h,b
            ret                ; return to main routine

;*******************************************************************************
                
LCD_String:	mov dptr,#My_String
		;clr	a
		mov	50h,dpl
		mov	52h,dph
			
LCDstring:	
		MOV	DPL,50H
		MOV	DPH,52H
		CLR	A
		movc	a,@a+dptr
		mov	34h,a
		jz	exit
		inc	dptr
		MOV 50H,DPL
		MOV 52H,DPH
		;lcall	rs_set
		;MOV	A,34H
		lcall LCD_Senddata1
		sjmp	LCDstring
exit:
		ret
		
Start_ADC:		
ADC_RD		equ	p3.2
ADC_WR		equ	p3.1
EOC		equ	p3.0
		;setb	ie0
		;setb	ex0
		;setb	ea
begin:		setb	ADC_RD
		setb	ADC_WR
;Start conversion
		clr	ADC_WR
		setb	ADC_WR
here:		jb	EOC,here
		clr	ADC_RD
		mov	a,p1
		mov	30h,a
		setb	ADC_RD
		lcall	DEL
		ret
hextoascii1:
		setb	rs1
		clr	rs0

                mov r4,#30h

                mov r5,#30h

                mov r6,#30h

                cjne a,#00h,c1_hextobcd            ; //check if number is 0 if not then continue
              ; clr	rs0
               ;clr	rs1 
                ret
  
c1_hextobcd:
		clr	c
		mov a,30h

                mov b,#100                      ;  //divide by 100

                div ab

                orl a,r4

                mov r4,a                            ;  //save 100th place in R0

                clr c

                mov a,b

                mov b,#10                         ;  //Divide by 10

                div ab

                orl a,r5

                mov r5,a                              ;//Save 10th place in R1

                mov a,b

                orl a,r6

                mov r6,a                             ; //Save  units place in R2
                ;clr	rs0
              ; clr	rs1

                ret
                

Busy flag checking

ready:
setb P1.7 ;D7 as input
clr P3.6 ;RS=0 cmd
setb P3.5 ;RW=1 for read
 
again:
setb P3.7 ;H->L pulse on E
clr P3.7
jb P1.7, again
ret		
                org 500h
My_String:
	db 'Core_Temp=',00h
	
	org 520h
 
Last edited by a moderator:

Have just uploaded a zipped file with the proteus file and the assembly codes....thanks
 

Attachments

  • proteus.zip
    30.2 KB · Views: 86

BigDog... any help available so far?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top