Advertisement
Guest User

progarm

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