Example #1
0
File: main.c Project: jaseg/bt-lamp
int main(void){
	usart_init(BAUDRATE);
	TCCR1A |= (1<<COM1A1)|(1<<COM1B1)|(1<<WGM11);
	TCCR1B |= (1<<WGM12)|(1<<WGM13)|(1<<CS10);
	ICR1=0xFFFF;
	sei();
#ifdef MASTER
	rx_check = 1;
	usart_write("atz0\r");
	_delay_ms(500);
	usart_write("atn=lelamp");
	_delay_ms(200);
	usart_write("atp=1234");
	_delay_ms(200);
	usart_status.usart_ready = 0;
	rx_check = 0;
#endif
	while(1){
		if(usart_status.usart_ready){
			uint16_t val = usart_rx_buffer[1]<<8|usart_rx_buffer[2];
			if(usart_rx_buffer[0] == OA_NUM){
				OCR1A = val;
			}else if(usart_rx_buffer[0] == OB_NUM){
				OCR1B = val;
			}else{ //if command not found: echo.
				usart_write_str(usart_rx_buffer);
			}
			usart_status.usart_ready = 0;
		}
	}
}
Example #2
0
File: mp3.c Project: mick909/ncnl
FRESULT play(FIL *fp)
{
	UINT bytesread;
	FRESULT res;
	prepare_decoder();

	do {
		WORD idx;
		res = f_read(fp, buf, 256, &bytesread);

		if ( res ) {
			usart_write_string("f_read failed :");
			usart_write( (res / 10) + '0' );
			usart_write( (res % 10) + '0' );
			usart_write_cr();
			return res;
		}

		if ( bytesread == 0 ) break;

//		usart_write_string("set 256 bytes...");
		PORTD &= ~XDCS;
		idx = 0;
		do {
			do {} while (! (PIND & DREQ));
			xchg_spi(buf[idx++]);
		} while (--bytesread);
		PORTD |= XDCS;
//		usart_write_string("done\r\n");
	} while (1);

	usart_write_string("play done, reset vs1011e\r\n");
	PORTD &= ~XRESET;
	return FR_OK;
}
Example #3
0
int main(void)
{
	// clock prescaler
	CLKPR = BIT(CLKPCE); // enable prescaler change
	CLKPR = BITS(0b0000, CLKPS0); // divider 1

	// disable JTAG - control F port
	MCUCR = BIT(JTD);
	MCUCR = BIT(JTD);

	// LED outputs
	bit_set(DDRF, LEDS);
	bit_set(PORTF, LEDS);

	// button inputs
	bit_clear(DDRD, BIT(BTN1) | BIT(BTN2));

	// IO inputs
	bit_clear(DDRB, BIT(IO1));
	bit_clear(DDRC, BIT(IO2));

	// initialize comms
	usb_init();
	usart_init();

	// wait for USB configuration
	// while (!usb_configured());
	_delay_ms(1000);

	// heartbeat timer (timer0)
	TCCR0A = BITS(0b10, WGM00); // CTC mode (mode 2)
	TCCR0B = BITS(0b101, CS00); // divider 1024
	TIMSK0 = BIT(OCIE0A); // enable compare A on timer0
	OCR0A = 250; // 62.5Hz
	TCNT0 = 0;

	sei(); // enable interrupts

	bit_clear(PORTF, BIT(LED2G));

	/*uint8_t n;
	char buf[16];*/

	while (1)
	{
		usart_write("3:s1\n");
		usart_write("4:s-1\n");

		_delay_ms(3000);


		usart_write("3:s-1\n");
		usart_write("4:s1\n");

		_delay_ms(3000);
	}
}
Example #4
0
int Ax12Class::move(unsigned char ID, long Position)
{
    char Position_H,Position_L;
    Position_H = Position >> 8;           // 16 bits - 2 x 8 bits variables
    Position_L = Position;
    
    TChecksum = (ID + AX_GOAL_LENGTH + AX_WRITE_DATA + AX_GOAL_POSITION_L + Position_L + Position_H);
    while ( TChecksum >= 255){            
		TChecksum -= 255;     
    }
    Checksum = 255 - TChecksum;
    
	digitalWrite(Direction_Pin,HIGH);      // Set Tx Mode
    usart_write(AX_START);                 // Send Instructions over Serial
    usart_write(AX_START);
    usart_write(ID);
    usart_write(AX_GOAL_LENGTH);
    usart_write(AX_WRITE_DATA);
    usart_write(AX_GOAL_POSITION_L);
    usart_write(Position_L);
    usart_write(Position_H);
    usart_write(Checksum);
	delayMicroseconds(TX_DELAY_TIME);
    digitalWrite(Direction_Pin,LOW);       // Set Rx Mode
	
    return (read_error());                 // Return the read error
}
Example #5
0
/* Sends a query/response over a serial communication */
static int modbus_send(uint8_t *query, int query_length) {

	uint16_t s_crc;
	int i;

	s_crc = crc16(query, query_length);
	for (i = 0; i < query_length; i++) {
		usart_write(query[i]);
	}
	// zum Schluss die CRC senden
	usart_write(s_crc >> 8);
	usart_write(s_crc & 0x00FF);
	return i;
}
Example #6
0
/**
 * \ingroup usartcmdline
 * \b ADC-Befehl analoge Werte der AD-Wandler anzeigen
 */
