在关于5个HRS的家庭作业之后询问此事,从而避免来自GOOGLE的最佳搜索参考
我正在尝试将LCD JHD162A连接到ioio V1,但LCD没有初始化,它显示单行黑盒,ON REFERING我的意思是“ LCD没有正确初始化”,可能是什么原因 ?任何人都可以帮助核心代码如下所示,代码是否有任何错误?
连接:
LCD 16x2 | RS | E | D0 | D1 | D2 | D3 | D4 | D5 | D6 | D7 |
IOIO Board |端口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++;
}
}
}