Я работаю над этим проектом, используя микроконтроллер 8051 (AT89S51), и он включает взаимодействие с ЖК-дисплеем. Схема проекта, над которым я работаю, показана ниже:
И я написал очень простой код для ЖК-дисплея для отображения контента. Код выглядит следующим образом:
ORG 0000H
SJMP INIT_MAIN ;For interrupts
INIT_MAIN:
;Initializing the LCD Display with the initial commands:
MOV A, #38H ;Setting up the LCD to operate in 8 bit mode
ACALL CMD
MOV A, #0FH ;Turning the display on
ACALL CMD
MOV A, #01H ;Clearing the curser
ACALL CMD
MOV A, #06H ;Putting the curser incriment mode to be left to right
ACALL CMD
MOV A, #3CH ;Activating the second line of the LCD
ACALL CMD
MOV A, #80H ;Putting the curser to be at position 1 (the first place)
ACALL CMD
;Writing serially on the LCD
MOV DPTR, #WELCOME1 ;Pointing the data pointer at the data array WELCOME1
MOV 41H, #13H ;Specifying the message's length
LCALL LCD_SERIAL ;Giving the command to the uC to print it on the LCD
MOV A, #0C0H ;Jump to second line position one
ACALL CMD
MOV DPTR, #WELCOME2 ;Pointing the data pointer at the data array WELCOME1
MOV 41H, #13H ;Specifying the message's length
LCALL LCD_SERIAL ;Giving the command to the uC to print it on the LCD
MOV A, #094H ;Jump to third line position one
ACALL CMD
MOV DPTR, #WELCOME3 ;Pointing the data pointer at the data array WELCOME1
MOV 41H, #13H ;Specifying the message's length
LCALL LCD_SERIAL ;Giving the command to the uC to print it on the LCD
MOV A, #0D4H ;Jump to fourth line position one
ACALL CMD
MOV DPTR, #WELCOME4 ;Pointing the data pointer at the data array WELCOME1
MOV 41H, #10H ;Specifying the message's length
LCALL LCD_SERIAL ;Giving the command to the uC to print it on the LCD
MOV A, #0FFH ;Pointing the curser away from the screen
ACALL CMD
MAIN:
SJMP MAIN
;-------------------------------------DELAY SUBROUTINES-------------------------------------
DELAY_1ms: ;delay for 1ms subroutine
MOV 39H,#0FAH ;Load 0FA into the register 39H
MOV 40H,#0FAH ;Load 0FA into the register 40H
LABEL1: DJNZ 39H,LABEL1 ;Decrease 39H by one and jump if not zero
LABEL2: DJNZ 40H,LABEL2 ;Decrease 40H by one and jump if not zero
RET
;-------------------------------------LCD SUBROUTINES---------------------------------------
CMD: ;Commands used in intializations
MOV P1, A ;Move the values of A to Pin 1. These will be the commands we want to transfer
CLR P3.5 ;This makes the RS equal to 0. When RS is zero,
CLR P3.6 ;This makes the RW equal to 0. When RW is zero,
SETB P3.7 ;This control the latch. Setting it and resetting it, latches the data
CLR P3.7 ;This control the latch. Setting it and resetting it, latches the data
ACALL DELAY_1ms ;A delay is required because on practical LCDs, it takes some time to change
RET
LCD_SERIAL: ;Used to display strings onto the LCD
MOV R0, #00H
REPEAT:
MOV A,R0
MOVC A,@A+DPTR ;obtain LCD lookup table
ACALL LCD_DISPLAY ;Display the character on the screen
INC R0 ;Increment R0
DJNZ 41H, REPEAT
RET
LCD_DISPLAY: ;Used to display info onto the LCD
MOV P1, A ;Move the values of A to pin 1. The data will now be on Port 1
SETB P3.5 ;This makes RS equal to 1. When RS is one,
CLR P3.6 ;This makes the RW equal to 0. When RW is one,
SETB P3.7 ;This control the latch. Setting it and resetting it, latches the data
CLR P3.7 ;This control the latch. Setting it and resetting it, latches the data
ACALL DELAY_1ms ;A delay is required because on practical LCDs, it takes some time to change
RET
;--------------------------------------LOOK UP TABLES---------------------------------------
WELCOME1:
DB 'WELCOME TO THE BANK'
WELCOME2:
DB 'PREVIOUS NUMBER 000'
WELCOME3:
DB 'YOUR NUMBER IS: ---'
WELCOME4:
DB 'HAVE A GOOD DAY!'
END
Приведенный выше код — это не полный код, который я написал, а только его части, относящиеся к ЖК-дисплею.
Этот код отлично работает в протейной симуляции (как видно из рисунка). Однако он вообще не работает, когда я строю его на реальной схеме. Иногда подсветка ЖК-дисплея просто включалась, и ничего не отображалось (даже черных квадратов), даже если я регулировал потенциометр. Иногда появлялись черные квадраты, но после сброса 8051 они исчезали.
Если это имеет значение, я использую программатор MikroE 8051,
Я сделал следующее вчера при построении схемы:
Я был бы очень признателен, если бы кто-нибудь мог дать мне представление о том, почему это может иметь место
Контроллер ЖК-дисплея может быть в 4-битном режиме и, что еще хуже, посередине между первым полубайтом и вторым. Так что ваша первая команда может быть не понята. Отправьте его 3 раза, чтобы разрешить любую ситуацию.
Кроме того, реальные ЖК-дисплеи имеют временные ограничения. IIRC некоторым из них требуется больше времени, чем 1 мс после инициализации команд. Пожалуйста, прочтите техпаспорт конкретной детали, которую вы используете. ЖК-дисплею может потребоваться некоторое время, чтобы он был готов принимать команды после включения питания.
Наконец, проверьте, что ваша задержка действительно составляет 1 мс.
Проверьте спецификацию вашего ЖК-дисплея еще раз.
Во всех таблицах данных ЖК-дисплеев у меня есть заземление на контакте 1, питание на контакте 2 и контрастность на контакте 3.
Припой