示例#1
0
int main(void){
	const uint16_t delay_t = 1000;	//Debug LED flash
	bool less_delay = false;	//compensate for LEx_led delay
	
	cli();//Disable Global Interrupt
	SPI_init();
	USART1_init(103);	//9600 baud rate
	sei();	//Enable Global Interrupt
	
	//set port as output
	//short pulse to execute the cmd received by the phase shifter
	DDRB |= 1<<DDB6;	//LE1 pulse
	DDRB |= 1<<DDB5;	//LE2 pulse
	DDRB |= 1<<DDB4;	//LE3 pulse
	DDRB |= 1<<DDB7;	//LE4 pulse
	
	//LED flashes after LE1 pulse is applied
	DDRE |= 1<<DDE6;	//PE6; LE1 LED
	DDRC |= 1<<DDC7;	//PC7; LE2 LED
	DDRC |= 1<<DDC6;	//PC6; LE3 LED
	DDRD |= 1<<DDD7;	//PD7; LE4 LED
	
	DDRB |= 1<<DDB0;	//debug; set port as output
	
	DDRD |= 1<<DDD5;	//set as output
	PORTD |= 1<<DDD5;	//turn off LED
	
    while (1){							
		PINB |= 1<<PINB0;		
		
		USART1_TX(0x15);
		
		if(LE1_led == 1){
			LE1_led = 0;
			PINE |= 1<<PINE6;	//turn on
			_delay_ms(LEx_led_t);
			PINE |= 1<<PINE6;	//turn off
			less_delay = true;
		}
		if(LE2_led == 1){
			LE2_led = 0;
			PINC |= 1<<PINC7;	//turn on
			_delay_ms(LEx_led_t);
			PINC |= 1<<PINC7;	//turn off
			less_delay = true;
		}
		if(LE3_led == 1){
			LE3_led = 0;
			PINC |= 1<<PINC6;	//turn on
			_delay_ms(LEx_led_t);
			PINC |= 1<<PINC6;	//turn off
			less_delay = true;
		} 
		if(LE4_led == 1){
			LE4_led = 0;
			PIND |= 1<<PIND7;	//turn on
			_delay_ms(LEx_led_t);
			PIND |= 1<<PIND7;	//turn off
			less_delay = true;
		}				
		
		if(less_delay){
			_delay_ms(delay_t-LEx_led_t);	
			less_delay = false;
		} else{
			_delay_ms(delay_t);	
		}
    }
}
示例#2
0
文件: uart.c 项目: ESS-Group/WSim
int uart1_putchar(int c)
{
  USART1_TX(c);
  return (unsigned char)c;
}