Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. #include <avr/io.h>
  2.  
  3. #include <lcd.h>
  4.  
  5. #ifndef __PGMSPACE_H_
  6. # include <avr/pgmspace.h>
  7. #endif
  8. // Zerowanie wyświetlacza
  9. void
  10. lcd_clear(void);
  11. // Przesunięcie kursora
  12. void
  13. lcd_home(void);
  14. // Inicjalizacja wyświetlacza 5x7, 2 wiersze
  15. void
  16. init_lcd(void);
  17. // Przepisanie tekstu (koniec = 0xFF) z pamięci programu na wyświetlacz
  18. // Funkcja dopuszcza wykorzystanie znaku o kodzie 0x00
  19. // _adres - adres tekstu w pam. FLASH
  20. void
  21. disp_txt_P(const char* _adres);
  22. // Przepisanie tekstu (koniec = 0x00) z pamięci danych na wyświetlacz
  23. // _adres - adres tekstu w pam. RAM
  24. void
  25. disp_txt_D(char* _adres);
  26. //Implementacja
  27. void
  28. lcd_clear(void)
  29. {
  30. pisz_com(0x01);
  31. }
  32. void
  33. lcd_home(void)
  34. {
  35. pisz_com(0x02);
  36. }
  37. void
  38. init_lcd(void)
  39. {
  40. MCUCR = _BV(SRE) |_BV(SRW10);
  41. XMCRA = _BV(SRW00) |_BV(SRW01) |_BV(SRW11);
  42. MMnet104_CONF = 0b00010011;
  43. _delay_ms(15);
  44. COMM_LCD = 0x30;
  45. _delay_ms(5);
  46. COMM_LCD = 0x30;
  47. _delay_ms(0.2);
  48. COMM_LCD = 0x30;
  49. _delay_ms(30);
  50. COMM_LCD = 0x38; //Słowo danych 8-bitów, dwa wiersze, znak 7x5
  51. //pikseli
  52. test_bf();
  53. pisz_com(0x0C); //Włączenie wyświetlacza, bez kursora, bez
  54. //migotania
  55. lcd_clear();
  56. pisz_com(0x06); //Wpisywanie znaków od lewej, autoinkrementacja
  57. lcd_home();
  58. }
  59. void
  60. disp_txt_P(const char* _adres)
  61. {
  62. volatile uint8_t al;
  63. for (int i = 0; i<16; i++)
  64. {
  65. al = pgm_read_byte(&_adres[i]);
  66. if (al == 0xFF) break;
  67. pisz_ws(al);
  68. }
  69. }
  70. void
  71. disp_txt_D(char* _adres)
  72. {
  73. volatile uint8_t al;
  74. for (int i = 0; i<16; i++)
  75. {
  76. al = _adres[i];
  77. if (al == 0x00) break;
  78. pisz_ws(al);
  79. }
  80. }
  81.  
  82. uint16_t read_adc(){
  83. ADCSRA |= _BV(ADIF);
  84. ADCSRA |= _BV(ADSC);
  85. while(!(ADCSRA * _BV(ADIF)));
  86.  
  87. volatile uint8_t c = ADCL;
  88. return ADCH << 8 | c;
  89. }
  90.  
  91. int main(void)
  92. {
  93.  
  94. init_lcd();
  95. lcd_home();
  96. ADMUX = 0b01000011;
  97. ADCSRA = 0b10001111;
  98.  
  99. char w[16] = {};
  100. char t[16] = {};
  101.  
  102. while(1)
  103. {
  104. lcd_clear();
  105. uint16_t v = read_adc();
  106. sprintf(w,"ADC=%x", v);
  107. disp_txt_D(w);
  108. float c = v * (float)5/ (float)1024 * 10;
  109. sprintf(t,"Vin=%d.%dV", (int)c/10, (int)c%10);
  110. pisz_com(0xc2);
  111. disp_txt_D(t);
  112. _delay_ms(200);
  113. //TODO:: Please write your application code
  114. }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement