Exemplo n.º 1
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();

	/* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
	CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	GlobalInterruptEnable();

	_setBrightness(50);

	for (;;)
	{
		/* Must throw away unused bytes from the host, or it will lock up while waiting for the device */
		CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
		CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();

		DS1302_clock_burst_read((uint8_t *) &rtc);

		_setDigit( rtc.Seconds % 10 );
		_setBrightness( 50 );

		_delay_ms(4);
    }
}
Exemplo n.º 2
0
void getTime1302(ds1302_struct &rtc) {
  // Read all clock data at once (burst mode).
  DS1302_clock_burst_read( (uint8_t *) &rtc);
}
Exemplo n.º 3
0
int main(void)
{
	//PORTS A,C,E,D are dedicated to matrix display
	DDRD = 0xFF;
	DDRE = 0xFF;
	DDRA = 0xFF;
	DDRC = 0xFF;
	
	//button port is for input
	BUTTON_DIR = 0x00;
	//pullups for PINB0 and PINB1 (button X and Z)
	BUTTON_PORT = 0x03;
	//just make sure pullups are NOT disabled
	MCUCR |= (0 << PUD);
	
	//A0-A3 : are the negative row 1-4
	//C4-C7 : are the negative row 5-8
	
	XDIV = 0x00;

	init_timer2_OVF();
	init_timer0_OVF();
	
	//DS1302 is plugged on the G port	
	setupDS1302();
			
	wormInit();
	rainInit();
	
	while (1){
		//refresh display
		showMatrix();
		
		if (mShowMode != MODE_SETTIME){
			//check if BUTTON_X is pressed (back board button)
			if ((~BUTTON_INPUT & (1 << BUTTON_X)) != 0){
				matrixClearAll();
				mShowMode = (mShowMode + 1) % MODE_COUNT;
				//debounce
				_delay_ms(500);
			}

			//Z : go set time
			if ((~BUTTON_INPUT & (1 << BUTTON_Z)) != 0){
				mShowMode = MODE_SETTIME;
				mSubModeSetTimeStep = 0;
				//debounce
				_delay_ms(500);
			}
		}		
		else {
			//mode set time

			//X : hour or minute +1
			if ((~BUTTON_INPUT & (1 << BUTTON_X)) != 0){
				if (mSubModeSetTimeStep == 0){
					//hours +=1
					uint8_t vHours = rtc.h24.Hour10 * 10 + rtc.h24.Hour;
					vHours = (vHours +1) % 24;
					rtc.h24.Hour10 = vHours / 10;
					rtc.h24.Hour = vHours % 10;
					
					//write and read just after to see the result
					DS1302_clock_burst_write((uint8_t *) &rtc);
					DS1302_clock_burst_read( (uint8_t *) &rtc);
				}
				if (mSubModeSetTimeStep == 1){
					//minutes +=1
					uint8_t vMin = rtc.Minutes10 * 10 + rtc.Minutes;
					vMin = (vMin +1) % 60;
					rtc.Minutes10 = vMin / 10;
					rtc.Minutes = vMin % 10;
					
					//write and read just after to see the result
					DS1302_clock_burst_write((uint8_t *) &rtc);
					DS1302_clock_burst_read( (uint8_t *) &rtc);			
				}
				//debounce
				_delay_ms(500);
			}

			//Z : go set time
			if ((~BUTTON_INPUT & (1 << BUTTON_Z)) != 0){
				mSubModeSetTimeStep++;
				if (mSubModeSetTimeStep > 1){
					//finished
					matrixClearAll();
					mShowMode = MODE_TIME_RND;
					mSubModeAnimId = rand() % 3;
				}
				//debounce
				_delay_ms(500);
			}
		}

	}
	
}