main.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #include <avr/io.h>
  2. #include <util/delay.h>
  3. #include <avr/pgmspace.h>
  4. #include <string.h>
  5. #include "led.h"
  6. #include "1wire.h"
  7. //__attribute__ ((section (".noinit"))) unsigned char initst;
  8. __attribute__ ((section (".noinit"))) union {
  9. unsigned int t;
  10. struct {
  11. unsigned char l;
  12. unsigned char h;
  13. };
  14. } t;
  15. /*register unsigned char error asm("r3");
  16. inline void gettemp(void){
  17. //if(!owtimer){
  18. error = _1WireInit();
  19. if(error!=1) return;
  20. _1WireWriteByte(0xcc); //skip rom
  21. _1WireWriteByte(0xbe); //odczyt
  22. t.l = _1WireReadByte();
  23. t.h = _1WireReadByte();
  24. t.t *= (int)(0.625*16);
  25. t.t >>= 4;
  26. _1WireInit();
  27. _1WireWriteByte(0xcc); //skip rom
  28. _1WireWriteBytePR(0x44); //start
  29. // owtimer = xxx;
  30. //}
  31. }
  32. */
  33. void __jumpMain(void) __attribute__ ((naked)) __attribute__ ((section (".vectors")));
  34. void __jumpMain(void){
  35. asm volatile ( ".set __stack, %0" :: "i" (RAMEND) );
  36. SP = RAMEND;
  37. asm volatile ( "clr __zero_reg__" ); // r1 set to 0
  38. asm volatile ( "rjmp main" ); // jump to main()
  39. }
  40. unsigned char div(unsigned int a, unsigned int d){
  41. unsigned int x=0;
  42. while(a>d){
  43. a-=d;
  44. x++;
  45. }
  46. while(x>=10) x-=10;
  47. return x;
  48. }
  49. __attribute__ ((section (".noinit"))) unsigned char czuj[5][8];
  50. __attribute__ ((section (".noinit"))) unsigned char rom[8];
  51. void main(void) __attribute__((noreturn));
  52. void main(void){
  53. disp_init();
  54. register signed int temp;
  55. register signed int tt;
  56. unsigned char error;
  57. unsigned char li=0,x;
  58. unsigned char i=0, rv;
  59. for(;;){
  60. //gettemp();
  61. //_1WirePoweroff();
  62. error = _1WireInit();
  63. //if(error!=1) continue;
  64. //_1WireWriteByte(0xcc); //skip rom
  65. _1WireWriteByte(0x55);
  66. _1WireSendRom(czuj[li]);
  67. _1WireWriteByte(0xbe); //odczyt
  68. t.l = _1WireReadByte();
  69. t.h = _1WireReadByte();
  70. //tt = (t.t*(int)(0.625*16))>>4;
  71. tt = (signed int)((t.t<<3) + (t.t<<1)) >> 4;
  72. if(++li>i){
  73. li=0;
  74. i=0; rv=0;
  75. do {
  76. rv = _1WireSearch(rv, rom);
  77. for(x=0;x<8;x++) czuj[i][x] = rom[x];
  78. // memcpy(czuj[i], rom, 8);
  79. i++;
  80. } while(rv && i<5);
  81. i--;
  82. _1WireInit();
  83. _1WireWriteByte(0xcc); //skip rom
  84. _1WireWriteBytePR(0x44); //start
  85. }
  86. /*if(error!=1){
  87. putchar(14); //b
  88. putchar(11); //ł
  89. putchar(13); //a
  90. putchar(16); //d
  91. putchar(17);
  92. putchar(17);
  93. putchar(17);
  94. putchar(error);
  95. display();
  96. } else {*/
  97. //clear();
  98. /* putchar(14);
  99. putchar(14);
  100. putchar(14);*/
  101. if(error!=1){
  102. putchar(14);
  103. putchar(14);
  104. putchar(21);
  105. putchar(error);
  106. display();
  107. continue;
  108. }
  109. temp = tt;
  110. if(i){
  111. x = 16+li;
  112. // if(li==0) x=16;else x=17;
  113. } else x=14;
  114. putchar(x);
  115. if(temp < 0){
  116. putchar(15); //-
  117. temp = -temp;
  118. } else if(temp>1000) putchar(div(temp,1000)); else putchar(14);
  119. if(temp>100) putchar(div(temp,100)); else putchar(14);
  120. putchar(div(temp,10));
  121. putchar(12); //,
  122. putchar(div(temp,1));
  123. putchar(10); //°
  124. /*if(i){
  125. if(li) x=16; else x=17;
  126. } else x=10;
  127. putchar(x);*/
  128. putchar(13); //C
  129. display();
  130. _delay_ms(3000);
  131. // }
  132. }
  133. }