Advertisement
Guest User

super hiper kod

a guest
Apr 20th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. /*
  2. * AVRGCC1.c
  3. *
  4. * Created: 2018-04-05 13:32:26
  5. * Author: student
  6. */
  7.  
  8. #include <avr/io.h>
  9.  
  10. #define F_CPU 16000000UL
  11. #include <util/delay.h>
  12.  
  13. #include <lcd.h>
  14.  
  15. void lcd_reset()
  16. {
  17. COMM_LCD = 0x02;
  18. test_bf();
  19. }
  20.  
  21. void lcd_clear()
  22. {
  23. COMM_LCD = 0x01;
  24. test_bf();
  25. }
  26.  
  27. void lcd_init(void)
  28. {
  29. _delay_ms(20);
  30. COMM_LCD = 0x30;
  31. _delay_ms(5);
  32. COMM_LCD = 0x30;
  33. _delay_ms(1);
  34. COMM_LCD = 0x30;
  35. _delay_ms(30);
  36. COMM_LCD = 0x38;
  37. test_bf();
  38. COMM_LCD = 0x0C;
  39. test_bf();
  40. lcd_clear();
  41. COMM_LCD = 0x06;
  42. test_bf();
  43. lcd_reset();
  44. // clear charrow
  45. for (int i = 0; i < 64; i++) {
  46. COMM_LCD = 0x40 | i;
  47. test_bf();
  48. DATA_LCD = 0;
  49. test_bf();
  50. }
  51. }
  52.  
  53. void extram_init(void)
  54. {
  55. MCUCR = _BV(SRE) | _BV(SRW10);
  56. XMCRA = _BV(SRW00) | _BV(SRW01) | _BV(SRW11);
  57. }
  58.  
  59. void lcd_putc(uint8_t x, uint8_t y, char c)
  60. {
  61. COMM_LCD = 0x80 | (y << 6) | x;
  62. test_bf();
  63. DATA_LCD = c;
  64. test_bf();
  65. }
  66.  
  67. void lcd_charrow(uint8_t chr, int8_t y, uint8_t data) {
  68. COMM_LCD = 0x40 | (chr << 3) | (y + 1);
  69. test_bf();
  70. DATA_LCD = data;
  71. test_bf();
  72. }
  73.  
  74. void led_set(uint8_t pos, uint8_t status) {
  75. if (!status) {
  76. PORTB |= 1 << pos;
  77. } else {
  78. PORTB &= ~(1 << pos);
  79. }
  80. }
  81.  
  82. char to_hex(int v) {
  83. v = v & 0xF;
  84. if (v < 0xA) {
  85. return v + '0';
  86. } else {
  87. return v + 'A' - 10;
  88. }
  89. }
  90.  
  91. int main(void)
  92. {
  93. DDRD = 0x00;
  94. PORTD = 0xFF;
  95. DDRB = 0xFF;
  96. PORTB = 0xFF;
  97.  
  98. ADMUX = 0x42;
  99. ADCSRA = 0xE7;
  100.  
  101. extram_init();
  102. lcd_init();
  103.  
  104. for (uint8_t i = 0; i < 16; i++) {
  105. lcd_putc(i, 0, ' ');
  106. lcd_putc(i, 1, ' ');
  107. }
  108. const char* const str = "POMIAR=X.DV";
  109. for (size_t i = 0u; i < strlen(str); ++i)
  110. lcd_putc(i, 0, str[i]);
  111. uint8_t adcl = ADCL;
  112. uint16_t adc = ((ADCH & 0x03) << 8) | adcl;
  113.  
  114. uint16_t vin = (adc * 50) / 1023;
  115.  
  116. uint16_t hi = (vin / 10) % 10;
  117. uint16_t lo = vin % 10;
  118.  
  119. lcd_putc(7, 0, to_hex(hi));
  120. lcd_putc(9, 0, to_hex(lo));
  121. while(1) {
  122. if(PIND == 0b11111110){
  123. uint8_t adcl = ADCL;
  124. uint16_t adc = ((ADCH & 0x03) << 8) | adcl;
  125.  
  126. uint16_t vin = (adc * 50) / 1023;
  127.  
  128. uint16_t hi = (vin / 10) % 10;
  129. uint16_t lo = vin % 10;
  130.  
  131. lcd_putc(7, 0, to_hex(hi));
  132. lcd_putc(9, 0, to_hex(lo));
  133. }
  134.  
  135. //_delay_ms(25);
  136.  
  137. }
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement