|
hi glasspusher thanks for providing this code
/* Analog in to LCD 4 bits * --------- * Adapted from the "analog_read_send" and "lcd_8bits" tutorials. * This example uses 4 less pins on the Arduino than the 8 bit example. * It will take a reading from a 'K' Type thermocouple ice point reference chip * on Analog Input 2 and display the temperature in degrees Centigrade on the LCD. * One can also set a target temperature for turning a relay off, say for a heater, * at a given setpoint temperature. This is done on digital pin 4. * * These are the pins used on the LCD: * * - DI(register select), RW, DB4..DB7, Enable (7 in total) * * the pinout for LCD displays is standard and there is plenty * of documentation to be found on the internet. * * 2006, Dave Sopchak glasspusher at outofoptions dot net * */
int DI = 12; // register select int RW = 11; int DB[] = {7, 8, 9, 10}; int Enable = 6;
int temperaturePin = 2; // select the input pin for the temperature int ledPin = 13; // pin for the LED
void tickleEnable() { // send a pulse to enable digitalWrite(Enable,HIGH); delayMicroseconds(1); // pause 1 ms according to datasheet digitalWrite(Enable,LOW); delayMicroseconds(1); // pause 1 ms according to datasheet }
void cmdWriteSet() { digitalWrite(Enable,LOW); delayMicroseconds(1); // pause 1 ms according to datasheet digitalWrite(DI,0); digitalWrite(RW,0); } void LcdCommandWrite(int value) { int i = 0;
for (i=DB[3]; i >= DB[0]; i--) // high nybble first { digitalWrite(i, value & 128); value <<= 1; } cmdWriteSet(); tickleEnable();
for (i=DB[3]; i >= DB[0]; i--) // low nybble next { digitalWrite(i, value & 128); value <<= 1; } cmdWriteSet(); tickleEnable(); }
void LcdDataWrite(int value) { int i = 0;
digitalWrite(DI, HIGH); digitalWrite(RW, LOW); for (i=DB[3]; i >= DB[0]; i--) // high nybble first { digitalWrite(i, value & 128); value <<= 1; } tickleEnable();
for (i=DB[3]; i >= DB[0]; i--) // low nybble next { digitalWrite(i, value & 128); value <<= 1; } tickleEnable(); }
void setup (void) { int i; for (i=Enable; i <= DI; i++) pinMode(i,OUTPUT);
delay(100); // initiatize lcd after a short pause // needed by the LCDs controller LcdCommandWrite(0x28); // function set: delay(64); // 4-bit interface, 2 display lines, 5x7 font // other interaces: // 0x20 = 4 bit, 1 display line
LcdCommandWrite(0x28); // function set: delay(64); // 4-bit interface, 2 display lines, 5x7 font
LcdCommandWrite(0x06); // entry mode set: // increment automatically, no display shift delay(20); LcdCommandWrite(0x0E); // display control: // turn display on, cursor on, no blinking delay(20); LcdCommandWrite(0x01); // clear display, set cursor position to zero delay(100); LcdCommandWrite(0x80); // display control: // turn display on, cursor on, no blinking delay(20); }
void loop (void) { int i, val = 0; for(i = 0; i < 20; ++i) { val += analogRead(temperaturePin); // read the value from the sensor delay(50); } val /= 4.06; // conversion value to millivolts digitalWrite(ledPin, HIGH); // turn the ledPin on delay(500); // stop the program for some time digitalWrite(ledPin, LOW); // turn the ledPin off if(val > 175 * 10) // temperature in deg C times 10, since we're measuring to tenths of a degree digitalWrite(4,LOW); else digitalWrite(4,HIGH);
LcdCommandWrite(0x02); // set cursor position to zero delay(10); firstDisplay(val); }
void firstDisplay(int value) { int first,second, third, fourth; first = value / 1000; // second = (value - 1000 * first)/ 100; third = (value - 1000 * first - 100 * second)/ 10; fourth = (value - 1000 * first - 100 * second - 10 * third);
LcdDataWrite('T'); LcdDataWrite('e'); LcdDataWrite('m'); LcdDataWrite('p'); LcdDataWrite(' '); LcdDataWrite('='); LcdDataWrite(' ');
LcdDataWrite(value > 999 ? first + 48 : ' '); // begin onscreen LcdDataWrite(value > 99 ? second + 48 : ' '); LcdDataWrite(third + 48); LcdDataWrite('.'); LcdDataWrite(fourth + 48);
LcdDataWrite(' '); LcdDataWrite('C'); LcdDataWrite(' '); LcdDataWrite(' '); }
...its really helping me alot... it will be very kind of u, if u also provide the schematic diagram to allow driving an LCD display in 4 bit mode that can display temperature on it and to make this code workable as i m taking the help frm this code in order to complete my obective that pretty much resemble with urs one.... THanks in Advance
|