Пример #1
0
int main(void) {
//	uint16_t i;

	// one wire initialization
	static OneWireDriver owDrv;
	static const OneWireConfig owCfg = { .dqPort = GPIOB,
	                                     .dqPad =  10,
	                                     .dqAlternate = 7,
	                                     .uartd = &UARTD3 };
	static OneWireRomAddress romAddr[8];
	static bool_t searched = FALSE;
	static bool_t initialized = FALSE;
	
	

	// Initialize the uGFX and the underlying system
	gfxInit();

	// Lock screen 	
uint8_t secret_sequence[UNLOCKER_COLS * UNLOCKER_ROWS];
  displayUnlockerSetup(secret_sequence);
 	displayUnlocker(secret_sequence);
	
	// Set the widget defaults
	gwinSetDefaultFont(gdispOpenFont("UI2"));
	gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE);
	gdispClear(Black);
 
	// Create the widget
	createWidgets();
 
	// Print to the console
	gwinPrintf(ghConsole, "Witamy w konsoli!\r\n\n");
	gwinPrintf(ghConsole, "Odczyt temp z czujnikow DS18B20.\r\n");
	//initialize ds18b20	
	if (initialized == FALSE) {
	    oneWireInit(&owDrv, &owCfg);
	    initialized = TRUE;
	}

	if (searched == FALSE) {
      		oneWireSearchRom (&owDrv, FALSE, romAddr, ARRAY_LEN(romAddr));
      		searched = TRUE;
	}
	while (1) {	oneWireSearchRom (&owDrv, FALSE, romAddr, ARRAY_LEN(romAddr));

	   	for (uint8_t i=0; i< ARRAY_LEN(romAddr); i++) {
			if (romAddr[i].addr[0] == 0x28) {
		  		ds1820BInit (&owDrv, &(romAddr[i]), 10);
		 		const float temp =ds1820BGetTemp (&owDrv, &(romAddr[i]));
				gwinPrintf(ghConsole, "czujnik %d temp =%.2f\r\n", i, temp);      	
				}
		}
	 
		gfxSleepMilliseconds(800);
	}
	 
	return 0;
}
Пример #2
0
void init_ATtiny85()
{

	uint8_t i;
	char buffer[5];
	CounterLoops = 0;

	DDRB |= _BV(LEDPIN);				// Set the LED pin to output mode

	// Setup timer interrupts
	TCCR0B |= (_BV(CS02) | _BV(CS00));	// Prescale timer0 to /1024 of the cpu clock (976.6 Hz)
	TCCR0A |= _BV(WGM01);				// Set "clear timer on compare match (CTC)" mode
	TIMSK |= _BV(OCIE0A);				// Enable interrupt for Timer/Counter Output Compare Match A


	usi_twi_master_initialize();		// Initialize the TWI interface
	mcp23008_Init(MCP23008_ADDR_LCD);	// Initialize the mcp23008 port expander

	LCD_init(MCP23008_ADDR_LCD);		// Initialize the LCD
	LCD_backlight(MCP23008_ADDR_LCD, 1);
	LCD_writeStr(MCP23008_ADDR_LCD, "20131123");

	oneWireInit();								// Initialize the OneWire net
	oneWireReadRom((uint8_t*) ds18b20addr);	// Get the address of the DS18B20

	// Write the address of the only DS18B20 device on the onewire net
	LCD_clear(MCP23008_ADDR_LCD);
	LCD_gotoLine(MCP23008_ADDR_LCD, 1);
	for (i = 0; i < 4; i++) {
		sprintf(buffer, "%02X", ds18b20addr[i]);
		LCD_writeStr(MCP23008_ADDR_LCD, buffer);
	}
	LCD_gotoLine(MCP23008_ADDR_LCD, 2);
	for (i = 4; i < 8; i++) {
		sprintf(buffer, "%02X", ds18b20addr[i]);
		LCD_writeStr(MCP23008_ADDR_LCD, buffer);
	}
	_delay_ms(2000);

}