Exemplo n.º 1
0
void sendShClockEdge(){
    char cmds[10];
//  PORTD = PORTD & (~ _BV(SR_SHCP));
  PORTC = PORTC & (~ _BV(SR_SHCP));
  #if SINGLE_STEP_BIT_LCD  
  USART_Transmit_String("Sh-Low");  
    while(USART_Receive_String(cmds, 30) <=0)
        asm("nop");
  #endif

//  PORTD = PORTD | _BV(SR_SHCP);
  PORTC = PORTC | _BV(SR_SHCP);
  #if SINGLE_STEP_BIT_LCD  
  USART_Transmit_String("Sh-High");  
    while(USART_Receive_String(cmds, 30) <=0)
        asm("nop");
  #endif
//  PORTD = PORTD & (~ _BV(SR_SHCP));
  PORTC = PORTC & (~ _BV(SR_SHCP));
  #if SINGLE_STEP_BIT_LCD  
  USART_Transmit_String("Sh-Low");  
    while(USART_Receive_String(cmds, 30) <=0)
        asm("nop");
  #endif
    }
Exemplo n.º 2
0
int
main (void) {
  char msg[30];
  unsigned char c; int i=0;
  int counter[3];
ioinit();
  //initTimer();
  initTimer2();
  initPWM();
  initLCD();
  //initPWM();
  USART_Transmit_String("Restarting..\r\n");
        wait(10);
    //LCD_gotoXY(1,0);
    //LCD_Write("Out-PWM-BC1");
     while (1) {
      unsigned int en, en1;
      asm("nop");
      cli();
       en = topup_timer2;
       en1 = timestamp[0];
      sei();
      sprintf(msg, "%04x,%04x", en, en1);
      USART_Transmit_String(msg);
      LCD_gotoXY(0,0);
      LCD_Write(msg);
    }
    return 0;
}
Exemplo n.º 3
0
int
main (void)
{
  int i;
  char testIntStr[20];

  ioinit ();
USART_Transmit_String("Restarted: "); 
//USART_Transmit_String2("This is a test..");

USART_Transmit_String("How are you???");
itoa(0x23,testIntStr,16);
USART_Transmit_String2(testIntStr);
USART_Transmit_String2("Very well, thank you???");
USART_Transmit_String2("Very well, thank you7???");

//USART_Receive_String();
USART_Transmit_String2("This is what is typed in ..");
USART_Transmit_String2(USART_Receive_String());
#if STATS_ENABLED
USART_PrintStats();
#endif
USART_Transmit_String2("Very well, thank you8???");

/* this probably is taken care of by gcc main program exit */
 while(1) {
  asm("nop");
  }
  return (0);
}
Exemplo n.º 4
0
void endGame() { //konczenie gry
	isStarted = 0; //zatrzymujemy gre
	isEnded = 1; //konczymy
	player = 1; //zmieniamy gracza do nastepnej rozgrywki na 1
	updateDisplay(9999);
	if (playerOneTime < playerTwoTime) { //wygral gracz pierwszy
		USART_Transmit_String("Wygrywa Gracz 1! Gratulacje!");
		USART_Transmit(10); //nowa linia
		USART_Transmit(13); //powrot karetki
	} else if(playerOneTime > playerTwoTime) {
		USART_Transmit_String("Wygrywa Gracz 2! Gratulacje!");
		USART_Transmit(10); //nowa linia
		USART_Transmit(13); //powrot karetki
	} else {
		USART_Transmit_String("Remis! Gratulacje!");
		USART_Transmit(10); //nowa linia
		USART_Transmit(13); //powrot karetki
	}
    
	USART_Transmit_String("Czas gracza pierwszego: ");
	char tmp[5];
	int i= 0;
	for(i = 0; i < 5; i++) {
		tmp[i] = 0;
	}
	itoa(playerOneTime, tmp, 10);
	USART_Transmit_String(tmp);
	USART_Transmit(10); //nowa linia
	USART_Transmit(13); //powrot karetki
	USART_Transmit_String("Czas gracza drugiego: ");
	for(i = 0; i < 5; i++) {
		tmp[i] = 0;
	}
	itoa(playerTwoTime, tmp, 10);
	USART_Transmit_String(tmp);
	USART_Transmit(10); //nowa linia
	USART_Transmit(13); //powrot karetki
	USART_Transmit_String("Roznica: ");
	for(i = 0; i < 5; i++) {
		tmp[i] = 0;
	}
	itoa(calculateDistance(playerOneTime, playerTwoTime), tmp, 10);
	USART_Transmit_String(tmp);
	USART_Transmit(10); //nowa linia
	USART_Transmit(13); //powrot karetki
    
	playerOneTime = 0; //zerujemy czasy obu graczy
	playerTwoTime = 0;
	clearAndSetZeroPosition(); //czyscimy wyswietlacz i wracamy na poczatek
	sendString("Jeszcze raz?");
	setPosition(0x28); //40 to pozycja pierwsza na dole
	sendString("Wcisnij klawisz");
}
Exemplo n.º 5
0
/* The main function */
int main(void)
{
	// Pin configurations
	DDRB = 0xff;	// all output; only one heartbeatLED used
	DDRC = 0x00;	// all input; the I2C special pin functions overrule this anyways
	DDRD = 0x00;	// all input
	PORTC = 0x00;	// all pullups off; the breakout board has its own 1k pullups attached
	
	// Initialise the serial communication interface. Note that this now also sets up the interrupts!
	struct USART_configuration config_57600_8N1 = {57600, 8, 0, 1};
	USART_Init(config_57600_8N1);
	
	
	// I2C initialisation
	TWBR = 12;									// 400 kHz at 16MHz crystal and no prescaler
	TWSR &= ~((1 << TWPS1) | (1 << TWPS0));		// prescaler 0
	TWDR = 0xFF;								// sending only ones equals an idle high SDA line
	TWCR = (1<<TWEN)|							// Enable TWI-interface and release TWI pins.
			(0<<TWIE)|(0<<TWINT)|				// Disable Interupt.
			(0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|	// No Signal requests.
			(0<<TWWC);							//
	
	sei();									// set interrupts (globally enabled)
	
	
	
	USART_Transmit_String("Welcome to the TMP102 I2C temperature sensor test!\r\n");
	
	int16_t temperature = 0;
	char buffer[10];

	while(1)
	{
		temperature = tmp102Read();
		USART_Transmit_String("Temperature: ");
		buffer[0] = '\0';
		itoa(temperature, buffer, 10);
		USART_Transmit_String(buffer);
		USART_Transmit_String(" deg. Celsius\r\n");
		
		PORTB ^= (1 << 5);	// heartbeat LED
		
		_delay_ms(500);
	}
}
Exemplo n.º 6
0
void sendDataToLCD(unsigned char data, int delay) {
    unsigned int i, bit;
    char cmds[10];
  #if SINGLE_STEP_LCD
    sprintf(cmds, "%02x\r\n", data);
    USART_Transmit_String(cmds);
  #endif
    data = data << 1;
    for(i=0;i<8;i++) { 
    /* though only 4bits are relevant, lets do it all */
      /* extract bit - highest bit first on shift, 
      it goes to MSB, after 8 shifts */
      bit = data & (1 << (7-i));

      if(bit) {
//        PORTD = PORTD | _BV(SR_DS);
        PORTC = PORTC | _BV(SR_DS);
      #if SINGLE_STEP_BIT_LCD
        USART_Transmit_String("1");
        #endif
      }
      else {
        #if SINGLE_STEP_BIT_LCD
        USART_Transmit_String("0");
      #endif
//        PORTD = PORTD & (~ _BV(SR_DS));    
        PORTC = PORTC & (~ _BV(SR_DS));    
      }
      /* time to clock it in */
      sendShClockEdge();
     #if SINGLE_STEP_LCD    
    while(USART_Receive_String2(cmds, 30) <=0)
        asm("nop");
    #endif
    }
    
    /* now move out data to output register */
    sendStClockEdge();
    /* now let it be registered by LCD */
    enableLCD(delay);
 //   USART_Transmit_String2(cmds);
}
Exemplo n.º 7
0
void checkResult() { //sprawdzanie czy to co wpisalismy jest prawidlowe
	uint32_t res = atoi(result);
	if(tries == 0 && failedTries == 0) { //jezeli zaczynamy
		if(player == 1) {
			USART_Transmit(10); //nowa linia
			USART_Transmit(13); //powrot karetki
			USART_Transmit_String("Gracz 1:");
			USART_Transmit(10); //nowa linia
			USART_Transmit(13); //powrot karetki
		} else {
			USART_Transmit(10); //nowa linia
			USART_Transmit(13); //powrot karetki
			USART_Transmit_String("Gracz 2:");
			USART_Transmit(10); //nowa linia
			USART_Transmit(13); //powrot karetki
		}
	}
	if(expectedResult == res) { //zgadlismy
		tries++; //zwiekszamy ilosc prob na ktore dobrze odpowiedzielismy
		USART_Transmit_String("Dobrze!");
		USART_Transmit(10); //nowa linia
		USART_Transmit(13); //powrot karetki
		USART_Transmit_String("Twoj aktualny czas: ");
		char tmp[5];
		int i= 0;
		for(i = 0; i < 5; i++) {
			tmp[i] = 0;
		}
		itoa(time, tmp, 10);
		USART_Transmit_String(tmp); //wyswietla aktualny czas
		USART_Transmit(10); //nowa linia
		USART_Transmit(13); //powrot karetki
	} else {
		failedTries++;
		USART_Transmit_String("Zle!");
		USART_Transmit(10); //nowa linia
		USART_Transmit(13); //powrot karetki
		USART_Transmit_String("Twoj aktualny czas: ");
		char tmp[5];
		int i= 0;
		for(i = 0; i < 5; i++) {
			tmp[i] = 0;
		}
		itoa(time, tmp, 10);
		USART_Transmit_String(tmp);
		USART_Transmit(10); //nowa linia
		USART_Transmit(13); //powrot karetki
		printGoodResult(expectedResult);
		TASK_TABLE[3].timeout = 3000; //uaktywniamy task czyszczenia
		TASK_TABLE[3].timetogo = 3000;
	}
}
Exemplo n.º 8
0
void sendStClockEdge(){
    char cmds[10];
  PORTD = PORTD & (~ _BV(SR_STCP));
  #if SINGLE_STEP_BIT_LCD  
  USART_Transmit_String("St-Low");
    while(USART_Receive_String(cmds, 30) <=0)
        asm("nop");
  #endif
  PORTD = PORTD | _BV(SR_STCP);
  #if SINGLE_STEP_BIT_LCD  
    while(USART_Receive_String(cmds, 30) <=0)
        asm("nop");
  USART_Transmit_String("St-High");
  #endif
  PORTD = PORTD & (~ _BV(SR_STCP));
  #if SINGLE_STEP_BIT_LCD    
  USART_Transmit_String("St-Low");
    while(USART_Receive_String(cmds, 30) <=0)
        asm("nop");
  #endif
}
Exemplo n.º 9
0
int
CProbabilisticNetwork::Load()
{
    mMode = 2;
    mDirected = 0;
    mMoral = 1;
    mTriangular = 1;
    mEliminationTree = 1;


    mNodeArray[0].Load(0, "Visit to Asia?", "NoVisit", "Visit", 8, 0);
    mNodeArray[1].Load(1, "Tuberculosis?", "Absent", "Present", 7, 0);
    mNodeArray[2].Load(2, "Smoking?", "NonSmoker", "Smoker", 6, 0);
    mNodeArray[3].Load(3, "Lung Cancer?", "Absent", "Present", 5, 0);
    mNodeArray[4].Load(4, "Bronchitis?", "Absent", "Present", 3, 0);
    mNodeArray[5].Load(5, "TuberculosisOrLungCancer?", "Nothing", "CancerOrTuberculosis", 2, 0);
    mNodeArray[6].Load(6, "X-RayResults", "Normal", "Abnormal", 4, 0);
    mNodeArray[7].Load(7, "Dyspnea?", "Absent", "Present", 1, 0);
    mNodeArray[8].Load(7, "Dys", "Normal", "Abnormal", 9, 0);

    USART_Transmit_String("\n\r");
    USART_Transmit_String("\n\r");
    int i;
    for ( i=0; i<9; i++)
    {
        USART_Transmit_String("\n\r");
        USART_Transmit_String(mNodeArray[i].mName);
        USART_Transmit_String(mNodeArray[i].mStateNameArray[0]);
        USART_Transmit_String(mNodeArray[i].mStateNameArray[1]);
    }

    return 1;

}
Exemplo n.º 10
0
int
main (void)
{
  char msg[30];
  unsigned char c; int i=0;
  int counter[3];
  ioinit();
  USART_Transmit_String("Restarting..\r\n");
     while (1) {
         /*if (PINB & (1<<3))
             PORTB &= ~0x02;
         else
             PORTB |= 0x02;*/
           cli();
          counter[0] = gCounter1[0];
          counter[1] = gCounter1[1];
          counter[2] = gCounter1[2];
          sei();
        sprintf(msg, "Ctr:%04x, %04x, %04x\r\n", counter[0], counter[1],counter[2]);
        USART_Transmit_String(msg);
    }
    return 0;
}
Exemplo n.º 11
0
void ioinit() {

USART_Init(51); 
/* IMPORTANT: 41 values works with -mmcu=avr5, where it should have been */
/* IMPORTANT: 51 works with -mmcu=atmega328p, strange.. what is the secret here???*/

//Below code may be removed, i believe this was for PWM
//TCCR1B = (TCCR1B & 0xF8) | 0x01;
//TIMSK1 = TIMSK1 | _BV(TOIE1);

initTimer();
USART_Transmit_String("Restarted: "); 
initLCD();
sei ();
}
Exemplo n.º 12
0
int main( void )
{

	_delay_ms(500);
     USART_Init();
	 while(1)
	 {
	 USART_Transmit_Char('a');

	 _delay_ms(100);
	USART_Transmit_String("Hallo Welt\n");
	_delay_ms(100);

	}

	 
}
Exemplo n.º 13
0
void wait(int ms) {
unsigned int ts[2], t[2];
char msg[30];
    cli();
            ts[0] = timestamp[0];
            ts[1] = timestamp[1];
    sei();
    /* suspected area of system hang, to be removed after fix*/
    sprintf(msg, "W:%04x%04x,%04x%04x", ts[1],ts[0], timestamp[1], timestamp[0]);
    USART_Transmit_String(msg);
    /* suspected area of system hang, to be removed after fix - ends*/

    if((0xFFFF - ts[0]) < ms) {
        ts[1] += 1;
        ts[0] = ms-(0xFFFF - ts[0]);
    } else
      ts[0] += ms;
 while(1) {
    asm("nop");
    asm("nop");
    asm("nop");
    asm("nop");
    cli();
            t[0] = timestamp[0];
            t[1] = timestamp[1];
    sei();
    /* suspected area of system hang*/
    if(ts[1] > timestamp[1]) {
    } else if(ts[1] == timestamp[1]) {
        if(ts[0] > timestamp[0]) {
          // still to wait
        } else {
            break; //time up
        }
    } else if(ts[1] < timestamp[1]) {
      break; //time up
    }
 }    
}
Exemplo n.º 14
0
void initLCD() {
    int i;
  DDRD = DDRD | _BV(4) |_BV(5) ;
  DDRC = DDRC | _BV(2) |_BV(1) ;
  sendDataToLCD(0x03,LCD_DELAY);
  USART_Transmit_String("First init");
  sendDataToLCD(0x03,LCD_DELAY);
  USART_Transmit_String("Second init");
  sendDataToLCD(0x03,LCD_DELAY);
  USART_Transmit_String("Third init");
  for(i=0; i < 1000; i++) {
    asm("nop");
  }

  /* Set 4-bit interface */
  sendDataToLCD(0x02,LCD_DELAY);
   USART_Transmit_String("4-bit");
 /* send command to setup font etc */
  sendDataToLCD(0x02,0);
  sendDataToLCD(0x0C,LCD_DELAY);
  /* off display */
    USART_Transmit_String("Off display");
    sendDataToLCD(0x00,0);
    sendDataToLCD(0x08,LCD_DELAY);
  /* clear display */
    sendDataToLCD(0x00,0);
    sendDataToLCD(0x01,LCD_DELAY_CLEAR);
 /* entry mode set */
    sendDataToLCD(0x00,0);
    sendDataToLCD(0x06,LCD_DELAY);
/* on display */
    sendDataToLCD(0x00,0);
    sendDataToLCD(0x0D,LCD_DELAY);
  USART_Transmit_String("LCD Cmd Over");

/* Send cursor to home */
   sendDataToLCD(0x00,0);
   sendDataToLCD(0x01,LCD_DELAY);  
}
Exemplo n.º 15
0
void Service_send_ERROR(char *text) //wyslanie informacji o niepowodzeniu przeprowadzonej operacji
{
	USART_Transmit(UART_CMD_ERROR);
	USART_Transmit_String(text);
	USART_Transmit(UART_EOT);
}