Ejemplo n.º 1
0
__interrupt void Timer0_A0(void) {
	switch (__even_in_range(TA0IV, 6)) {
	case TA0IV_NONE: {                         		// TA0CCR0
		P1OUT &= ~(CONTROL); // relais on bis
		if (i++ == 0) { // start reading
			onewire_reset(&ow);
			onewire_write_byte(&ow, 0xcc); // skip ROM command
			onewire_write_byte(&ow, 0x44); // convert T command
			onewire_line_high(&ow);
		}
		if (i >= 14) { // read values 16
			onewire_reset(&ow);
			onewire_write_byte(&ow, 0xcc); // skip ROM command
			onewire_write_byte(&ow, 0xbe); // read scratchpad command
			for (i = 0; i < 9; i++)
				scratchpad[i] = onewire_read_byte(&ow);
			temp = ((scratchpad[1] << 8) + scratchpad[0]) * 0.0625;
			// temp control
			if (temp < 32 & TA0CCR1 < 48000) { // increase pwm
			//TA0CCR1 = TA0CCR1 +1000;
			}
			if (temp > 32 & TA0CCR1 > 1000) { // decrease pwm
			//TA0CCR1 = TA0CCR1 -1000;
			}
			i = 0;
		}
		break;
	}
	case TA0IV_TACCR1: {		                        // TA0CCR1
		P1OUT |= CONTROL; // relais off
		break;
	}
	case TA0IV_TACCR2:                                 // TA0CCR2
	{
		break;
	}
	case 6:
		break;                          // TA0CCR3
	default:
		break;
	}
}
Ejemplo n.º 2
0
int main()
{
  onewire_t ow;
  int i;
  uint8_t scratchpad[9];
  uint8_t id[8];
 
  WDTCTL = WDTPW + WDTHOLD; //Stop watchdog timer
  BCSCTL1 = CALBC1_8MHZ;
  DCOCTL = CALDCO_8MHZ;
  uart_setup();
 
  ow.port_out = &P1OUT;
  ow.port_in = &P1IN;
  ow.port_ren = &P1REN;
  ow.port_dir = &P1DIR;
  ow.pin = BIT7;

  printf("start\n");
  search(&ow, id, 0, 1);
  printf("done\n");
 
  onewire_reset(&ow);
  onewire_write_byte(&ow, 0xcc); // skip ROM command
  onewire_write_byte(&ow, 0x44); // convert T command
  onewire_line_high(&ow);
//  DELAY_MS(850); // at least 750 ms for the default 12-bit resolution
// while __delay_cycles(>100000) give the __delay_cycles max value error:
for (i = 0; i < 65; i++) __delay_cycles(100000);

  onewire_reset(&ow);
  onewire_write_byte(&ow, 0xcc); // skip ROM command
  onewire_write_byte(&ow, 0xbe); // read scratchpad command
  for (i = 0; i < 9; i++) scratchpad[i] = onewire_read_byte(&ow);
  for (i = 0; i < 9; i++) printf("%02x", scratchpad[i]);
  //meas = scratchpad[0];  // LSB
  //meas |= ( (uint16_t)scratchpad[1] ) << 8; // MSB
  int j=0;
        uint16_t temp = 0;
        for(j = 16; j > 0; i--){
                temp >>= 1;
                if (onewire_read_bit(&ow)) {
                        temp |= 0x8000;
                }
	}
  if(temp<0x8000){
        return(temp*0.0625);
    }
    else
    {
        temp=(~temp)+1;
        return(temp*0.0625);
    }

  printf("%02x\n", temp);
  printf("%02x\n", scratchpad[2]);
  printf("%02x°C\n");
 
  _BIS_SR(LPM0_bits + GIE);
  return 0;
}