|
*/
int RS = 12;
int RW = 11;
int Enable = 2;
int LSB = 3;
int D0 = 3;
int D1 = 4;
int D2 = 5;
int D3 = 6;
int D4 = 7;
int D5 = 8;
int D6 = 9;
int D7 = 10;
int counter = 0;
char Busy = 0x80;
void lcdBusPrepare(char src)
{
bool val;
for(int i=0; i<8; i++)
{
val = (src >> i) & 0x01;
if(val == 0)
digitalWrite(LSB+i, LOW);
else
digitalWrite(LSB+i, HIGH);
}
delay(1);
}
void lcdStatusRead()
{
delay(10);
}
void lcdDataWrite(char src)
{
lcdStatusRead();
lcdBusPrepare(src);
digitalWrite(RS, HIGH);
digitalWrite(RW, LOW);
digitalWrite(Enable, LOW);
delay(1);
digitalWrite(Enable, HIGH);
delay(1);
}
void lcdCmdWrite(char src, bool bWaitForLeisure)
{
if(bWaitForLeisure)
lcdStatusRead();
lcdBusPrepare(src);
digitalWrite(RS, LOW);
digitalWrite(RW, LOW);
digitalWrite(Enable, LOW);
delay(1);
digitalWrite(Enable, HIGH);
delay(1);
}
void lcdDisplay(char src, char posX, char posY)
{
char posCmd;
posX &= 0x0F;
posY &= 0x01;
if(posY != 0)
posX |= 0x40;
posCmd = posX | 0x80;
lcdCmdWrite(posCmd, 0);
lcdDataWrite(src);
}
void setup()
{
delay(500);
pinMode(RS,OUTPUT);
pinMode(RW,OUTPUT);
pinMode(Enable,OUTPUT);
for(int i=0; i<8; i++)
{
pinMode(LSB+i, OUTPUT);
}
lcdCmdWrite(0x38, false);
delay(5);
lcdCmdWrite(0x38, false);
delay(5);
lcdCmdWrite(0x38, false);
delay(5);
lcdCmdWrite(0x38, true);
lcdCmdWrite(0x08, true); // disable display
lcdCmdWrite(0x01, true); // clear the screen;
lcdCmdWrite(0x06, true); // do something with the cursor
lcdCmdWrite(0x0C, true); // enable the display
/// display a char
lcdDisplay('B', 5, 0);
lcdDisplay('S', 6, 0);
lcdDisplay('K', 7, 0);
lcdDisplay('Y', 8, 0);
lcdDisplay('H', 4, 1);
lcdDisplay('E', 5, 1);
lcdDisplay('L', 6, 1);
lcdDisplay('L', 7, 1);
lcdDisplay('O', 8, 1);
lcdDisplay('!', 9, 1);
}
void loop()
{
char src;
counter = counter + 1;
if(counter > 9)
counter = 0;
src = counter + '0';
lcdDisplay(src, 12, 0);
lcdDisplay(src, 11, 1);
delay(1000);
} |
|