gpt4 book ai didi

c - LCD 遵循命令但不显示字符

转载 作者:行者123 更新时间:2023-11-30 15:25:34 26 4
gpt4 key购买 nike

我已经对 Atmega-16 微 Controller 进行了编程,以连接 LM016L LCD 显示器。程序如下:

#include <avr/io.h>
#include <util/delay.h>
#define MrLCDsCrib PORTB
#define DataDir_MrLCDsCrib DDRB
#define MrLCDsControl PORTD
#define DataDir_MrLCDsControl DDRD
#define LightSwitch 5
#define ReadWrite 7
#define BiPolarMood 2

void Check_IF_MrLCD_isBusy(void);
void Peek_A_Boo(void);
void Send_A_Command(unsigned char command);
void Send_A_Character(unsigned char character);

int main(void) {
DataDir_MrLCDsControl |= 1 << LightSwitch | 1 << ReadWrite | 1 << BiPolarMood;
_delay_ms(15);

Send_A_Command(0x01); //Clear Screen
_delay_ms(20);
Send_A_Command(0x38); //8-bit mode
_delay_ms(20);
Send_A_Command(0b00001110); // cursor on
_delay_ms(20);
Send_A_Command(0x0F); // cursor blinking
_delay_ms(20);

Send_A_Character(0x4E); //N
_delay_ms(20);
Send_A_Character(0x65); //e
_delay_ms(20);
Send_A_Character(0x77); //w
_delay_ms(20);


while (1) {}
}

void Check_IF_MrLCD_isBusy() {
DataDir_MrLCDsCrib = 0;
MrLCDsControl |= 1 << ReadWrite;
MrLCDsControl &= ~1 << BiPolarMood;

while (MrLCDsCrib >= 0x80) {
Peek_A_Boo();
}
DataDir_MrLCDsCrib = 0xFF;
}

//Peek_A_Boo() writes the data to or from the LCD that are waiting to be written
void Peek_A_Boo() {
MrLCDsControl |= 1 << LightSwitch;
asm volatile("nop");
asm volatile("nop");
MrLCDsControl &= ~1 << LightSwitch;
}

void Send_A_Command(unsigned char command) {
Check_IF_MrLCD_isBusy();
MrLCDsCrib = command;
MrLCDsControl &= ~ ((1 << ReadWrite) | (1 << BiPolarMood));
Peek_A_Boo();
MrLCDsCrib = 0;
}

void Send_A_Character(unsigned char character) {
Check_IF_MrLCD_isBusy();
MrLCDsCrib = character;
MrLCDsControl &= ~ (1 << ReadWrite);
MrLCDsControl |= 1 << BiPolarMood;
Peek_A_Boo();
MrLCDsCrib = 0;
}

当我向 LCD 发送命令(例如使光标闪烁)时,它工作得很好。但是当调用函数Send_A_Character()将字符写入屏幕时,它不起作用。我无法让 LCD 在屏幕上显示任何内容。上面的代码没有语法错误。如果你们中的任何人能够指出导致 LCD 无法在屏幕上显示任何内容的逻辑错误,那就太好了。我什至尝试将每个点的延迟增加到 2 秒,但这没有用。

最佳答案

我在这段代码上花了几个小时,但无法让它工作。不过,我设法在 LCD 上写了一些内容,如下所示:

  1. 需要将LCD的RW连接到MCu的GND
  2. 同样根据代码修改其他连接。
  3. 这是对我有用的代码:(http://circuitdigest.com/microcontroller-projects/lcd-interfacing-with-atmega32-avr)

    // Code for LCD Interfacing with ATmega32 AVR microcontroller
    #include <avr/io.h>
    #define F_CPU 1000000UL
    #include <util/delay.h>
    #define RS 6
    #define E 5
    void send_a_command (unsigned char command);
    void send_a_character(unsigned char character);
    int main(void)
    {
    DDRA = 0xFF;
    DDRD = 0xFF;
    _delay_ms(50);
    send_a_command(0x01);// sending all clear command
    send_a_command(0x38);// 16*2 line LCD
    send_a_command(0x0E);// screen and cursor ON

    send_a_character (0x44); // ASCII(American Standard Code for Information Interchange) code for 'D'
    send_a_character (0x49); // ASCII(American Standard Code for Information Interchange) code for 'I'
    send_a_character (0x4C); // ASCII(American Standard Code for Information Interchange) code for 'L'
    send_a_character (0x49); // ASCII(American Standard Code for Information Interchange) code for 'I'
    send_a_character (0x50); // ASCII(American Standard Code for Information Interchange) code for 'P'

    }
    void send_a_command (unsigned char command)
    {
    PORTA=command;
    PORTD&= ~(1<<RS);
    PORTD|= (1<<E);
    _delay_ms(50);
    PORTD&= ~(1<<E);
    PORTA =0;
    }
    void send_a_character (unsigned char character)
    {
    PORTA=character;
    PORTD|= (1<<RS);
    PORTD|= (1<<E);
    _delay_ms(50);
    PORTD&= ~(1<<E);
    PORTA =0;
    }

关于c - LCD 遵循命令但不显示字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27780623/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com