Advertisement
Guest User

Untitled

a guest
May 10th, 2011
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.10 KB | None | 0 0
  1. //Program to display special Characters on LCD using AVR Microcontroller (ATmega16)
  2. /*
  3. To display special character on LCD data
  4. LCD DATA port----PORT B
  5. ctrl port------PORT D
  6. rs-------PD0
  7. rw-------PD1
  8. en-------PD2
  9.  
  10. using internal clock frequency 1MHz
  11.  
  12. */
  13. #include<avr/io.h>
  14. #include<util/delay.h>
  15.  
  16. #define LCD_DATA PORTB //LCD data port
  17.  
  18. #define signal PORTD
  19. #define en PD2 // enable signal
  20. #define rw PD1 // read/write signal
  21. #define rs PD0 // register select signal
  22.  
  23. void LCD_cmd(unsigned char cmd);
  24. void init_LCD(void);
  25. void LCD_write(unsigned char data);
  26. void LCD_character();
  27.  
  28. int main()
  29. {
  30. DDRB=0xff;
  31. DDRD=0x07;
  32. init_LCD();
  33. _delay_ms(50); // delay of 50 mili seconds
  34. LCD_character();
  35. return 0;
  36. }
  37.  
  38. void init_LCD(void)
  39. {
  40. LCD_cmd(0x38); // initialization of 16X2 LCD in 8bit mode
  41. _delay_ms(1);
  42.  
  43. LCD_cmd(0x01); // clear LCD
  44. _delay_ms(1);
  45.  
  46. LCD_cmd(0x0E); // cursor ON
  47. _delay_ms(1);
  48.  
  49. LCD_cmd(0x80); // ---8 go to first line and --0 is for 0th position
  50. _delay_ms(1);
  51. return;
  52. }
  53.  
  54. void LCD_cmd(unsigned char cmd)
  55. {
  56. LCD_DATA=cmd;
  57. ctrl =(0<<rs)|(0<<rw)|(1<<en);
  58. _delay_ms(1);
  59. ctrl =(0<<rs)|(0<<rw)|(0<<en);
  60. _delay_ms(50);
  61. return;
  62. }
  63.  
  64. void LCD_write(unsigned char data)
  65. {
  66. LCD_DATA= data;
  67. ctrl = (1<<rs)|(0<<rw)|(1<<en);
  68. _delay_ms(1);
  69. ctrl = (1<<rs)|(0<<rw)|(0<<en);
  70. _delay_ms(50);  
  71. return ;
  72. }
  73.  
  74. void LCD_character()
  75. {
  76. LCD_cmd(64);  // Address where customized character is to be stored
  77. LCD_write(0);
  78. LCD_write(14);
  79. LCD_write(17);
  80. LCD_write(2);
  81. LCD_write(4);
  82. LCD_write(4);
  83. LCD_write(0);
  84. LCD_write(4);
  85. LCD_cmd(0x80);  // Location of LCD where the character is to be displayed
  86. LCD_write(0);  // Displaying the character created at address 0x64
  87. _delay_ms(10);
  88.  
  89. LCD_cmd(72);  // Address where customized character is to be stored
  90. LCD_write(0);
  91. LCD_write(10);
  92. LCD_write(21);
  93. LCD_write(17);
  94. LCD_write(18);
  95. LCD_write(4);
  96. LCD_write(0);
  97. LCD_write(0);
  98. LCD_cmd(0x82);  // Location of LCD where the character is to be displayed
  99. LCD_write(1);  // Displaying the character created at address 0x72
  100. _delay_ms(10);
  101.  
  102. LCD_cmd(80);  //Address where customized character is to be stored
  103. LCD_write(0);
  104. LCD_write(0);
  105. LCD_write(10);
  106. LCD_write(0);
  107. LCD_write(4);
  108. LCD_write(0);
  109. LCD_write(14);
  110. LCD_write(17);
  111. LCD_cmd(0x84);  // Location of LCD where the character is to be displayed
  112. LCD_write(2);  // Displaying the character created at address 0x80
  113. _delay_ms(10);
  114.  
  115. LCD_cmd(88);  //Address where customized character is to be stored
  116. LCD_write(1);
  117. LCD_write(3);
  118. LCD_write(5);
  119. LCD_write(9);
  120. LCD_write(9);
  121. LCD_write(11);
  122. LCD_write(27);
  123. LCD_write(24);
  124. LCD_cmd(0x86);  // Location of LCD where the character is to be displayed
  125. LCD_write(3);  // Displaying the character created at address 0x88
  126. _delay_ms(10);
  127.  
  128. LCD_cmd(96);  // Address where customized character is to be stored
  129. CD_write(0);
  130. LCD_write(0);
  131. LCD_write(0);
  132. LCD_write(4);
  133. LCD_write(0);
  134. LCD_write(31);
  135. LCD_write(0);
  136. LCD_cmd(0xC0);  // location where the character is to be displayed
  137. LCD_write(4);  // Display the character created at address 0x96
  138. _delay_ms(10);
  139.  
  140. LCD_cmd(104);  //Address where customized character is stored
  141. LCD_write(0);
  142. LCD_write(17);
  143. LCD_write(10);
  144. LCD_write(17);
  145. LCD_write(4);
  146. LCD_write(0);
  147. LCD_write(14);
  148. LCD_write(17);
  149. LCD_cmd(0xC2);  // Location of LCD where the character is to be displayed
  150. LCD_write(5);  // Display the character created at address 0x104
  151. _delay_ms(10);
  152.  
  153. LCD_cmd(112);  // Address where customized character is to be stored
  154. LCD_write(0);
  155. LCD_write(14);
  156. LCD_write(17);
  157. LCD_write(2);
  158. LCD_write(4);
  159. LCD_write(4);
  160. LCD_write(0);
  161. LCD_write(4);
  162. LCD_cmd(0xC4);  // Location of LCD where the character is to be displayed
  163. LCD_write(6);   // Display the character created at address 0x112
  164. _delay_ms(10);
  165.  
  166. LCD_cmd(120);  // Address where customized character is to be stored
  167. LCD_write(10);
  168. LCD_write(0);
  169. LCD_write(4);
  170. LCD_write(0);
  171. LCD_write(14);
  172. LCD_write(17);
  173. LCD_write(17);
  174. LCD_write(14);
  175. LCD_cmd(0xC6);  // Location of LCD where the character is to be displayed
  176. LCD_write(7);   // Display the character created at address 0x120
  177. _delay_ms(10);
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement