예제 #1
0
void twi_init_slave(uint8_t address)
{
  twi_setAddress(address);
  twi_attachSlaveTxEvent(onRequestService);
  twi_attachSlaveRxEvent(onReceiveService);
  twi_init_master();
}
예제 #2
0
파일: main.c 프로젝트: akafugu/ds_rtc_lib
void main(void)
{
	struct tm* t = NULL;
	char buf[32];
	uint8_t hour, min, sec;

	uartInit();
	uartSetBaudRate(9600);
	uartSendString("DS RTC Library Test\n");

	LED_DDR  |= _BV(LED_BIT); // indicator led

	for (int i = 0; i < 5; i++) {
		LED_HIGH;
		_delay_ms(100);
		LED_LOW;
		_delay_ms(100);
	}

	uartSendString("Before Init\n");
	twi_init_master();
	rtc_init();
	rtc_set_time_s(12, 0, 50);

	uartSendString("After Init\n");
	if (rtc_is_ds1307())
		uartSendString("DS1307\n");
	else
		uartSendString("DS3231\n");

	rtc_set_alarm_s(12, 1, 0);
	
	rtc_get_alarm_s(&hour, &min, &sec);

	sprintf(buf, "Alarm is set -%d:%d:%d-\n", hour, min, sec);
	uartSendString(buf);	
	uartSendString("---\n");
	uartSendString("---\n");
	uartSendString("---\n");

	while (1) {
		t = rtc_get_time();

		sprintf(buf, "%d:%d:%d\n", t->hour, t->min, t->sec);
		uartSendString(buf);
		uartSendString("---\n");

		if (rtc_check_alarm())
			uartSendString("ALARM!\n");

	   	_delay_ms(500);
	}
}
예제 #3
0
void initialize(void)
{
    // read eeprom
    g_24h_clock  = eeprom_read_byte(&b_24h_clock);
    g_show_temp  = eeprom_read_byte(&b_show_temp);
    g_brightness = eeprom_read_byte(&b_brightness);
    g_volume     = eeprom_read_byte(&b_volume);

    PIEZO_DDR |= _BV(PIEZO_LOW_BIT);
    PIEZO_DDR |= _BV(PIEZO_HIGH_BIT);

    PIEZO_LOW_OFF;
    PIEZO_HIGH_OFF;

    // Set buttons as inputs
    BUTTON_DDR &= ~(_BV(BUTTON1_BIT));
    BUTTON_DDR &= ~(_BV(BUTTON2_BIT));
    SWITCH_DDR  &= ~(_BV(SWITCH_BIT));

    // Enable pullups for buttons
    BUTTON_PORT |= _BV(BUTTON1_BIT);
    BUTTON_PORT |= _BV(BUTTON2_BIT);
    SWITCH_PORT |= _BV(SWITCH_BIT);

    LED_DDR  |= _BV(LED_BIT); // indicator led

    for (int i = 0; i < 5; i++) {
        LED_HIGH;
        _delay_ms(100);
        LED_LOW;
        _delay_ms(100);
    }

    sei();
    twi_init_master();

    rtc_init();
    rtc_set_ds1307();

    //rtc_set_time_s(16, 59, 50);
    //rtc_set_alarm_s(17,0,0);

    display_init(g_brightness);

    g_alarm_switch = get_alarm_switch();

    // set up interrupt for alarm switch
    PCICR |= (1 << PCIE2);
    PCMSK2 |= (1 << PCINT18);
}
예제 #4
0
// All initialization functions for peripherals should be placed here.
void init_modules() {
	uart_init();
	motor_init();
	pid_init();
	twi_init_master();
}
예제 #5
0
void initialize(void)
{

    PIEZO_DDR |= _BV(PIEZO_LOW_BIT);
    PIEZO_DDR |= _BV(PIEZO_HIGH_BIT);

    PIEZO_LOW_OFF;
    PIEZO_HIGH_OFF;

    // Set buttons as inputs
    BUTTON_DDR &= ~(_BV(BUTTON1_BIT));
    BUTTON_DDR &= ~(_BV(BUTTON2_BIT));
    SWITCH_DDR  &= ~(_BV(SWITCH_BIT));

    // Enable pullups for buttons
    BUTTON_PORT |= _BV(BUTTON1_BIT);
    BUTTON_PORT |= _BV(BUTTON2_BIT);
    SWITCH_PORT |= _BV(SWITCH_BIT);

    LED_DDR  |= _BV(LED_BIT); // indicator led

    for (int i = 0; i < 5; i++) {
        LED_HIGH;
        _delay_ms(100);
        LED_LOW;
        _delay_ms(100);
    }

    sei();
    twi_init_master();

    rtc_init();
    rtc_set_ds1307();

    //rtc_set_time_s(16, 59, 50);
    //rtc_set_alarm_s(17,0,0);

    piezo_init();
    beep(440, 1);
    globals_init();
    display_init(g_brightness);

    g_alarm_switch = get_alarm_switch();

#ifdef FEATURE_FLW
    g_has_eeprom = has_eeprom();
//	if (!g_has_eeprom)  beep(440,2);  // debug
    if (!g_has_eeprom)
        g_flw_enabled = false;
    if (tm_ && g_has_eeprom)
        seed_random(tm_->Hour * 10000 + tm_->Minute + 100 + tm_->Second);
#endif

    beep(1320, 1);
    menu_init();  // must come after display, flw init
    rtc_get_alarm_s(&alarm_hour, &alarm_min, &alarm_sec);

    // set up interrupt for alarm switch
    PCICR |= (1 << PCIE2);
    PCMSK2 |= (1 << PCINT18);

#ifdef FEATURE_WmGPS
    // setup uart for GPS
    gps_init(g_gps_enabled);
#endif
#ifdef FEATURE_AUTO_DST
    if (g_DST_mode)
        DSTinit(tm_, g_DST_Rules);  // re-compute DST start, end
#endif
}
예제 #6
0
void init_libraries(char *param) {
    twi_init_master(param);
    twi_rpc_client_init((TWIBuffer) { rpc_buffer, sizeof(rpc_buffer) });
    check_error();
}