Beispiel #1
0
void
board_init(void)
{

	printf("\n\n");
	printf("BWCT FSB-A920-1\n");
	printf("http://www.bwct.de\n");
	printf("\n");
#if defined(SDRAM_128M)
	printf("AT92RM9200 180MHz 128MB\n");
#else
	printf("AT92RM9200 180MHz 64MB\n");
#endif
	printf("Initialising USART0\n");
	USART0_Init();
	printf("Initialising USART1\n");
	USART1_Init();
	printf("Initialising USART2\n");
	USART2_Init();
	printf("Initialising USART3\n");
	USART3_Init();
	printf("Initialising TWI\n");
	EEInit();
	printf("Initialising DS1672\n");
	DS1672_Init();
	printf("Initialising Ethernet\n");
	printf("MAC %x:%x:%x:%x:%x:%x\n", mac[0],
	    mac[1], mac[2], mac[3], mac[4], mac[5]);
	EMAC_Init();
	EMAC_SetMACAddress(mac);
	printf("Initialising SD-card\n");
	sdcard_init();
}
Beispiel #2
0
int main(void)
{
 systick_hw_init();
 led_hw_init();
 USART0_Init(115200);
 glcd_init();
 glcd_draw_string(0,0,"<<SSD1306 OLED>>",WHITE);
	glcd_draw_string(0,16,"Hello,SAM4N",WHITE);
	glcd_draw_string(0,32,"www.eeboard.com",WHITE);
	glcd_draw_string(0,48,"oled font test",WHITE);
 glcd_update();
 while(1){
	 USART0_Init(115200);
USART0_SendString("hello\r\n");
 PIOB->PIO_CODR=(0x01<<LED0_PIN);
 delay_ms(100);
 PIOB->PIO_SODR=(0x01<<LED0_PIN);
 delay_ms(100);
 }

}
int main()
{
	Timer2_Init();		//Initialize Timer2
    USART0_Init(9600);	//Initialize USART0 with baud rate of 9600
	USART1_Init(9600);	//Initialize USART1 with baud rate of 9600
	_delay_ms(500);		//delay 500 milisecond

	sei();//Enable Gloabal Interrupt

	while(1)//dead loop
	{

	}

return 0;

}
int main()
{
    //unsigned char temp = 0;
	unsigned char second;
	unsigned char j = 0;
	unsigned char temp_data,memData;
	unsigned char w_array[BlockNum];
	unsigned char r_array[BlockNum];	
	
	USART0_Init(38400);//Initialize USART0 with baud rate of 9600
	USART1_Init(38400);//Initialize USART1 with baud rate of 9600
	
	TWI_Init();
	sei();         	//Enable Gloabal Interrupt
	//cli();		//Disable Gloabal Interrupt
	_delay_ms(500);

	Init();//optional
	_delay_ms(1000);
	ReadAddr();
	return 0;
}
int main()
{

    USART0_Init(38400);//Initialize USART0 with baud rate of 38400
    USART1_Init(38400);//Initialize USART1 with baud rate of 38400
    initIO();

    _delay_ms(10);
    sei();                     //Enable Gloabal Interrupt

    while(1){

    	readButtonSatus();

    	checkStatus();

    	_delay_ms(10);
    }


    return 0;

}
Beispiel #6
0
int main (void)
{
	// set mosi/sck out
	DDRB = (1<<DDB5)|(1<<DDB3)|(1<<DDB2);
	
	//latch out
	DDRB |= (1<<DDB1);
	//blank out
	DDRD |= (1<<DDD7);

	// latch aus
	PORTB &= ~(1<<PORTB1);
	// blank = high (all LEDs off)
	PORTD |= (1<<PORTD7);
	
	//SPI_Init()
	SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);

	//fill the RAM of the TLC with defined values
	SetLed(0,0,0,0);
	writeChannels();

	// blank = low (enable LEDs)
	PORTD &= ~(1<<PORTD7);
	
	DDRC &= ~(1<<PORTC0);
	DDRC &= ~(1<<PORTC1);
	DDRC &= ~(1<<PORTC2);
	DDRC &= ~(1<<PORTC3);
	DDRD &= ~(1<<PORTD2);
	DDRD &= ~(1<<PORTD3);
	PORTC |= (1<<PORTC0)|(1<<PORTC1)|(1<<PORTC2)|(1<<PORTC3);
	PORTD |= (1<<PORTD2)|(1<<PORTD3);

	//enable pullups ununsed pins
	PORTD |= (1<<PORTD4);
	PORTD |= (1<<PORTD5);
	PORTD |= (1<<PORTD6);
	PORTB |= (1<<PORTB0);
	PORTB |= (1<<PORTB2);
	PORTC |= (1<<PORTC4);
	PORTC |= (1<<PORTC5);
	
	//disable input buffers on unused pins
	DIDR1 |= (1<<AIN0D);
	DIDR0 |= (1<<ADC4D);
	DIDR0 |= (1<<ADC5D);
	
	//disable unused hardware (twi,adc,acd,timer0,timer2)
	PRR |= (1<<PRTWI)|(1<<PRADC)|(1<<PRTIM0)|(1<<PRTIM2);
	ACSR |= (1<<ACD); 

	//timer1 for tlc sync

	//set to FastPWM Mode & prescaler 8
	TCCR1A |= (1<<WGM10)|(1<<WGM11);
	TCCR1B |= (1<<WGM12)|(1<<WGM13)|(1<<CS11);//|(1<<CS10);
	//this is one cycle length of the TLC (2560)
	OCR1A = 1112; //2780 looks good
	//enable interrupt
	TIMSK1 |= (1<<TOIE1);
	


	//enable UART RX
	USART0_Init();
	
	//enable interrupts
	sei();

	uint8_t i = 0;
	
	while(1)
	{
		for(i=0;i<10;i++)
		{
			for(uint8_t j=0;j<10-i;j++)
			{
				SetLed(0,255,255,255);
				writeChannels();
				_delay_ms(i*10);
				SetLed(0,0,0,255);
				writeChannels();
				_delay_ms(i*10);
			}
		}

		for(i=0;i<20;i++)
		{
			for(uint8_t j=0;j<10-i;j++)
			{
				SetLed(0,0,255,0);
				writeChannels();
				_delay_ms(i*10);
				SetLed(0,0,0,255);
				writeChannels();
				_delay_ms(i*10);
			}
		}

		for(i=0;i<20;i++)
		{
			for(uint8_t j=0;j<10-i;j++)
			{
				SetLed(0,0,255,0);
				writeChannels();
				_delay_ms(i*10);
				SetLed(0,255,0,0);
				writeChannels();
				_delay_ms(i*10);
			}
		}


		for(uint8_t j=50;j<100;j+=10)
		{
		for(i=0;i<5;i++)
		{
			SetLed(0,255,0,0);
			writeChannels();
			_delay_ms(j);
			SetLed(0,0,0,255);
			writeChannels();
			_delay_ms(j);
		}
		}

		for(uint8_t j=50;j<100;j+=10)
		{
		for(i=0;i<5;i++)
		{
			SetLed(0,0,255,0);
			writeChannels();
			_delay_ms(j);
			SetLed(0,255,255,0);
			writeChannels();
			_delay_ms(j);
		}
		}



		for(uint8_t j=0;j<3;j++)
		{
			for(i=1;i<5;i++)
			{
				SetLed(0,0,0,0);
				SetLed(i*2,255,0,0);
				SetLed(i*2-1,255,0,0);

				SetLed((5-i)*2,0,0,255);
				SetLed((5-i)*2-1,0,0,255);
				writeChannels();
				_delay_ms(200);
			}
			for(i=4;i>1;i--)
			{
				SetLed(0,0,0,0);
				SetLed(i*2,255,0,0);
				SetLed(i*2-1,255,0,0);

				SetLed((5-i)*2,0,0,255);
				SetLed((5-i)*2-1,0,0,255);
				writeChannels();
				_delay_ms(200);
			}
		}



		for(i=0;i<50;i++)
		{
			SetLed(0,255,0,0);
			writeChannels();
			_delay_ms(30);
			SetLed(0,0,255,0);
			writeChannels();
			_delay_ms(30);
			SetLed(0,0,0,255);
			writeChannels();
			_delay_ms(30);
		}

		for(i=0;i<50;i++)
		{
			SetLed(0,255,0,0);
			writeChannels();
			_delay_ms(10);
			SetLed(0,0,255,0);
			writeChannels();
			_delay_ms(10);
			SetLed(0,0,0,255);
			writeChannels();
			_delay_ms(10);
		}

		for(i=0;i<100;i++)
		{
			SetLed(0,0,255,255);
			writeChannels();
			_delay_ms(3);
			SetLed(0,255,0,255);
			writeChannels();
			_delay_ms(3);
			SetLed(0,255,255,0);
			writeChannels();
			_delay_ms(3);
		}


		SetLed(0,0,0,0);

		uint16_t q = 0;
		uint16_t j = 1;
		
		for(q=1024;q>2;)
		{
			for(uint16_t v=0;v<j;v++)
			{
				SetLed(0,0,255,255);
				writeChannels();
				_delay_ms(q);
				SetLed(0,255,0,255);
				writeChannels();
				_delay_ms(q);
				SetLed(0,255,255,0);
				writeChannels();
				_delay_ms(q);
				SetLed(0,255,0,0);
				writeChannels();
				_delay_ms(q);
				SetLed(0,0,255,0);
				writeChannels();
				_delay_ms(q);
				SetLed(0,0,0,255);
				writeChannels();
				_delay_ms(q);
			}
			j = j * 2;
			
			q = q >> 1;
		}

	}


}
Beispiel #7
0
int main(void)
{
	//USART init (mark)
	USART0_Init(MYUBRR0);
	fdevopen(uart_putc0, USART0_Receive);
	printf("Hello World!\n");
	
	//SPI_MasterInit();
	//SPI_config for spi adc module ??? (mark)
	DDR_SPI |= (1<<DD_MOSI) | (1<<DD_SCK) | (1<<DD_SS);
	DDR_SPI &= ~(1<<DD_MISO);
	PORT_SPI |= (1<<DD_SS);
	SPCR = (1<<SPIE) | (1<<SPE) | (1<<MSTR);
	//Can init with id 20. (mark)
	can_init();
	CAN_packet p;
	p.id = ID_power_measure;
	p.length = 4;
	//Estop can message recv funcion setup -> id 1
	prepare_rx(1, ID_e_stop, 0x7ff, receiveEStop);
	//prepare_rx(2, MOTOR_STATUS_ID, 0x7ff, receiveMotorStatus);
	
	
	//leds and e_stop relay
	DDRD |= (1<<LED1) | (1<<LED2) | (1<<LED3);
	DDRE |= (1<<E_STOP);
	
	PORTD &= ~((1<<LED1) | (1<<LED2) | (1<<LED3));
	PORTE &= ~(1<<E_STOP);
	
	//ADC1 positive differential input, ADC0 negative differential input
	//ADMUX = (1<<REFS0) | (1<<REFS1) | 0x10;
	//Enable, start conversion, interrupt enable, prescaler 64 (8MHz/64 = 125KHz)
	//ADCSRA |= (1<<ADEN) | (1<<ADSC) | (1<<ADIE) | (1<<ADPS2) | (1<<ADPS1);
	
	TCCR1B |= (1<<WGM12) | (1<<CS12);		//CTC mode, prescaler 256
	TIMSK1 |= (1<<OCIE1A);				//compare match A interrupt
	OCR1A = 31249;
	
	PORT_SPI &= ~(1<<DD_SS);	//initate new reading
	SPDR = 0x06;	//single ended
	spi_seq = 1;
	spi_ch = 0;
	
	sei();
	
	
	
	uint32_t temp_voltage, temp_current_motor;
	uint16_t temp_counter;
	
	for (unsigned char i = 0; i < p.length; i++)
	{
		p.data[i] = i;
	}
	
    while(1)
    {
		if (timer_done == true)
		{
			timer_done = false;
			//heartbeat (mark)
			PORTD ^= (1<<LED1);
			
			//saving sampled data (mark)
			cli();
			temp_voltage = voltage_ADC_sum;
			temp_current_motor = current_motor_ADC_sum;

			temp_counter = counter;
			voltage_ADC_sum = 0;
			current_motor_ADC_sum = 0;

			counter = 0;
			sei();
			
			//Average and scale data (mark)
			int voltage = temp_voltage*100/temp_counter/VOLTAGE_SCALE; //TODO chage to uint32_t ??
			uint32_t currentM = ((uint32_t)(temp_current_motor/temp_counter) - CURRENT_MOTOR_ZERO + 5)/CURRENT_MOTOR_SCALE ;

 		
			//What is 455??? (mark)
			if (voltage > 455)
			{
				PORTD |= (1<<LED3);
			}
			else
			{
				PORTD &= ~(1<<LED3);
			}
			
			//Preapere can message (mark)
			p.data[0] = voltage>>8;
			p.data[1] = voltage;
			p.data[2] = currentM>>8;
			p.data[3] = currentM;
		
			//For debugging
			
			printf("Average over %d samples:\n\r", temp_counter);
			printf("Voltage: %d\n\r", voltage);
			printf("Current motor: %lu\n\r", currentM);
			//printf("Current without scaling: %lu\n\r", (uint32_t)(temp_current_motor/temp_counter));
			//printf("calc: (%u/%d - %d + 5)/%d*100)\n\r", temp_current_motor, temp_counter, CURRENT_MOTOR_ZERO, CURRENT_MOTOR_SCALE);
			//printf("Current one: %lu\n\r", current_motor_one_value);
			
			//printf("CAn packet: %s\n", str);
			can_tx(14, &p);
			
			PORTD ^= (1<<LED1); //heartbeat (mark)
		}
		
	}
Beispiel #8
0
int main(void)
{
	TCCR0B |= (1<<CS00);
	TIMSK0 |= (1<<TOIE0);

	PORTC &= ~((1<<PORTC2)|(1<<PORTC3)|(1<<PORTC4)|(1<<PORTC5));
	DDRC |= (1<<PORTC2)|(1<<PORTC3)|(1<<PORTC4)|(1<<PORTC5);

	DDRD |= (1<<PORTD5);
	PORTD &= ~(1<<PORTD5);


	USART0_Init();
	
	
	sei();
	

	DDRB |= (1<<PORTB0);
	PORTB |= (1<<PORTB0);
	

	led_a2 = 1;//white
	led_b2 = 1;//blue
	led_c2 = 1;//green
	led_d2 = 1;//red
	

	uint8_t idx = 0;
	uint8_t escape = 0;
	uint8_t our_data = 0;

	while(1)
	{
		uint8_t data = 0;

		if(USART0_Getc_nb(&data))
		{

			if(data == 0x42)
			{
				idx = 0;
				escape = 0;
				our_data = 0;
				continue;
				
			} else if (data == 0x23)
			{
				idx=5;
				continue;
			} else if (data == 0x65)
			{
				escape = 1;
				continue;
			}

			if(escape == 1)
			{
				if(data == 1)
				{
					data = 0x23;
				}
				else if (data == 2)
				{
					data = 0x42;
				}
				else if (data == 3)
				{
					data = 0x65;
				}
				else if (data == 4)
				{
					data = 0x66;
				}
				escape = 0;
			}

			if(idx == 0)
			{
				if(data == 0xf1)//addr
				{
					our_data = 1;
				} else if(data == 0xf0)//bcast
				{
					our_data = 1;
				}
				else
				{
					our_data = 0;
				}
			} 
			else if(our_data == 1)
			{
			
				if (idx == 1)
				{
					led_d2 = data;//red
				} else if (idx == 2)
				{
					led_c2  = data;//green
				} else if (idx == 3)
				{
					led_b2 = data;//blue
				} else if (idx == 4)
				{
					led_a2 = data;//white
					
					our_data = 0;
				}
				
			}
			if(idx < 5)
			{
				idx++;
			}
		}

	}

}