Thông báo

Collapse
No announcement yet.

89S52 giao tiếp LCD 16x2 chế độ 4 bit tại cổng P1

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • 89S52 giao tiếp LCD 16x2 chế độ 4 bit tại cổng P1

    Mình muốn sửa code này cho mạch dưới mà nó không chạy. Mọi người có thể giúp mình sửa được không? Xin cảm ơn!
    Code:
    $mod51
    ;+++++++++++++++++++++++++++variables
    ;++++++++++++++++++++++++++++++++++++
    
      U equ 31        ;memory location to hold upper nibble
      L equ 32 ;memory location to hold lower nibble
    
      Port equ P1      ;data port to connect LCD
      RS equ P1.0      ;RS pin connection
      RW equ P1.1      ;RW pin connection
      EN equ P1.2      ;EN pin connection
    
      ;connection of Port
      ;Port.1-Port.3 (not used)
      ;Port.4 = DB4
      ;Port.5 = DB5
      ;Port.6 = DB6
      ;Port.7 = DB7
    ;+++++++++++++++++++++++++++++++++++++
      ORG 0000h
      CLR RW
      ACALL init
    
      MOV A, #'T'     ;SEND "TENTUTS.COM 4BIT" 
      ACALL lcd_data     ;in first line of LCD
      MOV A, #'E'
      ACALL lcd_data
      MOV A, #'N'
      ACALL lcd_data
      MOV A, #'T'
      ACALL lcd_data
      MOV A, #'U'
      ACALL lcd_data
      MOV A, #'T'
      ACALL lcd_data
      MOV A, #'S'
      ACALL lcd_data
      MOV A, #'.'
      ACALL lcd_data
      MOV A, #'C'
      ACALL lcd_data
      MOV A, #'O'
      ACALL lcd_data
      MOV A, #'M'
      ACALL lcd_data
      MOV A, #' '
      ACALL lcd_data
      MOV A, #'4'
      ACALL lcd_data
      MOV A, #'B'
      ACALL lcd_data
      MOV A, #'I'
      ACALL lcd_data
      MOV A, #'T'
      ACALL lcd_data
    
      MOV A, #0c0H         ;switch to 2nd line of LCD
      ACALL lcd_cmd  
    
      MOV A, #'M'     ;SEND "MODE USING 2 PORT" 
      ACALL lcd_data     ;in SECOND line of LCD
      MOV A, #'O'
      ACALL lcd_data
      MOV A, #'D'
      ACALL lcd_data
      MOV A, #'E'
      ACALL lcd_data
      MOV A, #' '
      ACALL lcd_data
      MOV A, #'U'
      ACALL lcd_data
      MOV A, #'S'
      ACALL lcd_data
      MOV A, #'I'
      ACALL lcd_data
      MOV A, #'N'
      ACALL lcd_data
      MOV A, #'G'
      ACALL lcd_data
      MOV A, #' '
      ACALL lcd_data
      MOV A, #'2'
      ACALL lcd_data
      MOV A, #'P'
      ACALL lcd_data
      MOV A, #'O'
      ACALL lcd_data
      MOV A, #'R'
      ACALL lcd_data
      MOV A, #'T'
      ACALL lcd_data
      
      SJMP $     ;INFINITE LONG LOOP
    
    ;+++++++++++++++++++++++++++++Separator
    ;++++++++++++++++++++++++++++++++++++++
    
     
    separator:
       MOV U,A        ;save A at temp location U
       ANL U,#0F0H    ;mask it  with 0Fh (28h & F0h = 20h) 
       SWAP A         ;swap nibble (28h => 82H)
       ANL A,#0F0H    ;mask it with 0fh (82h & f0h = 80h)
       MOV L,A        ;save it at temp location L
       RET            ;return
    
    ;++++++++++++++++++++++++++Move To Port 
    ;++++++++++++++++++++++++++++++++++++++
    
    move_to_Port:
       MOV port,A       ;put content of A to port
       SETB EN    ;make EN high
       ACALL DELAY   ;call a short delay routine
       CLR EN     ;clear EN
       ACALL DELAY   ;short delay
       RET     ;return
    
                
    ;++++++++++++++++++++++++++LCD command 
    ;++++++++++++++++++++++++++++++++++++++
    
       lcd_cmd:
        CLR RS     ;clear rs, going to send command
        ACALL separator     ;separate the command and save to U and L
        MOV A, U     ;copy U to A
        ACALL move_to_port  ;move content of a to port 
        MOV A, L            ;copy L to A
        ACALL move_to_port  ;move content of a to port
        RET       ;return
     
    ;++++++++++++++++++++++++++++++LCD data
    ;++++++++++++++++++++++++++++++++++++++
    
      lcd_data:
       SETB RS            ;RS=1, going to send DATA
       ACALL separator    ;separate the data and save to U & L
       MOV A, U           ;copy U to A
       ACALL move_to_port ;send it to LCD
       MOV A, L           ;copy L to A
       ACALL move_to_port ;send it to LCD
       RET                ;return
    
    ;+++++++++++++++++++++++++Initilization
    ;++++++++++++++++++++++++++++++++++++++
    
    init:
       ACALL delay     ;some delay to lcd after power on
       ACALL delay
    
       MOV port, #20h  ;send 20h to lcd to set 4 bit mode
       CLR RS   ;after that we can use lcd_cmd
       SETB EN         ;make EN switching
       ACALL delay
       CLR EN
    
       MOV A, #28H
       ACALL lcd_cmd
       MOV A, #0CH
       ACALL lcd_cmd
       MOV A, #06H
       ACALL lcd_cmd
       MOV A, #01H
       ACALL lcd_cmd
       RET
    
    ;+++++++++++++++++++++++++++++++++Delay
    ;++++++++++++++++++++++++++++++++++++++
    
    delay:
       MOV R0, #10H
      L2: MOV R1,#0FH
      L1: DJNZ R1, L1
       DJNZ R0, L2
       RET
    
    ;+++++++++++++++++++++++++++++++++++++++
    
    end

Về tác giả

Collapse

teenbg97 Tìm hiểu thêm về teenbg97

Bài viết mới nhất

Collapse

Đang tải...
X