1

在大约 5 小时的作业后在这里提问,因此避免来自 GOOGLE 的热门搜索参考


我正在尝试将 LCD JHD162A 连接到 ioio V1,但 LCD 未初始化,它显示单行黑盒,我的意思是“ LCD 未正确初始化”,可能是什么原因?任何人都可以帮助核心代码如下所示,代码有什么错误吗?

连接:


  • 液晶 16x2 | 回复 | E | D0 | D1 | D2 | D3 | D4 | D5 | D6 | D7 |


  • IOIO 板 | 端口 1 | 端口 2 | 端口 3 | 端口 4 | 端口 5 | 端口 6 | 端口 7 | 端口 8 | 端口 9 | 端口 10 |


所有连接都正常并检查三次或更多
信息:对比度可调

核心代码:

class Looper extends BaseIOIOLooper {


// Create object for assigned to output port
private DigitalOutput D0,D1,D2,D3,D4,D5,D6,D7,RS,E;

// This function will do when application is startup
// Like onCreate function but use with ioio board
@Override
public void setup() throws ConnectionLostException {

    // Assigned eacth object to each output port and initial state is false

    D0 = ioio_.openDigitalOutput(3, false);
    D1 = ioio_.openDigitalOutput(4, false);
    D2 = ioio_.openDigitalOutput(5, false);
    D3 = ioio_.openDigitalOutput(6, false);
    D4 = ioio_.openDigitalOutput(7, false);
    D5 = ioio_.openDigitalOutput(8, false);
    D6 = ioio_.openDigitalOutput(9, false);
    D7 = ioio_.openDigitalOutput(10, false);
    RS = ioio_.openDigitalOutput(1, false);
    E = ioio_.openDigitalOutput(2, false);



            lcd_init();
            Print("LCD is ok", 0x82);

    }


}

// This function will always running when device connect with ioio board
// It use for control ioio board
@Override
public void loop() throws ConnectionLostException { }

// Function for send high pulse to LCD
public void enable() {
    try {

        // Set e to be High
        E.write(true);

        // Send high pulse for one millisecond
        Thread.sleep(1);

        // Set back to Low
        E.write(false);
    } catch (ConnectionLostException e) {
    } catch (InterruptedException e) { }
}

// Function for convert integer to boolean and send to data port on LCD
public void senddatabit(int i) {
    // Call function for convert integer to boolean
    // and set boolean logic to each port
    try {
        D0.write(check(i));
        D1.write(check(i >> 1));
        D2.write(check(i >> 2));
        D3.write(check(i >> 3));
        D4.write(check(i >> 4));
        D5.write(check(i >> 5));
        D6.write(check(i >> 6));
        D7.write(check(i >> 7));
    } catch (ConnectionLostException e) {
        e.printStackTrace();
    }       

    // Call enable function
    enable();
}

// Function for convert integer value to boolean
public boolean check(int i) {

    // Create variable for convert binary to boolean
    // Use for command LCD on IOIO Board
    boolean st = false;
    i = i & 0x01;
    // If i = 0 set st = false or if i =1 set st = true
    // and return st back to main program
    if(i == 0x00)
        st = false;
    else if(i == 0x01)
        st = true;
    return st;
}

// Send command to LCD
public void lcd_command(int com) {
    try {
        // Set rs port to low
        RS.write(false);
    } catch (ConnectionLostException e) {
        e.printStackTrace();
    }

    // Call senddatabit for send command
    senddatabit(com);
}

// Send command to LCD
public void lcd_write(int text) {
    try {
        // Set rs port to high
        RS.write(true);
    } catch (ConnectionLostException e) {
        e.printStackTrace();
    }

    // Call senddatabit for send data
    senddatabit(text);
}       

// Send data to LCD
public void lcd_init() {

    // LCD 8 Bit 5x7 Dot 2 Line
    lcd_command(0x38);

    // Clear screen
    lcd_command(0x01);

    // Display on, no cursor
    lcd_command(0x0C); 


}

// Send one letters to LCD with set address
public void SendC(char c, int address) {

    // Set address
    lcd_command(address);

    // Send the letters to LCD
    lcd_write(Integer.valueOf(c));
}

// Send text string to LCD
public void Print(String str, int address) {

    // Send the letters one by one until the end
    for (int i = 0; i < str.length(); i++) {
        SendC(str.charAt(i), address);
        address++;
    }
}
}
4

0 回答 0