//***************************************************************************** // File Name : humisens.c // // Title : Humidity sensor // Revision : 1.0 // Notes : // Target MCU : Atmel AVR series, namely ATmega8 // Editor Tabs : 4 // // Revision History: // When Who Description of change // ----------- ----------- ----------------------- // 11-Apr-2008 Shaddack Created the program //***************************************************************************** /* (Shad's RS232 adapter: Rx=edge, Tx=center) .--------. /RST PC6 -| 1 28|- PC5 ADC5 SCL Rx PD0 -| 2 27|- PC4 ADC4 SDA Tx PD1 -| 3 26|- PC3 ADC3 INT0 PD2 -| 4 25|- PC2 ADC2 INT1 PD3 -| 5 24|- PC1 ADC1 XCK/T0 PD4 -| 6 23|- PC0 ADC0 Vcc -| 7 22|- GND GND -| 8 21|- ARef Xtal1 PB6 -| 9 20|- AVcc Xtal2 PB7 -|10 19|- PB5 SCK T1 PD5 -|11 18|- PB4 MISO AIN0 PD6 -|12 17|- PB3 MOSI OC2 AIN1 PD7 -|13 16|- PB2 /SS OC1B ICP1 PB0 -|14 15|- PB1 OC1A `--------' Fuse Low Byte = 0xef 1110-1111 Fuse High Byte = 0xd9 1100-1100 Fuse Extended Byte = 0xff ATmega8 .---------. Reset, Prog /RST PC6 -| 1 28|- PC5 ADC5 SCL Tx Rx PD0 -| 2 27|- PC4 ADC4 SDA Rx Tx PD1 -| 3 26|- PC3 ADC3 IOBUS-3 USB INT0 PD2 -| 4 25|- PC2 ADC2 IOBUS-2 USB INT1 PD3 -| 5 24|- PC1 ADC1 IOBUS-1 XCK/T0 PD4 -| 6 23|- PC0 ADC0 IOBUS-0 Vcc Vcc -| 7 22|- GND GND GND GND -| 8 21|- ARef XTAL Xtal1 PB6 -| 9 20|- AVcc XTAL Xtal2 PB7 -|10 19|- PB5 SCK Prog T1 PD5 -|11 18|- PB4 MISO Prog AIN0 PD6 -|12 17|- PB3 MOSI OC2 Prog AIN1 PD7 -|13 16|- PB2 /SS OC1B LIGHT-BUTTON LIGHT-OUT ICP1 PB0 -|14 15|- PB1 OC1A '---------' */ //----- Include Files --------------------------------------------------------- #include #include // include I/O definitions (port names, pin names, etc) //#include // include "signal" names (interrupt names) #include #include #include #include #include "global.h" // include our global settings //#include "crc8.h" //#include "crc8.c" #include "delay.h" #include "usbdrv.h" //#include "I2C.c" #include "../usb_commands.h" #define TIMER_CLK_STOP 0x00 ///< Timer Stopped #define TIMER_CLK_DIV1 0x01 ///< Timer clocked at F_CPU #define TIMER_CLK_DIV8 0x02 ///< Timer clocked at F_CPU/8 #define TIMER_CLK_DIV64 0x03 ///< Timer clocked at F_CPU/64 #define TIMER_CLK_DIV256 0x04 ///< Timer clocked at F_CPU/256 #define TIMER_CLK_DIV1024 0x05 ///< Timer clocked at F_CPU/1024 #define TIMER_CLK_T_FALL 0x06 ///< Timer clocked at T falling edge #define TIMER_CLK_T_RISE 0x07 ///< Timer clocked at T rising edge #define TIMER_PRESCALE_MASK 0x07 ///< Timer Prescaler Bit-Mask #define TICKS_PER_SECOND 10 // actually a little more than 10 but way less than 11 //----- Begin Code ------------------------------------------------------------ /* #define SHTPORT PORTD #define SHTPIN PIND #define SHTDDR DDRD #define SHTPORT_CLK 5 #define SHTPORT_DTA0 6 #define SHTPORT_DTA1 7 #define LCDPORT PORTB #define LCDPIN PINB #define LCDDDR DDRB #define LCDPIN_RS 4 #define LCDPIN_RW 5 #define LCDPIN_D7 3 #define LCDEPORT PORTC #define LCDEPIN PINC #define LCDEDDR DDRC #define LCDEPIN_E 0 */ //#define UART_BAUDRATE 19200 #define UART_BAUDRATE 9600 #define BAUDDIV ((F_CPU+(UART_BAUDRATE*8L))/(UART_BAUDRATE*16L)-1) /* #define SYMBOL_DEG 0xDF #define LCDPOS_TEMP 0 #define LCDPOS_HUMI 5 #define LCDPOS_TEMP2 11 #define LCDPOS_PRESS 10 #define LCDLINE_INSIDE 1 #define LCDLINE_OUTSIDE 0 */ volatile u08 tmr0; volatile u08 tmr1; volatile u08 tmroflow; volatile u08 rawdata[RAWDATA_LEN]; // memory array where all the crap is stored - raw sensor data, calculated results, averaged results #define var_light rawdata[OFFS_LIGHT] #define var_button rawdata[OFFS_BUTTON] #define var_button_debounce rawdata[OFFS_BUTTON_DEBOUNCE] #define var_portc rawdata[OFFS_PORTC] #define DEBOUNCE_COUNT 250 #define o(x) uartout(x) //--------------------------------------- // memory array functions void raw_storeint(u08 offs,u16 i) { rawdata[offs]=i>>8;rawdata[offs+1]=i; } void raw_storelong(u08 offs,long i) { rawdata[offs]=i>>24;rawdata[offs+1]=i>>16;rawdata[offs+2]=i>>8;rawdata[offs+3]=i; } int raw_getint(u08 offs) { return (rawdata[offs]<<8)|rawdata[offs+1]; } //int raw_getint_2(u08 offs) //{ return (rawdata[offs+1]<<8)|rawdata[offs]; //} long raw_getlong(u08 offs) { long l=0; u08 t; for(t=0;t<4;t++){l<<=8;l|=rawdata[offs+t];} return l; } void raw_inclong(u08 offs) { long l; l=raw_getlong(offs); l++; raw_storelong(offs,l); } void raw_incint(u08 offs) { u16 i; i=raw_getint(offs); i++; raw_storeint(offs,i); } u08 raw_decint(u08 offs) // return 1 if decremented to zero, return 0 if already zero or not decremented { u16 i; i=raw_getint(offs);if(!i)return 0; i--; raw_storeint(offs,i); if(i)return 0;return 1; } void raw_zerolong(u08 offs) { raw_storelong(offs,0x0L); } /* void raw_storeavglong(u08 offs,long val) { long l; u16 cnt; offs=offs*6;offs+=AVG_BASE; l=raw_getlong(offs); cnt=raw_getint(offs+4); l+=val; cnt++; raw_storelong(offs,l); raw_storeint(offs+4,cnt); } void raw_storeavgint(u08 offs,s16 i) { raw_storeavglong(offs,(long)i); } void raw_zeroavg() { u08 t; for(t=0;t<(6*4+6*2);t++)rawdata[AVG_BASE+t]=0; } void printout(u08 x,u08 y,u08 val); void printoutlcd(u08 x,u08 y,u08 val); u08 getdecdigit(long val,u08 digit,u08 showzero) { u08 t; // if(val<0)val=0-val; for(t=0;t>4);} void ohex(u08 t) { ohigh(t);olow(t);} void ohex16(u16 t) { ohex(t>>8);ohex(t);} #define ocrlf() o('\r');o('\n') void ostr(char*s) { while(s[0]){o(s[0]);s++;}} u08 getnybble(u08 c) { if((c&0x0F)<0x0a)return (c&0x0F)+'0';return (c&0x0F)+'A'-0x0a;} // ----------------------------------------- // LCD functions /* #define LCD_WRITECMD 0 #define LCD_WRITEDATA BV(LCDPIN_RS) #define LCD_READCMD BV(LCDPIN_RW) #define LCD_READDATA (BV(LCDPIN_RW)+BV(LCDPIN_RS)) #define LCD_SETWRITE LCDDDR=0xFF #define LCD_SETREAD LCDDDR=0xF0 #define LCD_INIT LCD_SETWRITE;LCDPORT=0xFF;LCDEDDR=0xFF;LCDEPORT=0xFE; #define LCD_PULSEON sbi(LCDEPORT,LCDEPIN_E) #define LCD_PULSEOFF cbi(LCDEPORT,LCDEPIN_E) #define LCD_PULSE LCD_PULSEON;LCD_PULSEOFF char lcd[LCDLINES+LINEBUFROWS][LCDLINELEN]; u08 lineptr=0; void lcd_initlines() { u08 t; for(t=2;t> 4) | ctrl; LCD_PULSE; LCDPORT=(data & 0x0F) | ctrl; LCD_PULSE; _delay_us(100); } void lcd_writec(u08 data) { lcd_write(data,LCD_WRITECMD);} void lcd_writed(u08 data) { lcd_write(data,LCD_WRITEDATA);} void lcdrefresh(u08 reset) { u08 t; if(reset) { LCD_INIT; lcd_writec( BV(5)+BV(3)+BV(2) ); // init mode lcd_writec(2); // home } lcd_writec( BV(3)+BV(2) ); // mode lcd_writec( BV(7) ); // goto address 0 for(t=0;t=LINEBUFROWS){lineptr=0;break;}} for(t=0;t60us } u08 onewire_read(void) { uint8_t result; sbi(DDR1w, IO1w); sbi(PORT1w, IO1w); cbi(PORT1w, IO1w); _delay_us(1); sbi(PORT1w, IO1w); cbi(DDR1w, IO1w); // get ready to read input _delay_us(5); // wait for thermo to respond (<15us) result = (PIN1w & (1<60us long return result; } void onewire_write_byte(u08 command) { u08 i; for (i = 0; i < 8; i++) { onewire_write(command & 1); command >>= 1; } } u08 onewire_read_byte(void) { u08 r,i; r = 0; for (i = 0; i < 8; i++) { r |= (onewire_read() << (i)); } return r; } void onewire_do_measurement(void) { onewire_reset(); onewire_write_byte(0xCC); // skip ROM command onewire_write_byte(0x44); // convert T } #define DS18_ERR_NO_SENSOR 1 #define DS18_ERR_BAD_CRC 2 #define DS18_MAX_ERRORS 5 void onewire_read_temp(void) { u08 scratchpad[9]; u08 i; u08 crc; long l; u16 val; for (i = 0; i < 9; i++) scratchpad[i] = 0; onewire_reset(); onewire_write_byte(0xCC); // skip ROM onewire_write_byte(0xBE); // read scratchpad for (i = 0; i < 9; i++) { scratchpad[i] = onewire_read_byte(); } rawdata[DS18_TEMP ]=scratchpad[0]; rawdata[DS18_TEMP+1]=scratchpad[1]; crc=crc8(scratchpad,9); rawdata[DS18_CRC]=crc; if((scratchpad[0]==scratchpad[1])&&(scratchpad[1]==scratchpad[2])&&(scratchpad[2]==scratchpad[3]) &&((scratchpad[0]==0)||(scratchpad[0]==0xff))){rawdata[DS18_ERR]=DS18_ERR_NO_SENSOR;} else if(crc){rawdata[DS18_ERR]=DS18_ERR_BAD_CRC;} else {rawdata[DS18_ERR]=0;} val=raw_getint_2(DS18_TEMP); if(val&0x8000)l=0-val;else l=val; l*=125;l>>=1; l/=10; //if((l>9999)|(rawdata[DS18_ERR]))l=9999; //if(val&0x8000)l=0-l; if(rawdata[DS18_ERR]){l=MAGIC_BADVAL;if(rawdata[DS18_ERR_CONSEC]=DS18_MAX_ERRORS))raw_storeint(VAR_TEMPD,l); // write result to buffer if no or three read errors if(!rawdata[DS18_ERR])raw_storeavglong(AVG_TEMPD,l); } void onewire_print() { printint(LCDPOS_TEMP2,LCDLINE_INSIDE,VAR_TEMPD,1,SYMBOL_DEG); } */ //------------------------------- // SHT15 sensor functions /* #define SHT_CLK0 cbi(SHTPORT,SHTPORT_CLK) #define SHT_CLK1 sbi(SHTPORT,SHTPORT_CLK) #define SHT_DTA0 sbi(SHTDDR,SHTPORT_DTA0);sbi(SHTDDR,SHTPORT_DTA1);cbi(SHTPORT,SHTPORT_DTA0);cbi(SHTPORT,SHTPORT_DTA1) #define SHT_DTA1 sbi(SHTDDR,SHTPORT_DTA0);sbi(SHTDDR,SHTPORT_DTA1);sbi(SHTPORT,SHTPORT_DTA0);sbi(SHTPORT,SHTPORT_DTA1) #define SHT_RDTA cbi(SHTDDR,SHTPORT_DTA0);sbi(SHTPORT,SHTPORT_DTA0);cbi(SHTDDR,SHTPORT_DTA1);sbi(SHTPORT,SHTPORT_DTA1) #define SHT_GETDTA0 (SHTPIN&BV(SHTPORT_DTA0)) #define SHT_GETDTA1 (SHTPIN&BV(SHTPORT_DTA1)) #define SHT_SENDSTART SHT_DTA1;SHT_CLK1;SHT_DTA1;SHT_DTA0;SHT_CLK0;SHT_CLK1;SHT_DTA1 #define SHT_SEND0 SHT_CLK0;SHT_DTA0;SHT_CLK1;SHT_CLK1 #define SHT_SEND1 SHT_CLK0;SHT_DTA1;SHT_CLK1;SHT_CLK1 #define SHT_SENDREAD SHT_CLK0;SHT_RDTA;SHT_CLK1;SHT_CLK1 u08 shtTimeOut; u08 sht15_isready() { if(SHT_GETDTA0)return 0; if(SHT_GETDTA1)return 0; return 1; } void sht15_init(u08 therm) { SHT_SENDSTART; SHT_DTA1;SHT_DTA1;SHT_DTA1; SHT_SEND0;SHT_SEND0;SHT_SEND0;SHT_SEND0;SHT_SEND0; if(therm){SHT_SEND0;SHT_SEND1;} // temperature else{SHT_SEND1;SHT_SEND0;} // humidity SHT_SEND1; SHT_SENDREAD; SHT_CLK0;SHT_CLK0;SHT_CLK0;SHT_CLK0;SHT_CLK0;SHT_CLK0; } u08 sht15_iserror(u08 addr) { u08 t; t=rawdata[addr]&rawdata[addr+1]; if(t==0xFF)return 1; if(t==0x7F)if(rawdata[addr+2]==0x7F)return 1; return 0; } u08 sht15_getrawaddr(u08 therm,u08 sensor) { if(sensor)sensor=SHT1_BASE;else sensor=SHT0_BASE; if(therm)sensor+=SHT_TEMP_OFFS;else sensor+=SHT_HUMI_OFFS; return sensor; } void sht15_getbyte(u08 addr) { u08 t; u08 ShiftReg0,ShiftReg1; ShiftReg0=0;ShiftReg1=0; for(t=0;t<8;t++){SHT_SENDREAD; ShiftReg0<<=1;ShiftReg1<<=1; if(SHT_GETDTA0)ShiftReg0|=1; if(SHT_GETDTA1)ShiftReg1|=1;} SHT_SEND0; rawdata[SHT0_BASE+addr]=ShiftReg0; rawdata[SHT1_BASE+addr]=ShiftReg1; } void sht15_readvalues(u08 therm) { int val; u08 sens,addr,err; long l,ll; if(therm)addr=SHT_TEMP_OFFS;else addr=SHT_HUMI_OFFS; sht15_getbyte(addr); sht15_getbyte(addr+1); sht15_getbyte(addr+2); for(sens=0;sens<2;sens++){ if(sens)addr=SHT1_BASE;else addr=SHT0_BASE; if(therm)addr+=SHT_TEMP_OFFS;else addr+=SHT_HUMI_OFFS; val=raw_getint(addr); err=sht15_iserror(addr); if(therm) {val-=4000; // fixed decimal point, -40.00 if(err)val=MAGIC_BADVAL; else raw_storeavgint(AVG_TEMP0+(sens<<1),val); raw_storeint(VAR_TEMP0+(sens<<2),val); } else {l=(long)val;l*=367;l-=20468; ll=(long)val;ll*=ll;ll*=16;ll/=1000; //(ll=val*val*16/1000) l-=ll; // linear humidity: RHlin = -2.0468 + 0.0367*val - 0.0000015955*val*val ll=(long)val;ll*=8;ll+=1000; ll*=((long)raw_getint(VAR_TEMP0+(sens<<2))-2500); ll/=1000; l+=ll; // temp-compensated humidity: RHreal = (temp - 25) * (0.01 + 0.00008*val) + RHlin val=l/100; // fixed decimal at 1=0.01 if(val>9900)val=9999; if(err)val=MAGIC_BADVAL; else raw_storeavgint(AVG_HUMI0+(sens<<1),val); raw_storeint(VAR_HUMI0+(sens<<2),val); } } } void sht15_printvalues(u08 therm) { u08 sens,x,row,addr,addr2,c; for(sens=0;sens<2;sens++) { addr=sht15_getrawaddr(therm,sens); if(sens==0)row=LCDLINE_INSIDE;else row=LCDLINE_OUTSIDE; if(therm){x=LCDPOS_TEMP;c=SYMBOL_DEG;}else{x=LCDPOS_HUMI;c='%';} addr2=VAR_TEMP0;addr2+=sens<<2;addr2+=(1-therm)<<1; printint(x,row,addr2,0,c); } } */ //-------------------------------------- // SCP1000-D11 I2C sensor functions /* #define I2CADDR_SCP1000 0x22 void SCP1000_setup(u08 force) { if( (force) || (raw_getlong(VAR_PRES)==16385) || (rawdata[SCP_I2CSTATE]!=I2C_RESULT_OK) ) i2cclkWriteByte(I2CADDR_SCP1000&0xFE,0x03,0x0a); } //ballpark output: 06 13 74 02 56 void SCP1000_get_pressure() { long pres; int temp; i2cclkReadBlock(I2CADDR_SCP1000&0xFE, 0x7F, 5, (char*)rawdata+SCP_BASE); rawdata[SCP_I2CSTATE]=i2cstate; pres =rawdata[SCP_PRES+0];pres<<=8; pres|=rawdata[SCP_PRES+1];pres<<=8; pres|=rawdata[SCP_PRES+2]; pres+=4;//rounding pres>>=2; temp=(rawdata[SCP_TEMP]<<8)|rawdata[SCP_TEMP+1]; temp<<=2; if(i2cstate!=I2C_RESULT_OK){pres=MAGIC_BADVAL;temp=MAGIC_BADVAL;} raw_storeint(VAR_TEMPP,temp); if(pres<150000L) // skip storing value when out of range - indicates faulty reading {raw_storelong(VAR_PRES,pres); if(pres>60000L)raw_storeavglong(AVG_PRES,pres);} } void SCP1000_print() { printlong(LCDPOS_PRESS,LCDLINE_OUTSIDE,VAR_PRES); } */ //------------------------------------------ // USB functions //u08 light=0; void light_on() { if(!var_light){raw_zerolong(OFFS_STATE);raw_inclong(OFFS_CHANGECOUNT);} var_light=1; cbi(PORTB,0); // inverted output } void light_off() { if(var_light){raw_zerolong(OFFS_STATE);raw_inclong(OFFS_CHANGECOUNT);} var_light=0; sbi(PORTB,0); raw_storeint(OFFS_OFFTIMER,0); // reset OFF timer } void light_toggle() { if(var_light)light_off();else light_on(); } u08 read_button() { if(!(PINB&BV(2)))return 1; if(!(PINC&BV(0)))return 1; return 0; } void button_release() { light_toggle(); } void set_poweroff_autotimeout() { u16 i; if(var_light)i=raw_getint(OFFS_TIMERDELAY_ON); else i=raw_getint(OFFS_TIMERDELAY_OFF); raw_storeint(OFFS_OFFTIMER,i); } void button_handle() { u08 b; static u08 suppress_release=0; u16 i; b=read_button(); i=raw_getint(OFFS_BUTTON); if(b){if(var_button_debounceraw_getint(OFFS_PRESSLEN)){if(!suppress_release)set_poweroff_autotimeout(); if(!var_light)light_on(); suppress_release=1;}} else{if(var_button_debounce==DEBOUNCE_COUNT){if(!suppress_release){button_release();raw_storeint(OFFS_OFFTIMER,0);}} var_button_debounce=0; suppress_release=0; raw_storeint(OFFS_BUTTON,0);} // if(read_button())light_on();else light_off(); } void counters_add() { long l; long i; raw_inclong(OFFS_RUNTIME); raw_inclong(OFFS_STATE); if(read_button())raw_incint(OFFS_BUTTON); if(var_light){ if(raw_decint(OFFS_OFFTIMER))light_off(); // auto-off for short times i=raw_getlong(OFFS_MAXONTIMER); l=raw_getlong(OFFS_STATE); if(i>0)if(l>i)light_off();// auto-off for long times } } USB_PUBLIC uchar usbFunctionSetup(uchar data[8]) { usbRequest_t *rq = (void *)data; static uchar replyBuf[8]; u08 t,addr; usbMsgPtr = replyBuf; if(rq->bRequest == PSCMD_ECHO){ replyBuf[0] = rq->wValue.bytes[0]; replyBuf[1] = rq->wValue.bytes[1]; return 2; } if(rq->bRequest == PSCMD_READRAW){ addr=rq->wIndex.word;if(addr>RAWDATA_LEN-4)addr=RAWDATA_LEN-4; for(t=0;t<4;t++)replyBuf[t]=rawdata[addr+t]; return 4; } if(rq->bRequest == PSCMD_WRITEWORD){ addr=rq->wIndex.word; if(addr>RAWDATA_LEN-1)return 0; if(addrwValue.bytes[0]; rawdata[addr+1]=rq->wValue.bytes[1]; return 1; } if(rq->bRequest == PSCMD_LIGHTON){ light_on(); replyBuf[0]=var_light; return 1; } if(rq->bRequest == PSCMD_LIGHTOFF){ light_off(); replyBuf[0]=var_light; return 1; } if(rq->bRequest == PSCMD_LIGHTTOGGLE){ light_toggle(); replyBuf[0]=var_light; return 1; } if(rq->bRequest == PSCMD_LIGHTSTATUS){ replyBuf[0]=var_light; return 1; } /* if(rq->bRequest == PSCMD_READRAW6){ //addr=rq->wIndex.word;if(addr>RAWDATA_LEN-6)addr=RAWDATA_LEN-6; //for(t=0;t<6;t++)replyBuf[t]=rawdata[addr+t]; return 6; } if(rq->bRequest == PSCMD_STATUS){ replyBuf[0]=PINB; replyBuf[1]=oper; replyBuf[2]=pos; replyBuf[3]=close_attempts; replyBuf[4]=button_counter>>8; replyBuf[5]=button_counter; return 6; } if(rq->bRequest == PSCMD_TRAY_OPEN){ tmr0=0; oper=OPER_OUT; replyBuf[0]=1; return 1; } if(rq->bRequest == PSCMD_TRAY_CLOSE){ tmr0=0; oper=OPER_IN; replyBuf[0]=1; return 1; } if(rq->bRequest == PSCMD_TRAY_INIT){ tmr0=0; oper=OPER_INIT; replyBuf[0]=1; return 1; } if(rq->bRequest == MSG_CLEAR){ msgptr=0;while(msgptrbRequest == MSG_SENDBYTE){ msgbuf[msgptr]=rq->wValue.bytes[0]; if(msgptrwValue.bytes[0]); //ocrlf(); return 0; } if(rq->bRequest == MSG_GETCRC){ u08 crc; crc=calculatecrc((u08*)msgbuf,msgptr); replyBuf[0] = crc; //ostr("CRC="); //ohex(crc); //ocrlf(); return 1; } if(rq->bRequest == MSG_COMMIT){ //u08 t; //ostr("MSG="); //for(t=0;t>8); UCSRB=BV(RXEN)|BV(TXEN); UCSRC=(BV(URSEL))|(3< 500 ms */ wdt_reset(); _delay_ms(2); } usbDeviceConnect(); usbInit(); // lcd_initlines(); // SCP1000_setup(1);//TODO: init when something wrong detected, or periodically loopcnt = 1; // raw_zeroavg(); light_off(); raw_storeint(OFFS_TIMERDELAY_ON,250); // delayed power-off raw_storeint(OFFS_TIMERDELAY_OFF,250); // temporary power-on raw_storeint(OFFS_PRESSLEN,6); // length of long power-on button press raw_storelong(OFFS_MAXONTIMER,108000L); // length of long power-on button press, a bit below 3 hours for(;;){ wdt_reset(); usbPoll(); button_handle(); var_portc=PINC; switch(state){ case 0: //ostr("HT1;"); state++;break; case 1: waitto=tmr0+5; // delay up to 255 Tmr0 cycles state++;break; case 2: if(tmr0!=waitto)break; //light_toggle(); counters_add(); state++;break; /* case 1: sht15_init(loopcnt&1);waitto=tmr0+25;shtTimeOut=0; state++;break; case 2: if(sht15_isready()){state++;break;} if(waitto==tmr0){shtTimeOut=1;state++;} break; case 3: sht15_readvalues(loopcnt&1); sht15_printvalues(loopcnt&1); state++;break; case 4: SCP1000_get_pressure(); SCP1000_print(); state++;break; case 5: onewire_read_temp(); onewire_print(); state++;break; case 6: ocrlf(); onewire_do_measurement(); state++;break; case 7: for(t=0;t<16;t++)o(lcd[0][t]);ocrlf(); state++;break; case 8: for(t=0;t<16;t++)o(lcd[1][t]);ocrlf(); state++;break; case 9: lcdrefresh(tmroflow);tmroflow=0; state++;break; case 10:waitto=tmr0+60; // delay up to 255 Tmr0 cycles if((loopcnt&0x07)==0)SCP1000_setup(0); state++;break; case 11:if(tmr0!=waitto)break; state++;break; */ default: loopcnt++;state=0; } } return 0; } SIGNAL(SIG_OVERFLOW0) { tmr0++; if(!tmr0){tmr1++;tmroflow=1;} } UART_INTERRUPT_HANDLER(SIG_UART_RECV) { // u08 c; // c = inb(UDR); // get received char } UART_INTERRUPT_HANDLER(SIG_UART_TRANS) { // recvchar='x'; }