int16_t command_ADC(char *outbuffer)
{
	if (outbuffer)					// nur bei USART
		return cmd_502(outbuffer);

	#if USE_ADC
	int8_t	i;

	for (i=0; i<MAX_VAR_ARRAY; i++) {
		usart_write("\r\nADC-Kanal(%i) = %i",i,var_array[i]);
	}
	usart_write("\r\n");
	#endif
	return 0;
}
Example #7
0
int main()
{
    char str[1024] = {0};
    int len = 0;

	SysTick_Config(720000);

    usart_init();
    usart_write("Hello, rnrOS!\r\n", 15);
    while (1){
        len = usart_read(str, 1024);
        usart_write(str, len);
        len = 0;
    }
}
void main_task(void *args) {
    uint8_t buf = 0;

    usart_write(DEBUG_USART, (uint8_t *)"Enter some text:\r\n", 18);

    for(;;) {
        usart_read(DEBUG_USART, &buf, 1);
        usart_write(DEBUG_USART, &buf, 1);

        if (buf == '\r') {
            buf = '\n';
            usart_write(DEBUG_USART, &buf, 1);
        }
    }
}
Example #9
0
void xb_nonvolatile(char *rs)
{
	/* Commit changes to the Xbee to non-volatile memory. */
	usart_text("ATWR");
	usart_write('\r');
	xb_response(rs);
}
Example #10
0
void xb_exit_command(char *rs)
{
	/* Leave XBee command mode. */
	usart_text("ATCN");
	usart_write('\r');
	xb_response(rs);
}
Example #11
0
//------------------------------------------------------------------------------
//print Time
void command_time (void)
{
//	unsigned char hh = (time/3600)%24;
//	unsigned char mm = (time/60)%60;
//	unsigned char ss = time %60;
    usart_write ("\n\rTIME: %2i:%2i:%2i\r\n",hh,mm,ss);
}
void usart_put_command(command_t cmd)
{
	usart_putword(cmd.code);
	usart_putword(cmd.length);
	if (cmd.length > 0)
		usart_write(cmd.data, cmd.length);
}
Example #13
0
// Prints a series of ascii characters on the serial port for the specified SerialInstance.
void serial_instance_print(SerialInstance* instance, char* string)
{
  while (*string) // Unsafe & exploitable
  {
    usart_write(&instance->_Usart, *string++);
  }
}
Example #14
0
/**
 * \brief Send a char to ISO7816.
 *
 * \param uc_char Char to be sent.
 *
 * \return status of US_CSR.
 */
static uint32_t iso7816_send_char(uint8_t uc_char)
{
	uint32_t ul_status;

	if (USART_RCV == gs_uc_state) {
		usart_reset_status(ISO7816_USART);
		usart_reset_iterations(ISO7816_USART);
		usart_reset_nack(ISO7816_USART);
		gs_uc_state = USART_SEND;
	}

	/* Wait USART ready for transmit. */
	while ((usart_get_status(ISO7816_USART) & US_CSR_TXRDY) == 0) {
	}

	/* There is no character in the US_THR, transmit a char. */
	usart_write(ISO7816_USART, uc_char);

	ul_status = usart_get_status(ISO7816_USART) & (US_CSR_OVRE |
			US_CSR_FRAME | US_CSR_PARE | US_CSR_TIMEOUT |
			US_CSR_NACK | US_CSR_ITER);

	if (ul_status != 0) {
		/** There are errors happened, reset the status bit. */
		usart_reset_status(ISO7816_USART);
	}

	/* Return status. */
	return (ul_status);
}
void usart_print( char *msg )
{
	int len = strlen( msg );

	for ( int c = 0; c < len; c++ )
		usart_write( (uint8_t)*msg++ );
}
Example #16
0
int main(void)
{
    u8 cnt;

    board_setup();

    configure_leds(C);
    light_leds(C, 0x0);

    enable_interrupt(0, IT_RAISING_EDGE);
    enable_interrupt(1, IT_LEVEL);

    usart_init(9600);

    sei();

    light_leds(C, 0x1);
    {
        u8 hw[] = "HELLO WORLD\n";
        usart_write(hw, sizeof(hw)-1);
    }

    for (;;) {
        int_clear_ack(0);
        int_clear_ack(1);

        led_cbk[cur_led_cbk]();

        _delay_ms(1000);
    }

    return 0;
}
Example #17
0
size_t usart_print(usart * usx, const char * s) {
	size_t n = 0;
	while (*s) {
		usart_write(usx, (uint16_t) *s++);
		n++;
	}
	return n;
}
Example #18
0
//------------------------------------------------------------------------------
//print/edit NTP Server IP
void command_ntp (void)
{
#if USE_NTP
    write_eeprom_ip(NTP_IP_EEPROM_STORE);
    (*((unsigned long*)&ntp_server_ip[0])) = get_eeprom_value(NTP_IP_EEPROM_STORE,NTP_IP);
    usart_write("NTP_Server: %1i.%1i.%1i.%1i\r\n",ntp_server_ip[0],ntp_server_ip[1],ntp_server_ip[2],ntp_server_ip[3]);
#endif //USE_NTP
}
Example #19
0
/**
 * \ingroup tcpcmdcommon
 * \b Ver-Befehl zeige enc28j60 chip version
 */
int16_t command_ver (char *outbuffer)
{
#if USE_ENC28J60
	if (outbuffer) {
		sprintf_P(outbuffer,PSTR("250 ok. ENC28J60-Version: %1x\r\n"), enc28j60_revision);
		return strlen(outbuffer);
	}
	else {
		usart_write("ENC28J60-Version: %1x\r\n", enc28j60_revision);
		return 0;
	}
#endif

#if USE_RTL8019
	usart_write("RTL8019 Ethernetcard\r\n");
#endif
}
Example #20
0
//Routine für das schreiben eines Puffers
uint8_t usart_write_buffer(const uint8_t *buffer, uint8_t len)
{
  while (len-->0) 
  {
    uint8_t retval = usart_write(*buffer++);
    if (retval!=0x80) return len;
  }
  return len;  
}
Example #21
0
//Routine für das schreiben eines Puffers aus dem Programmspeicher
uint8_t usart_write_buffer_p(const uint8_t *buffer, uint8_t len)
{
	while (len-->0)
	{
		uint8_t retval = usart_write(pgm_read_byte(buffer++));
		if (retval!=0x80) return len;
	}
	return len;
}
Example #22
0
unsigned int usart_printf(const char* fmt, ...)
{
  char buf[255];
  va_list va;
  va_start(va, fmt);
  int length = vsnprintf(buf, 255, fmt, va);
  va_end(va);
  return usart_write(buf, length);
}
Example #23
0
/**
 * \ingroup usartcmdline
 * \b TCP-Befehl zeige TCP-Tabelle
 */
int16_t command_tcp (char *outbuffer)
{
	if (outbuffer)					// momentan nur bei USART
		return cmd_502(outbuffer);

	for (unsigned char index = 0;index<MAX_TCP_ENTRY;index++)
	{
		usart_write("%2i",index);
		usart_write("  IP:%3i",(tcp_entry[index].ip&0x000000FF));
		usart_write(".%3i",((tcp_entry[index].ip&0x0000FF00)>>8));
		usart_write(".%3i",((tcp_entry[index].ip&0x00FF0000)>>16));
		usart_write(".%3i",((tcp_entry[index].ip&0xFF000000)>>24));
		usart_write(" SRC_PORT:%4i",HTONS(tcp_entry[index].src_port));
		usart_write(" DEST_PORT:%4i",HTONS(tcp_entry[index].dest_port));
		usart_write(" Time:%4i\r\n",tcp_entry[index].time);
	}
	return 0;
}
Example #24
0
//void xb_set_reg(const char *command, char *rs)
void xb_set_reg(char *command, char *rs)
{
	/* Write value to an XBee register. 
	 * Returns OK or maybe ERROR. */
	usart_text("AT");
	usart_text(command);
	usart_write('\r');
	xb_response(rs);
}
Example #25
0
/** Write character.  */
int
usart_putc (usart_t usart, char ch)
{
    int ret;
    
    ret = usart_write (usart, &ch, 1);
    if (ret == 1)
        return ch;
    return ret;
}
Example #26
0
//void xb_get_reg(const char *command, char *rs)
void xb_get_reg(char *command, char *rs)
{
	/* Read the value of an XBee register.
	 * Returns a value of the register or 
	 * maybe ERROR. */
	usart_text("AT");
	usart_text(command);
	usart_write('\r');
	xb_response(rs);
}
Example #27
0
//------------------------------------------------------------------------------
// print Temperaturen
void command_ow (void)
{
// ist schon in main.c erwähnt !!!
// Speicherplatz für 1-wire Sensorwerte
    extern volatile int16_t ow_array[MAXSENSORS];
    uint8_t i;
    int16_t TWert;
    for(i=0; i<MAXSENSORS; i++)
    {
        TWert = ow_array[i];
        usart_write ("Sensor %i: ",i);
        // Vorzeichen
        if ( ow_array[i] < 0 ) {
            usart_write ("-");
            TWert *= (-1);
        }
        usart_write ("%i,%i\r\n",(TWert/10),(TWert%10));
    }
}
Example #28
0
/**
 * \ingroup usartcmdline
 * \b OW-Befehl T-Werte der fixen DS18x20 anzeigen
 */
int16_t command_OWread(char *outbuffer)
{
	if (outbuffer)					// nur bei USART
		return cmd_502(outbuffer);

	#if USE_OW
	uint8_t i;

	lese_Temperatur();

	usart_write("\r\nFixed T-Sensor Werte:");
	for (i=0; i<MAXSENSORS; i++) {
		usart_write("\r\n%i: %i",(i+1),ow_array[i]);
	}

	usart_write("\r\n");
	#endif
	return 0;
}
Example #29
0
/** Write formatted output to the debug UART. */
void debug_printf(const char *fmt, ...)
{
    va_list ap;
    char buf[128];

    va_start(ap, fmt);
    vsnprintf(buf, sizeof(buf), fmt, ap);
    usart_write(DEBUG_UART, (uint8_t *)buf, strlen(buf));
    va_end(ap);
}
Example #30
0
/**
 * \ingroup tcpcmdcommon
 * \b MAC-Befehl zeige eigene MAC-Adresse
 */
int16_t command_mac (char *outbuffer)
{
	if (outbuffer) {
		sprintf_P(outbuffer,PSTR("250 ok. My MAC: %2x:%2x:%2x:%2x:%2x:%2x\r\n"),mymac[0],mymac[1],mymac[2],mymac[3],mymac[4],mymac[5]);
		return strlen(outbuffer);
	}
	else {
		usart_write("My MAC: %2x:%2x:%2x:%2x:%2x:%2x\r\n",mymac[0],mymac[1],mymac[2],mymac[3],mymac[4],mymac[5]);
		return 0;
	}
}