Advertisement
Guest User

Untitled

a guest
Apr 27th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. /*
  2. * AVRGCC1.c
  3. *
  4. * Created: 2018-04-27 08:43:39
  5. * Author: student
  6. */
  7.  
  8. #define F_CPU 16000000UL
  9.  
  10. #include <avr/io.h>
  11. #include <lcd.h>
  12.  
  13. void clear_lcd(){
  14. pisz_com(0b10000000);
  15. for(int i=0;i<16;i++){
  16. pisz_ws(' ');
  17. }
  18. pisz_com(0b11000000);
  19. for(int i=0;i<16;i++){
  20. pisz_ws(' ');
  21. }
  22. }
  23. void napisz_litere(char c){
  24. switch(c){
  25. case 0x3A: c = 'A'; break;
  26. case 0x3B: c = 'B'; break;
  27. case 0x3C: c = 'C'; break;
  28. case 0x3D: c = 'D'; break;
  29. case 0x3E: c = 'E'; break;
  30. case 0x3F: c = 'F'; break;
  31. }
  32. pisz_ws(c);
  33. }
  34. void napisz_napis(char * tekst){
  35. while(*tekst != '\0'){
  36. pisz_ws(*tekst);
  37. tekst++;
  38. }
  39. }
  40.  
  41. int main(void)
  42. {
  43. char* tekst = " Lab. 0-proc ";
  44. char byt;
  45. int stan = 0;
  46. int a = 255;
  47. int address = 0;
  48. int kroki = 0;
  49. int numbers[16];
  50. char byess[64];
  51. tekst[7] = 228;
  52. MCUCR = _BV(SRE) | MCUCR | _BV(SRW10) ;
  53. XMCRA = _BV(SRW00) | _BV(SRW01) | _BV(SRW11) | XMCRA;
  54.  
  55. DDRD = 0x00; // Wszystkie linie portu D będą wejściami
  56. PORTD = 0xFF;
  57. DDRE = 0xFF;
  58.  
  59. MMnet104_CONF = 0x13;
  60.  
  61. _delay_ms(20);
  62. COMM_LCD = 0x30;
  63. _delay_ms(5);
  64. COMM_LCD = 0x30;
  65. _delay_ms(1);
  66. COMM_LCD = 0x30;
  67. _delay_ms(20);
  68.  
  69. COMM_LCD = 0b00111000;
  70. _delay_ms(20);
  71. COMM_LCD = 0b00001100;
  72. _delay_ms(20);
  73. COMM_LCD = 0b00000001;
  74. _delay_ms(20);
  75. COMM_LCD = 0b00000110;
  76. _delay_ms(20);
  77. clear_lcd();
  78. pisz_com(0b10000000);
  79. clear_lcd();
  80.  
  81. while(1)
  82. {
  83. byt = iB_reset();
  84. clear_lcd();
  85. pisz_com(0b10000000);
  86. if (byt) {
  87. napisz_napis("Kod pastylki");
  88. if (stan % 2 == 0) PORTE |= _BV(1);
  89. else PORTE = PORTE & ~_BV(1);
  90. stan++;
  91. PORTE = PORTE & ~_BV(2);
  92. _delay_ms(500);
  93. }
  94. else {
  95. napisz_napis("Kod pastylki");
  96. PORTE = PORTE & ~_BV(1);
  97. PORTE |= _BV(2);
  98. {
  99. iB_send_bit(1);
  100. iB_send_bit(1);
  101. iB_send_bit(0);
  102. iB_send_bit(0);
  103. iB_send_bit(1);
  104. iB_send_bit(1);
  105. iB_send_bit(0);
  106. iB_send_bit(0);
  107. for(int i=0;i<64;i++){
  108. byess[i] = iB_recv();
  109. }
  110. a =3;
  111. pisz_com(0b11000000);
  112. for(int i=0;i<16;i++){
  113. numbers[i] = 1*byess[4*i]+ 2*byess[4*i+1] + 4*byess[4*i+2] + 8*byess[4*i+3];
  114. napisz_litere(numbers[i]+0x30);
  115. }
  116. }
  117. _delay_ms(3000);
  118. }
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement