Exemplo n.º 1
0
usart_t 
usart_init (const usart_cfg_t *cfg)
{
    usart_dev_t *dev = 0;
    uint16_t baud_divisor;

    if (cfg->baud_rate == 0)
        baud_divisor = cfg->baud_divisor;
    else
        baud_divisor = USART_BAUD_DIVISOR (cfg->baud_rate);

#if USART0_ENABLE
    if (cfg->channel == 0)
    {
        usart0_init (baud_divisor);
        dev = &usart0_dev;
    }
#endif

#if USART1_ENABLE
    if (cfg->channel == 1)
    {
        usart1_init (baud_divisor);
        dev = &usart1_dev;
    }
#endif

    dev->read_timeout_us = cfg->read_timeout_us;
    dev->write_timeout_us = cfg->write_timeout_us;
    return dev;
}
Exemplo n.º 2
0
int main(void)
{

    usart0_init(25, 8, 1, USART_PARITY_EVEN,1); //38400
    usart1_init(25, 8, 1, USART_PARITY_DISABLED,0); //TODO check oi_alternative OI_ALTERNATE_BAUD_RATE

    _delay_ms(333);
    oi_switch_baud_rate();
    _delay_ms(333);
    oi_init();
    oi_full_mode();
    int i;
    int val;
    for (i = 0; i < 10; i++)
    {
        val = i % 2;
        oi_set_leds(val, val, val, val, 0xFF * val, 0xFF);
        _delay_ms(50);
    }
    oi_init();

    //input_capture_test();
    printf0("Hello world!\r\n");
    printf0(" 0x%02X 0x%02X 0x%02X", UCSR0A, UCSR0B, UCSR0C);
    _delay_ms(3000);
    doSweepLoop();
    doPingLoop();
    doIrLoop();
    servo_test();
}
Exemplo n.º 3
0
/**
 * @brief   Low level serial driver configuration and (re)start.
 *
 * @param[in] sdp       pointer to a @p SerialDriver object
 * @param[in] config    the architecture-dependent serial driver configuration.
 *                      If this parameter is set to @p NULL then a default
 *                      configuration is used.
 *
 * @notapi
 */
void sd_lld_start(SerialDriver * sdp, const SerialConfig * config) {

  if (config == NULL) {
    config = &default_config;
  }

  if (sdp->state == SD_STOP) {
#if MSP430X_SERIAL_USE_USART0 == TRUE
    if (&SD0 == sdp) {
      usart0_init(config);
    }
#endif
#if MSP430X_SERIAL_USE_USART1 == TRUE
    if (&SD1 == sdp) {
      usart1_init(config);
    }
#endif
#if MSP430X_SERIAL_USE_USART2 == TRUE
    if (&SD2 == sdp) {
      usart2_init(config);
    }
#endif
#if MSP430X_SERIAL_USE_USART3 == TRUE
    if (&SD3 == sdp) {
      usart3_init(config);
    }
#endif
  }
}
Exemplo n.º 4
0
int main()
{
	init();

	usart0_init();

	TWIOpen(0x40);
	
	sei();
		
	while(1)
	{
		if(!(PIN_KEY & KEY1))
		{
			PORT_LED_GREEN|=LED_GREEN;

			char data[17];	// yy/mm/dd,hh:mm:ss

			GetDataTimeRTC(data, 17);

			for(uint8_t i=0; i<sizeof(data); i++) usart0_write(data[i]);

			usart0_write(0x0D);
			usart0_write(0x0A);

			_delay_ms(100);
			
		}

		else

		{
			PORT_LED_GREEN&=~LED_GREEN;
		}

		if(!(PIN_KEY & KEY0))
		{
			PORT_LED_YELLOW|=LED_YELLOW;

			char data[]={'1','2','/','1','1','/','1','0',',','2','1',':','2','0',':','0','0'};	// yy/mm/dd,hh:mm:ss

			SetDataTimeRTC(data);

			//char data[]={'1','8',':','0','0',':','0','0'};
			//SetTimeRTC(data);

		}

		else

		{
			PORT_LED_YELLOW&=~LED_YELLOW;
		}

		
	}

}
void Init(void)
{
    CLKPR = _BV(CLKPCE); // enable clock scalar update
    CLKPR = 0x00;	// set to 8Mhz
    PORTC = 0xff;	// all off
    DDRC  = 0xff; 	// show byte in leds
    usart0_init( 51 );	// 9600 baud at 8MHz

    Init_IO ();
    Spi_p_Init ();      // Initialization (polling)

}
Exemplo n.º 6
0
int main(void){

	init();

	usart0_init();

	sei();

	for(uint8_t delay=0; delay<3; delay++) 
		_delay_ms(1000);

	while(AtOk())			//Проверяем готовность модуля командой AT.
	{
		PORT_SIM|= (PWR_KEY);
		_delay_ms(2000);
		PORT_SIM&= ~(PWR_KEY);
		_delay_ms(5000);
		PORT_SIM|= (PWR_KEY);
	}
	
	while(ConfigGsmModules())	_delay_ms(1000);

	_delay_ms(500);

	while(GsmReg())	_delay_ms(2000);

//	START_TIMER0;

	_delay_ms(1000);

	//SimIMEI(u);	//!!!And IMEI_NUM_ENABLE

	while(SignalQualityReport(u)) 	_delay_ms(2000);
	

	while(SendSMS("+79119008502", "Hello GSM SIM300!")) _delay_ms(2000);

	//while(UnstructuredSupplementaryServiceData("#102#", u)) _delay_ms(2000);


	while(1){
		
		//PORT_OUT|=BUZ;
		
		PORT_OUT&=~BUZ;
		PORT_OUT&=~BUZ;
		PORT_OUT&=~BUZ;

	}
}
Exemplo n.º 7
0
int main()
{
	
	init();

	usart0_init();
	
	uint8_t slave_id=~(PINB);

	char tx_buffer[4];

	tx_buffer[0]=slave_id;
	tx_buffer[1]=DEVICE_ID;

	sei();

	while(1)
	{

		if(!(PIN_BUT & (BUT1)))
		{
		
			tx_buffer[2]=LED_GO_ON;
			tx_buffer[3]=_crc8_update(tx_buffer, (sizeof(tx_buffer)-1));

			for(uint8_t i=0; i<sizeof(tx_buffer); i++)
				usart0_write(tx_buffer[i]);
				
			_delay_ms(PAUSE);
		}

		if(!(PIN_BUT & (BUT2)))
		{
		
			tx_buffer[2]=LED_GO_OFF;
			tx_buffer[3]=_crc8_update(tx_buffer, (sizeof(tx_buffer)-1));

			for(uint8_t i=0; i<sizeof(tx_buffer); i++)
				usart0_write(tx_buffer[i]);
				
			_delay_ms(PAUSE);
		}
		
		usart0_clear_tx_buffer();

	}

}
Exemplo n.º 8
0
int main(void)
{

	init();

	usart0_init();							//Init USART 19200 8-N-1.
	usart1_mod_init(select_baud_rate());

	init_time_0xffff();			//All time[] = 0xFFFF.

	slave_add=select_slave_addr();

	PORTB&=~(1<<PB1);			//PORT_RS485|=(1<<RE_DE);

	sei();						//Enable Interrupt.

	while(1)
	{

		//”словие отвечающие за обработку MODBUS протокола.
		if(usart1_rx_len()!=back_len1)	
		{
			back_len1=usart1_rx_len();
			TCNT3=0x0000; 
			TCCR3B=(1<<CS32)|(0<<CS31)|(0<<CS30);
		}

		//”словие отвечающие за обработку GPS протокола.
		if(usart0_rx_len()!=back_len)
		{
			back_len=usart0_rx_len();
			TCNT1=0x0000;
			TCCR1B=(1<<CS12)|(0<<CS11)|(0<<CS10);
		}

		//”словие отвечающее за time[] = 0xFFFF.
		if(timeout_gps_conect)
			timeout_gps_conect--;
			else
				init_time_0xffff();


		wdt_reset();	//Watchdog Reset.

	
	}// End while(1).

}// End main().
Exemplo n.º 9
0
// Main program: USART0: send & receive
int main( void )
{
	DDRB = 0xFF;							// set PORTB for output, for testing
	DDRA = 0xFF;							// set PORTA for output, for testing
	usart0_init();							// initialize USART0
	usart0_start();							// uart0: start send & receive

	while (1)
	{
		wait(50);							// every 50 ms (busy waiting)
		PORTB ^= BIT(7);					// toggle bit 7 for testing

		character = uart0_receiveChar();	// read char
		PORTA = character;					// show read character, for testing

		uart0_sendChar(character);			// send back
	}
}
Exemplo n.º 10
0
/**
 * @brief   Low level serial driver configuration and (re)start.
 *
 * @param[in] sdp       pointer to a @p SerialDriver object
 * @param[in] config    the architecture-dependent serial driver configuration.
 *                      If this parameter is set to @p NULL then a default
 *                      configuration is used.
 *
 * @notapi
 */
void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) {

  if (config == NULL)
    config = &default_config;

#if USE_MSP430_USART0
  if (&SD1 == sdp) {
    usart0_init(config);
    return;
  }
#endif
#if USE_MSP430_USART1
  if (&SD2 == sdp) {
    usart1_init(config);
    return;
  }
#endif
}
Exemplo n.º 11
0
void main(void)
{
	clock_init();
	usart0_init();

	/* Give PIO control over the RGB pins */
	SAM3_PIOA.enable = (1 << 20) | (1 << 16) | (1 << 0);
	SAM3_PIOA.output_enable = (1 << 20) | (1 << 16) | (1 << 0);

	/* Drive them */
	for (;;) {
		SAM3_PIOA.set_output_data = (1 << 20) | (1 << 16) | (1 << 0);
		delay_ms(100);
		SAM3_PIOA.clear_output_data = (1 << 20) | (1 << 16) | (1 << 0);
		delay_ms(100);
		usart0_putc('X');
	}
}
Exemplo n.º 12
0
int main(void)
{
    // Initialise USART
    usart0_init();

    // Direct stdout stream to printf_stream
    stdout = &printf_stream;

    // Send strings
    printf("printf - String in data memory (RAM)\n");

    printf_P(PSTR("printf_P - String in data memory (RAM)\n"));

    PRINTF("PRINTF - String in program memory (FLASH)\n");

    // Repeat indefinitely
    for(;;)
    {
        ;
    }
}
Exemplo n.º 13
0
int main()
{
 	unsigned short adcVal;	// Variable to store input ADC Value
	unsigned char  dc;	// Store calculated DC value based on adcVal
	
	stdout = &USART0_stream;// change standard output to point to a USART stream
	
	PWM_OC1A_init();	// initialize pwm  on OC1A
	ADC0init();		// Initialize ADC0 input
	usart0_init();		// Initialize USART0 for debugging and monitoring
	
	while (1) 
	{
		adcVal = readADC();	// read ADC0;
		dc = (unsigned short)(100.0*adcVal / 1023); // get percentage of input voltage from Vcc. 
 		updateDC_OC1A(dc);	// Update OCR1A to update duty cycle of OC1A 
		printf("ADC Value = %u\n", adcVal);		// Monitoring output
		printf("\tDuty cycle = %u%%\n", dc);	// Monitoring output
 		_delay_ms(100);		// Have an imperceivable delay
	}
}
Exemplo n.º 14
0
int main (void)
{
	init();
	
	usart0_init();				//Init UART.

    Enc28j60Init(mymac);    //initialize enc28j60
    _delay_ms(10);
    InitPhy();
    Init_ip_arp_udp_tcp(mymac,myip,80);  //init the ethernet/ip layer
	
	PORTB&= ~(LED_RUN);

	sei();
	
	while(1)
	{
		timeUpdate = false;
	}

}
Exemplo n.º 15
0
int main()
{
	init();

	usart0_init();

	sei();

	_delay_ms(1000);
	char ate="ATE0\n";
	char at="AT\n";
	char ok="OK";

//	usart0_write_str(ate);

	_delay_ms(1000);

	Begin0:
	usart0_clear_tx_buffer();
	usart0_clear_rx_buffer();

	usart0_write_str(at);

	while(usart0_wait(ok))
	{
		_delay_ms(1000);
		_delay_ms(1000);
		goto Begin0;
	}


	PORT_LED&=~(1<<LED);

	while(1)
	{
	
			
	}

}
Exemplo n.º 16
0
// send/receive uart - dB-meter
int main( void )
{
	char buffer[16];						// declare string buffer 	

	init_Lcd_4_bit_mode();					// initialize LCD-display
	usart0_init();							// initialize USART0
	usart0_start();
		
	display_text("Hallo");
	set_cursor(0);
	while (1)
	{
		wait(150);							// every 50 ms (busy waiting)
		//PORTB ^= BIT(7);					// toggle bit 7 for testing

		uart0_receiveString( buffer );		// receive string from uart
		
		// write string to LCD display
		display_text(buffer);
		set_cursor(0);
	}
}
Exemplo n.º 17
0
int main(void) {

#ifdef USART_DEBUG
	usart0_init();
#endif

	init_pwm();
	ir_init();
	control_init();
	fe_init();
	
	sei();

#ifdef USART_DEBUG
	usart0_puts("Initialized\n\r");
#endif

	while (1) {
		ir_handler();
		control_handler();
		pwm_handler();
		fe_handler();
	}
}
int usart_main(int argc, char *argv[])
{
	cli();
	local::system_init();
	usart0_init(57600UL);
	usart1_init(57600UL);
	sei();

	PORTD = 0xFF;
	_delay_ms(100);
	PORTD = 0x00;

	while (1)
	{
		if (!usart0_is_empty())
		{
/*
#if 0
			uint8_t hex = usart0_top_char();
			usart0_pop_char();
#else
			uint8_t ascii = usart0_top_char();
			usart0_pop_char();
			uint8_t hex = ascii2hex(ascii);
#endif
			uint16_t num = 0xABCD;
			usart1_push_char(hex2ascii((num >> 12) & 0x0F));
			usart1_push_char(hex2ascii((num >> 8) & 0x0F));
			usart1_push_char(hex2ascii((num >> 4) & 0x0F));
			usart1_push_char(hex2ascii(num & 0x0F));
*/
			uint8_t ascii = usart0_top_char();
			usart0_pop_char();
			uint8_t hex = ascii2hex(ascii);

			PORTA = hex;

			usart0_push_char(ascii);
		}

		if (!usart1_is_empty())
		{
/*
#if 0
			uint8_t hex = usart1_top_char();
			usart1_pop_char();
#else
			uint8_t ascii = usart1_top_char();
			usart1_pop_char();
			uint8_t hex = ascii2hex(ascii);
#endif
			uint16_t num = 0xABCD;
			usart1_push_char(hex2ascii((num >> 12) & 0x0F));
			usart1_push_char(hex2ascii((num >> 8) & 0x0F));
			usart1_push_char(hex2ascii((num >> 4) & 0x0F));
			usart1_push_char(hex2ascii(num & 0x0F));

*/
			uint8_t ascii = usart1_top_char();
			usart1_pop_char();
			uint8_t hex = ascii2hex(ascii);

			PORTA = hex;

			usart1_push_char(ascii);
		}

		//sleep_mode();
	}

	return 0;
}
Exemplo n.º 19
0
int main(void)
{
//	EXT_MEM_INIT;
	
	usart0_init(USART_RS485_SLAVE, 38400);
	usart0_setprotocol_modbus();
	usart1_init(USART_RS232, 115200);
	USART1_SET_8N1;
	USART1_RX_INT_DISABLE;

	timer_init();
	kbd_init();
	shift_init();
	sensor_init();
	menu_init();
	menu_items_init();

	beep_init();
	
	GLOBAL_INT_ENABLE;

	beep_ms(1000);
	_delay_ms(500);
	beep_ms(200);
	_delay_ms(200);
	beep_ms(200);
	_delay_ms(200);

	lcd_init();

	for (;;)
	{
		//do_kbd();
		do_lcd();
		do_shift();
		do_sensor();
		
		menu_doitem();

		process_usart();
		process_soft_controls();
		process_siren();
		//process_foil();
		//process_kbd();
		
		// simple process foil
		
		soft_sensors = sensors;
		
		if (TEST_SOFT_CONTROL(SOFT_CONTROL_BUNKER_MOTOR) &&
			TEST_SENSOR(SENSOR_END_OF_FOIL))
			
			SOFT_CONTROL_OFF(SOFT_CONTROL_BUNKER_MOTOR);
/*			
		if (!TEST_SENSOR(SENSOR_END_OF_FOIL) &&
			TEST_SENSOR(SENSOR_SEC_REEL))
			
			SOFT_CONTROL_ON(SOFT_CONTROL_BUNKER_MOTOR);
*/
	}
	return 0;
}
Exemplo n.º 20
0
Arquivo: init.c Projeto: lwid/openasc
/*! Init the UART for the computer communication */
void init_usart_computer(void) {
	usart0_init(7); //115.2kbit
	fdevopen((void*)usart0_transmit, (void*)usart0_receive_loopback);
}
Exemplo n.º 21
0
Arquivo: init.c Projeto: lwid/openasc
/*! Init the UART for the computer communication */
void init_usart_computer(void) {
	usart0_init(47); //19200 baud
	fdevopen((void*)usart0_transmit, (void*)usart0_receive_loopback);
}
Exemplo n.º 22
0
int main()
{



	init();

	PORTA|=(1<<PWR_KEY);
	_delay_ms(2000);
	PORTA&=(0<<PWR_KEY);
	_delay_ms(5000);
	PORTA|=(1<<PWR_KEY);


	usart0_init();

	sei();

	_delay_ms(3000);

	PORT_LED&=~(1<<LED);

#if 0
	while(at_ok())				//Проверяем готовность модуля командой AT.
	{ 							//Если все правильно и скорости совпадают вернтся ответ "0".
		at_ok();
									
		ATV0;	//Макрос отключающий словесный формат ответа. Т.е. теперь будут приходить коды ответа.

			_delay_ms(1000);
		
		ATE0;	//Макрос отключающий эхо от модуля.

			_delay_ms(1000);
	}

#endif

	CMGF1;			//Макрос уставливает режим PDU.

	//while(ok());
	_delay_ms(1000);

	CSCS_UCS2;		//Макрос устанавливает кодировку Юникод. По умолчанию GSM.

	//while(ok());	//Ждем ОК (! ОК прийдет уже не как "OK", а как "0").

	_delay_ms(1000);


	
		usart0_clear_rx_buffer();
		usart0_clear_tx_buffer();

	//	ATD;
	//	NUMBER3_GSM;
	//	ENTER_ATD;

	while(1)
	{

		if(!(PIN_KEY & (1<<KEY0)))
		{
			sms_tx(0,0);
						for(uint8_t p=0; p<5; p++) _delay_ms(1000);

			sms_tx(0,1);
						for(uint8_t p=0; p<5; p++) _delay_ms(1000);

			sms_tx(0,2);
						for(uint8_t p=0; p<5; p++) _delay_ms(1000);

			sms_tx(0,3);
						for(uint8_t p=0; p<5; p++) _delay_ms(1000);


			PORT_LED&=~(1<<LED);

			for(uint8_t p=0; p<10; p++) _delay_ms(1000);

			usart0_clear_rx_buffer();
			usart0_clear_tx_buffer();

			ATD;
			NUMBER0_GSM;
			ENTER_ATD;	

		}
			else
			{
				PORT_LED|=(1<<LED);
			}

	}

return 0;

}