Advertisement
Guest User

Untitled

a guest
Apr 26th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.71 KB | None | 0 0
  1. /*
  2.  * Project name:
  3.      Lcd_Test (Demonstration of the LCD library routines)
  4.  * Copyright:
  5.      (c) Mikroelektronika, 2009.
  6.  * Revision History:
  7.      20080930:
  8.        - initial release;
  9.        - 20090818 - Slavisa Zlatanovic;
  10.  * Description:
  11.      This code demonstrates how the usage of the LCD 4-bit library. LCD is first
  12.      initialized, then some text is written, then the text is moved.
  13.  * Test configuration:
  14.      MCU:             ATmega16
  15.                       http://www.atmel.com/dyn/resources/prod_documents/doc2466.pdf
  16.      Dev.Board:       EasyAVR6
  17.                       http://www.mikroe.com/en/tools/easyavr6/
  18.      Oscillator:      External Clock 08.0000 MHz
  19.      Ext. Modules:    Character LCD 2x16
  20.                       http://www.mikroe.com/en/tools/components/#other
  21.      SW:              mikroC PRO for AVR
  22.                       http://www.mikroe.com/en/compilers/mikroc/avr/
  23.  * NOTES:
  24.      - Turn on the LCD backlight on the EasyAVR6 board (SW10.7).
  25. */
  26.  
  27. // LCD module connections
  28. sbit LCD_RS at PORTD.B2;
  29. sbit LCD_EN at PORTD.B3;
  30. sbit LCD_D4 at PORTD.B4;
  31. sbit LCD_D5 at PORTD.B5;
  32. sbit LCD_D6 at PORTD.B6;
  33. sbit LCD_D7 at PORTD.B7;
  34.  
  35. sbit LCD_RS_Direction at DDRD.B2;
  36. sbit LCD_EN_Direction at DDRD.B3;
  37. sbit LCD_D4_Direction at DDRD.B4;
  38. sbit LCD_D5_Direction at DDRD.B5;
  39. sbit LCD_D6_Direction at DDRD.B6;
  40. sbit LCD_D7_Direction at DDRD.B7;
  41. // End LCD module connections
  42.  
  43. char txt1[] = "mikroElektronika";    
  44. char txt2[] = "EasyAVR6";
  45. char txt3[] = "Lcd4bit";
  46. char txt4[] = "example";
  47.  
  48. char i;                              // Loop variable
  49.  
  50. void Move_Delay() {                  // Function used for text moving
  51.   Delay_ms(500);                     // You can change the moving speed here
  52. }
  53.  
  54. void main(){
  55.   Lcd_Init();                        // Initialize LCD
  56.   Lcd_Cmd(_LCD_CLEAR);               // Clear display
  57.   Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  58.  
  59.   Lcd_Out(1,6,txt3);                 // Write text in first row
  60.   Lcd_Out(2,6,txt4);                 // Write text in second row
  61.   Delay_ms(2000);
  62.   Lcd_Cmd(_LCD_CLEAR);               // Clear display
  63.  
  64.   Lcd_Out(1,1,txt1);                 // Write text in first row
  65.   Lcd_Out(2,4,txt2);                 // Write text in second row
  66.   Delay_ms(2000);
  67.  
  68.   // Moving text
  69.   for(i=0; i<4; i++) {               // Move text to the right 4 times
  70.     Lcd_Cmd(_LCD_SHIFT_RIGHT);
  71.     Move_Delay();
  72.   }
  73.  
  74.   while(1) {                         // Endless loop
  75.     for(i=0; i<7; i++) {             // Move text to the left 7 times
  76.       Lcd_Cmd(_LCD_SHIFT_LEFT);
  77.       Move_Delay();
  78.     }
  79.  
  80.     for(i=0; i<7; i++) {             // Move text to the right 7 times
  81.       Lcd_Cmd(_LCD_SHIFT_RIGHT);
  82.       Move_Delay();
  83.     }
  84.  
  85.   }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement