Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Thread Closed: Issue successfully resolved

???
02/04/04 13:45
Read: times


 
#63996 - 8051 with LCD
Hi I am new to the 8051 and I am trying to send data to my LCD via the 8051. The LCD I was given and stuck with is a TRIMOD-1538 STN LED B/L 16*2 character.
I have come up with the following code for what I want to do but when run the LCD flashes and different characters appear on the screen and disappear again.Can anyone help.

;======================================================================
;
; Author : Jeffrey Ryan
;
; Date : January 2004
;
; File : display2.asm
;
; Description : Will drive the lcd display
;
;======================================================================
;
$MOD812S ; Use 8052 predefined Symbols

LCD_DATA EQU P0
LCD_EN EQU P3.7
LCD_RS EQU P3.6
LCD_RW EQU P3.5
CHAR DATA 040H
;======================================================================

CSEG ; Defines the following as a
; segment of code

ORG 0000H ; Load Code at '0'
LJMP MAIN ; (main program)

;======================================================================

INIT_LCD:

CLR LCD_RW ; SELECTS WRITE MODE
SETB LCD_EN
CLR LCD_RS
MOV R0,#38h
Call SEND_CMD

MOV R0,#06H
Call SEND_CMD

MOV R0,#02H
CALL SEND_CMD

MOV R0,#0Ch
CALL SEND_CMD




SEND_CMD:
MOV CHAR,R0 ; SAVES R0 TO LOCATION CHAR
CALL CHKBUSY ; CHECKS BUSY FLAG
MOV R0,CHAR ; PULLS CONTENTS OF R0 FROM CHAR
MOV LCD_DATA,R0 ; SENDS TO PORT 0
CLR LCD_RW ; CLEARS R/W LINE
CLR LCD_RS ; CLEARS RS LINE
CALL PULSE_E ; CLOCKS IN DATA INTO LCD
RET ; RETURNS


CHKBUSY:
MOV R0,#0FFH
MOV LCD_DATA,R0 ; SETS UP PORT 0 AS I/P’S
CLR LCD_RS ; CLEARS RS LINE
SETB LCD_RW ; SETS R/W LINE
NOP
NOP
NOP


BUSYREAD:
SETB LCD_EN ; CLOCKS E HIGH
NOP
NOP
NOP
MOV ACC,LCD_DATA ; READS PORT 0
NOP
NOP
NOP
CLR LCD_EN ; CLOCKS E LOW
NOP
NOP
JB ACC.7,BUSYREAD ; IF BUSY, LOOP
RET


PULSE_E:
NOP
NOP
SETB LCD_EN ; CLOCKS E HIGH
NOP
NOP
NOP
NOP
NOP
CLR LCD_EN ; CLOCKS E LOW
NOP
NOP
RET




TEXTO:
DB 'Hello'
DB 099h
DB 'World'
DB 099h
RET

BOTHLINES:

PUSH PSW ;Save Carry
ACALL LINE1
INC DPTR
ACALL LINE2

FIN: POP PSW
RET

LINE1: MOV R0,#80h ;cursor address
CALL SEND_CMD
CALL WRITE
RET

LINE2: MOV R0,#0C0h ;set cursor address
CALL SEND_CMD
CALL WRITE
RET

WRITE:
MOV DPTR,#TEXTO
LCALL BOTHLINES

write_loop:

MOV A,R1
MOVC A,@A+DPTR
CJNE A,#9h,write_cont ;stop writing condition
RET

write_cont:
MOV R0,A
CALL send_char ;send 1 ASCII char
INC DPTR ;next char
JMP write_loop

send_char:
MOV CHAR,R0
CALL CHKBUSY
MOV R0,CHAR
MOV LCD_DATA,R0 ; initilise lcd
CLR LCD_RW
SETB LCD_RS
CALL PULSE_E
RET

MAIN: MOV SP,#18H
CLR P3.4
CPL P3.4
LCALL INIT_LCD

FINISH: JMP FINISH
END

List of 32 messages in thread
TopicAuthorDate
8051 with LCD            01/01/70 00:00      
   RE: 8051 with LCD            01/01/70 00:00      
      RE: 8051 with LCD            01/01/70 00:00      
      RE: 8051 with LCD            01/01/70 00:00      
      RE: 8051 with LCD            01/01/70 00:00      
         RE: 8051 with LCD            01/01/70 00:00      
   RE: 8051 with LCD            01/01/70 00:00      
   RE: 8051 with LCD            01/01/70 00:00      
      RE: 8051 with LCD            01/01/70 00:00      
   RE: 8051 with LCD            01/01/70 00:00      
   8051 with 20x2 LCD            01/01/70 00:00      
      RE: 8051 with 20x2 LCD            01/01/70 00:00      
      RE: 8051 with 20x2 LCD            01/01/70 00:00      
         RE: 8051 with 20x2 LCD            01/01/70 00:00      
            RE: 8051 with 20x2 LCD            01/01/70 00:00      
               RE: 8051 with 20x2 LCD            01/01/70 00:00      
                  RE: 8051 with 20x2 LCD            01/01/70 00:00      
                     RTFM            01/01/70 00:00      
                        Could not agree more!            01/01/70 00:00      
                        RE: RTFM            01/01/70 00:00      
                        RE: RTFM            01/01/70 00:00      
                     RE: 8051 with 20x2 LCD - Russell            01/01/70 00:00      
                        RE: 8051 with 20x2 LCD - Russell            01/01/70 00:00      
                           RE: 8051 with 20x2 LCD - Russell            01/01/70 00:00      
                              RE: 8051 with 20x2 LCD - Oleg            01/01/70 00:00      
      RE: 8051 with 20x2 LCD - Kapil            01/01/70 00:00      
         RE: 8051 with 20x2 LCD - Kapil            01/01/70 00:00      
            RE: 8051 with 20x2 LCD - Kapil            01/01/70 00:00      
               RE: 8051 with 20x2 LCD            01/01/70 00:00      
                  RE: 8051 with 20x2 LCD            01/01/70 00:00      
            RE: 20x2 LCD = 16x2 LCD !            01/01/70 00:00      
               RE: 20x2 LCD = 16x2 LCD !            01/01/70 00:00      

Back to Subject List