123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- #include <avr/io.h>
- #include <util/delay.h>
- #include <avr/pgmspace.h>
- #include <string.h>
- #include "led.h"
- #include "1wire.h"
- //__attribute__ ((section (".noinit"))) unsigned char initst;
- __attribute__ ((section (".noinit"))) union {
- unsigned int t;
- struct {
- unsigned char l;
- unsigned char h;
- };
- } t;
- /*register unsigned char error asm("r3");
- inline void gettemp(void){
- //if(!owtimer){
- error = _1WireInit();
- if(error!=1) return;
- _1WireWriteByte(0xcc); //skip rom
- _1WireWriteByte(0xbe); //odczyt
- t.l = _1WireReadByte();
- t.h = _1WireReadByte();
- t.t *= (int)(0.625*16);
- t.t >>= 4;
- _1WireInit();
- _1WireWriteByte(0xcc); //skip rom
- _1WireWriteBytePR(0x44); //start
- // owtimer = xxx;
- //}
- }
- */
- void __jumpMain(void) __attribute__ ((naked)) __attribute__ ((section (".vectors")));
- void __jumpMain(void){
- asm volatile ( ".set __stack, %0" :: "i" (RAMEND) );
- SP = RAMEND;
- asm volatile ( "clr __zero_reg__" ); // r1 set to 0
- asm volatile ( "rjmp main" ); // jump to main()
- }
- unsigned char div(unsigned int a, unsigned int d){
- unsigned int x=0;
- while(a>d){
- a-=d;
- x++;
- }
- while(x>=10) x-=10;
- return x;
- }
- __attribute__ ((section (".noinit"))) unsigned char czuj[5][8];
- __attribute__ ((section (".noinit"))) unsigned char rom[8];
- void main(void) __attribute__((noreturn));
- void main(void){
- disp_init();
- register signed int temp;
- register signed int tt;
- unsigned char error;
- unsigned char li=0,x;
- unsigned char i=0, rv;
- for(;;){
- //gettemp();
- //_1WirePoweroff();
- error = _1WireInit();
- //if(error!=1) continue;
- //_1WireWriteByte(0xcc); //skip rom
- _1WireWriteByte(0x55);
- _1WireSendRom(czuj[li]);
- _1WireWriteByte(0xbe); //odczyt
- t.l = _1WireReadByte();
- t.h = _1WireReadByte();
- //tt = (t.t*(int)(0.625*16))>>4;
- tt = (signed int)((t.t<<3) + (t.t<<1)) >> 4;
- if(++li>i){
- li=0;
- i=0; rv=0;
- do {
- rv = _1WireSearch(rv, rom);
- for(x=0;x<8;x++) czuj[i][x] = rom[x];
- // memcpy(czuj[i], rom, 8);
- i++;
- } while(rv && i<5);
- i--;
- _1WireInit();
- _1WireWriteByte(0xcc); //skip rom
- _1WireWriteBytePR(0x44); //start
- }
- /*if(error!=1){
- putchar(14); //b
- putchar(11); //ł
- putchar(13); //a
- putchar(16); //d
- putchar(17);
- putchar(17);
- putchar(17);
-
- putchar(error);
- display();
- } else {*/
- //clear();
- /* putchar(14);
- putchar(14);
- putchar(14);*/
- if(error!=1){
- putchar(14);
- putchar(14);
- putchar(21);
- putchar(error);
- display();
- continue;
- }
- temp = tt;
- if(i){
- x = 16+li;
- // if(li==0) x=16;else x=17;
- } else x=14;
- putchar(x);
- if(temp < 0){
- putchar(15); //-
- temp = -temp;
- } else if(temp>1000) putchar(div(temp,1000)); else putchar(14);
- if(temp>100) putchar(div(temp,100)); else putchar(14);
- putchar(div(temp,10));
- putchar(12); //,
- putchar(div(temp,1));
- putchar(10); //°
- /*if(i){
- if(li) x=16; else x=17;
- } else x=10;
- putchar(x);*/
- putchar(13); //C
- display();
- _delay_ms(3000);
- // }
- }
- }
|