Advertisement
Guest User

Marin Purgar

a guest
Mar 30th, 2010
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. // LCD4Bits.pde
  2. //
  3. // Author: Marin Purgar - marin.purgar@gmail.com
  4. //
  5.  
  6. #define LCD_RS 8
  7. #define LCD_E 9
  8.  
  9. void lcdPulseEnable() {
  10. digitalWrite(LCD_E, HIGH);
  11. delayMicroseconds(1);
  12. digitalWrite(LCD_E, LOW);
  13. delayMicroseconds(1);
  14. }
  15.  
  16. void lcdWriteNibble(uchar c){
  17. int i;
  18. for(i=0; i<4; i++){
  19. digitalWrite(4+i, (c >> i) & 0x01);
  20. }
  21. lcdPulseEnable();
  22. }
  23.  
  24. void lcdWriteByte(uchar c, int mode) {
  25. digitalWrite(LCD_RS, mode);
  26. lcdWriteNibble(c >> 4);
  27. lcdWriteNibble(c);
  28. }
  29.  
  30. void lcdSendControl(uchar c) {
  31. lcdWriteByte(c, LOW);
  32. }
  33.  
  34. void lcdSendData(uchar c) {
  35. lcdWriteByte(c, HIGH);
  36. }
  37.  
  38. void lcdSetAddress(uchar line, uchar column) {
  39. lcdSendControl( 0x80 + 0x40 * (line - 1) + (column - 1));
  40. }
  41.  
  42. void lcdPrint(char *string) {
  43. int i;
  44. for( i=0; string[i]; i++) {
  45. lcdSendData(string[i]);
  46. }
  47. }
  48.  
  49. void lcdInit() {
  50. int i;
  51.  
  52. pinMode(LCD_E, OUTPUT);
  53. digitalWrite(LCD_E, LOW);
  54. pinMode(LCD_RS, OUTPUT);
  55. digitalWrite(LCD_RS, LOW);
  56. for(i = 4; i < 8; i++) {
  57. pinMode(i, OUTPUT);
  58. }
  59. delay(20);
  60. lcdWriteNibble(0x03);
  61. delayMicroseconds(1);
  62. lcdWriteNibble(0x03);
  63. delayMicroseconds(1);
  64. lcdWriteNibble(0x02);
  65. delayMicroseconds(200);
  66. lcdSendControl(0x28); // 4 Bit, 2 Lines
  67. delayMicroseconds(1);
  68. lcdSendControl(0x0C); // Display On
  69. delayMicroseconds(1);
  70. lcdSendControl(0x01); // Clear display
  71. delay(2);
  72. lcdSendControl(0x02); // Cursor home
  73. delay(2);
  74. }
  75.  
  76. uchar line1[] = "Pinguino Team ";
  77. uchar line2[] = "Croatia ";
  78.  
  79. uchar line3[] = "Marin Purgar ";
  80. uchar line4[] = "Goran Horvatic";
  81.  
  82. void setup() {
  83. lcdInit();
  84. }
  85.  
  86. void loop() {
  87. lcdSetAddress(1, 1);
  88. lcdPrint(line1);
  89. lcdSetAddress(2, 1);
  90. lcdPrint(line2);
  91. delay(3000);
  92.  
  93. lcdSetAddress(1, 1);
  94. lcdPrint(line3);
  95. lcdSetAddress(2, 1);
  96. lcdPrint(line4);
  97. delay(3000);
  98. }
  99.  
  100. // EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement