Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. /**************************************/
  2. /* ARE 2008 */
  3. /* e-mail: biuro@are.net.pl */
  4. /* www : are.net.pl */
  5. /**************************************/
  6.  
  7. #define F_CPU 8000000UL // 1 MHz
  8. //#define F_CPU 14.7456E6
  9. #include <avr/io.h>
  10. #include <stdio.h>
  11. #include <util/delay.h>
  12. #include <string.h>
  13.  
  14. void delay_ms(int ms)
  15. {
  16. volatile long unsigned int i;
  17. for(i=0;i<ms;i++)
  18. _delay_ms(1);
  19. }
  20.  
  21. void delay_us(int us)
  22. {
  23. volatile long unsigned int i;
  24. for(i=0;i<us;i++)
  25. _delay_us(1);
  26. }
  27.  
  28. //RS PA0
  29. //RW PA1
  30. //E PA2
  31. //DATA PD
  32.  
  33. #define RS 0
  34. #define RW 1
  35. #define E 2
  36.  
  37. void LCD2x16_init(void)
  38. {
  39. PORTB &= ~(1<<RS);
  40. PORTB &= ~(1<<RW);
  41.  
  42. PORTB |= (1<<E);
  43. PORTD = 0x38; // dwie linie, 5x7 punktow
  44. PORTB &=~(1<<E);
  45. _delay_us(120);
  46.  
  47. PORTB |= (1<<E);
  48. PORTD = 0x0e; // wlacz wyswietlacz, kursor, miganie
  49. PORTB &=~(1<<E);
  50. _delay_us(120);
  51.  
  52. PORTB |= (1<<E);
  53. PORTD = 0x06;
  54. PORTB &=~(1<<E);
  55. _delay_us(120);
  56. }
  57.  
  58. void LCD2x16_clear(void){
  59. PORTB &= ~(1<<RS);
  60. PORTB &= ~(1<<RW);
  61.  
  62. PORTB |= (1<<E);
  63. PORTD = 0x01;
  64. PORTB &=~(1<<E);
  65. delay_ms(120);
  66. }
  67.  
  68. void LCD2x16_putchar(int data)
  69. {
  70. PORTB |= (1<<RS);
  71. PORTB &= ~(1<<RW);
  72.  
  73. PORTB |= (1<<E);
  74. PORTD = data;
  75. PORTB &=~(1<<E);
  76. _delay_us(120);
  77. }
  78.  
  79. void LCD2x16_pos(int wiersz, int kolumna)
  80. {
  81. PORTB &= ~(1<<RS);
  82. PORTB &= ~(1<<RW);
  83.  
  84. PORTB |= (1<<E);
  85. delay_ms(1);
  86. PORTD = 0x80+(wiersz-1)*0x40+(kolumna-1);
  87. delay_ms(1);
  88. PORTB &=~(1<<E);
  89. _delay_us(120);
  90. }
  91.  
  92.  
  93.  
  94. int main(void){
  95. char www[16] = "www-> are.net.pl";
  96. char email[16] = "biuro@are.net.pl";
  97. char tmp[16];
  98.  
  99. int i;
  100. int j=4;
  101.  
  102. DDRD = 0xff;
  103. PORTD = 0x00;
  104. DDRB = 0xff;
  105. PORTB = 0x00;
  106.  
  107. _delay_ms(200);
  108.  
  109. LCD2x16_init();
  110. LCD2x16_clear();
  111.  
  112.  
  113. for(i=0;i < 16;i++)
  114. LCD2x16_putchar(www[i]);
  115. LCD2x16_pos(2,1);
  116. for(i=0;i < 16;i++)
  117. LCD2x16_putchar(email[i]);
  118.  
  119. delay_ms(3000);
  120. LCD2x16_clear();
  121. for(i=0;i < 16;i++)
  122. LCD2x16_putchar(www[i]);
  123.  
  124. while(1)
  125. {
  126. //LCD2x16_clear();
  127. LCD2x16_pos(2,1);
  128. sprintf(tmp,"Dzialam juz %2is ",j);
  129. j++;
  130. for(i=0;i < 16;i++)
  131. LCD2x16_putchar(tmp[i]);
  132. delay_ms(1000);
  133. }
  134.  
  135. return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement