int main (void)
{
	wdt_reset();
	wdt_enable(WDTO_2S);    //Watchdog an
	DDRD = 0xFF;     		//Pullups, Port Initialisierung  
	DDRD &= ~ (1<<PD3);
	DDRD &= ~ (1<<PD2);
	DDRB = 0xFF;
	PORTC |= (1 << PC2);
	PORTC |= (1 << PC3);
	PORTC |= (1 << PC5);
	PORTC |= (1 << PC6);
	PORTC |= (1 << PC7);
	PORTD |= (1<<PD3);
	PORTD |= (1<<PD2);
	i2c_init();
	////Hardware PWM für Motoren 20000000 Hz / 256 / 256 (8bit Timer) = 304 Hz///
	TCCR0A = (1<<COM0A1)|(1<<COM0B1)|(1<<WGM01)|(1<<WGM00);  // Timer 0 für PWM bei A und B
	TCCR0B = (0 << CS02)|(1 << CS01)|(1 << CS00);           // Vorteiler / prescaler 1024 für Timer 0 (S. 100)############## PWM Frequenz ändern
	TCCR2A = (1<<COM2A1)|(1<<COM2B1)|(1<<WGM21)|(1<<WGM20);  // Timer 2 für PWM bei A und B
	TCCR2B = (1 << CS22)|(0 << CS21)|(0 << CS20);            // Vorteiler / prescaler 1024 für Timer 2 (S. 149)############## 
	
	
	
	
	TIMSK1 = (1<<TOIE1);									// Overflow Interrupt 312.5 1/s
	TCCR1B = 1;
	ReadChannelInit(1);
	
	if(PINSET(MCUSR, WDRF))
	   SETLED(P_LEDW);
	MCUSR &= ~(1 << WDRF);

	sei();//Interrupt starten
	
	while(true)									// main Schleife	
	{ 
	 wdt_reset();	
	}
}
int main (void)
{
	wdt_reset();
	wdt_enable(WDTO_2S);    //Watchdog an
	DDRD = 0xFF;     		//Pullups, Port Initialisierung  
	DDRD &= ~ (1<<PD3);
	DDRD &= ~ (1<<PD2);
	DDRB = 0xFF;
	PORTC |= (1 << PC2);
	PORTC |= (1 << PC3);
	PORTC |= (1 << PC5);
	PORTC |= (1 << PC6);
	PORTC |= (1 << PC7);
	PORTD |= (1<<PD3);
	PORTD |= (1<<PD2);
	i2c_init();
	////Hardware PWM für Motoren 20000000 Hz / 256 / 256 (8bit Timer) = 304 Hz///
	TCCR0A = (1<<COM0A1)|(1<<COM0B1)|(1<<WGM01)|(1<<WGM00);  // Timer 0 für PWM bei A und B
	TCCR0B = (0 << CS02)|(1 << CS01)|(1 << CS00);           // Vorteiler / prescaler 1024 für Timer 0 (S. 100)############## PWM Frequenz ändern
	TCCR2A = (1<<COM2A1)|(1<<COM2B1)|(1<<WGM21)|(1<<WGM20);  // Timer 2 für PWM bei A und B
	TCCR2B = (1 << CS22)|(0 << CS21)|(0 << CS20);            // Vorteiler / prescaler 1024 für Timer 2 (S. 149)############## 
	
	
	
	
	TIMSK1 = (1<<TOIE1);									// Overflow Interrupt 312.5 1/s
	TCCR1B = 1;
	ReadChannelInit(1);
	
	if(PINSET(MCUSR, WDRF))
	   SETLED(P_LEDW);
	MCUSR &= ~(1 << WDRF);

	sei();//Interrupt starten
	bool t = true;
	int16_t z = 0;
	
	while(true)									// main Schleife	
	{
	  if(t) {
		SETLED(P_LEDR);
		t=false; z++;
		_delay_ms(20);
	  } else {
		CLEARLED(P_LEDR);
		t=true;
		_delay_ms(20);
	  } 
	  if(z==20) {
	   change_i2c_address_srf08(adress_old,adress_new);
	   _delay_ms(50);
	  }
	  if(z==24) {
	    while(true) {
			if(t) {
				SETLED(P_LEDR);
				SETLED(P_LEDW);
				SETLED(P_LEDG);
				_delay_ms(1000);
				t=false;
			} else {
				CLEARLED(P_LEDR);
				CLEARLED(P_LEDW);
				CLEARLED(P_LEDG);
				_delay_ms(1000);
				t=true;
			}
			wdt_reset();
		}	
	  }
	 wdt_reset();	
	}
}
Beispiel #3
0
void
smdk2800_io_init(void)
{
	unsigned int hclk;
	unsigned int pclk;
	unsigned int tmdat;

#define	O	PCON_OUTPUT
#define	I	PCON_INPUT
#define	A	PCON_ALTFUN
#define	_	0       
#define	_C(b7,b6,b5,b4,b3,b2,b1,b0) \
	((b7<<14)|(b6<<12)|(b5<<10)|(b4<<8)|(b3<<6)|(b2<<4)|(b1<<2)|(b0<<0))

	/* GPIO port */
	IOW(S3C2800_GPIO_BASE+GPIO_PCONA, _C(O,O,A,A,A,A,A,A));
	IOW(S3C2800_GPIO_BASE+GPIO_PUPA,  0xff);
	IOW(S3C2800_GPIO_BASE+GPIO_PCONB, _C(I,O,A,A,A,A,A,A));
	IOW(S3C2800_GPIO_BASE+GPIO_PCONC, _C(_,_,_,_,O,A,A,A));
	IOW(S3C2800_GPIO_BASE+GPIO_PUPC,  0xff);
	IOW(S3C2800_GPIO_BASE+GPIO_PCOND, _C(A,A,A,A,A,A,A,A));
	IOW(S3C2800_GPIO_BASE+GPIO_PUPD,  0xff);
	IOW(S3C2800_GPIO_BASE+GPIO_PCONE, _C(O,O,O,O,A,A,A,A));
	IOW(S3C2800_GPIO_BASE+GPIO_PUPE,  0xff);
	IOW(S3C2800_GPIO_BASE+GPIO_PCONF, _C(A,A,A,A,A,A,A,A));
	IOW(S3C2800_GPIO_BASE+GPIO_PUPF,  0xff);
	IOW(S3C2800_GPIO_BASE+GPIO_EXTINTR, EXTINTR_INIT);

#undef	O
#undef	I
#undef	A
#undef	_
#undef 	_C

	/* Get clock value */
	if(IOR(S3C2800_CLKMAN_BASE+CLKMAN_CLKCON) & CLKCON_HCLK)
		hclk = FCLK / 2;
	else
		hclk = FCLK;

	if(IOR(S3C2800_CLKMAN_BASE+CLKMAN_CLKCON) & CLKCON_PCLK)
		pclk = hclk / 2;
	else
		pclk = hclk;

	/* Timer */
	if((pclk/F_1MHZ) < 1)
		tmdat = 1<<16;
	else
		tmdat = (pclk/F_1MHZ)<<16;

#define TMDAT_INIT		0xf424

	IOW(S3C2800_TIMER0_BASE+TIMER_TMDAT, (tmdat | TMDAT_INIT));
	IOW(S3C2800_TIMER1_BASE+TIMER_TMDAT, (tmdat | TMDAT_INIT));
	IOW(S3C2800_TIMER2_BASE+TIMER_TMDAT, (tmdat | TMDAT_INIT));

	IOW(S3C2800_TIMER0_BASE+TIMER_TMCON, TMCON_MUX_DIV32 | TMCON_INTENA | TMCON_ENABLE);
	IOW(S3C2800_TIMER1_BASE+TIMER_TMCON, TMCON_MUX_DIV16 | TMCON_INTENA | TMCON_ENABLE);
	IOW(S3C2800_TIMER2_BASE+TIMER_TMCON, TMCON_MUX_DIV8 | TMCON_INTENA | TMCON_ENABLE);

	/* Interrupt controller */
	IOW(S3C2800_INTCTL_BASE+INTCTL_INTMOD, 0);
	IOW(S3C2800_INTCTL_BASE+INTCTL_INTMSK, 0);

	/* Initial complete */
	SETLED(0x0);	/* All LEDs on (o o o) */
}