예제 #1
0
void lcd_tryb()
{
	sensors_debug();
//	motor_debug();
	return;
	
	if(lcd_old != tryb)
	{
		LCD_Clear();
		switch(tryb)
		{
			case 0:
				LCD_WriteText("=[Wybierz tryb]=");
				LCD_GoTo(0, 1);
				LCD_WriteText("/|:pad O:auto");
				break;
			case 1:
				LCD_WriteText("Tryb: pad");
				break;
			case 2:
				LCD_WriteText("Tryb: czujniki");
				break;
		}
		
		lcd_old = tryb;
	}			
}
예제 #2
0
int main()  {

	ADC_Init();

	 LCD_Initalize();
     LCD_Clear();
     LCD_Lightness(20);

	while(1)  {


	 ADCSRA |= (1<<ADSC);		//uruchomienie poj. konwersji
	      while(ADCSRA & (1<<ADSC));	//zakonczenie poj. konwersji

	        char ADC_char[32];
	        char volt_char[32];
	        volatile float v_in;
	        const float v_ref = 5.00f;

	        v_in = (ADC*v_ref)/1024.0f;

	        sprintf(ADC_char, "10bit=%d",ADC);
	        sprintf(volt_char,"U[V]=%1.2f",(double)v_in);


	      LCD_Clear();
          LCD_GoTo(0,0);
      	  LCD_WriteText(ADC_char);
      	  LCD_GoTo(0,1);
      	  LCD_WriteText(volt_char);

      	  _delay_ms(50);
	}

}
예제 #3
0
void clear_screen()
{
    LCD_GoTo(0,0);
    LCD_WriteText("                \0");
    LCD_GoTo(0,1);
    LCD_WriteText("                \0");
}
예제 #4
0
int main(void) 
 {  
	_delay_ms(100);	
	LCD_Initalize();
	LCD_WriteText("Anal Intruder 1");
	LCD_GoTo(0, 1);
	LCD_WriteText("8=======D (.)(.)");
	pad_init();
	motor_init();
	brzeczyk_init();
	sensors_init();
	sei();
	play(power, 11);
	
   while(1)
   {     		
		while(!pad_get_state()) // sprawdzenie po³¹czenia z padem
		{
			m1_stop();
			m2_stop();
			LCD_Clear();
			LCD_WriteText("Pad conn error!");
			LCD_GoTo(0, 1);
			LCD_WriteText("Reconnecting...");			
			_delay_ms(500);
			pad_init();
			tryb = 0;
			lcd_old = -1;
			motor_lcd = false;
		}

		lcd_tryb();
		switch(tryb)
		{
			case 0:				
				if(!(tab[4] & (1 << 4))) // jeœli wciœniêty trojkat
					tryb = 1;
				else if(!(tab[4] & (1 << 5))) // jeœli wciœniête jest kolko
					tryb = 2;
				break;			
			case 1:	
				pad_loop();
				break;
			case 2:		
				sensors_loop();				
				break;			
		}
		
		if(!(tab[3] & (1 << 3)))
		{		// jeœli wciœniêty start
			tryb = 0;
			m1_stop();
			m2_stop();
			srednia = 0;
		}
   }  
 }
예제 #5
0
파일: main.c 프로젝트: bzyx/smiw-rfm70
void printScreen(char screen[4][17]) {
	if (isChanged == 1) {
		LCD_Clear();
		isChanged = 0;
	}
	LCD_GoTo(0, 0);
	LCD_WriteText(screen[0]);
	LCD_GoTo(0, 1);
	LCD_WriteText(screen[1]);
	LCD_GoTo(0, 2);
	LCD_WriteText(screen[2]);
	LCD_GoTo(0, 3);
	LCD_WriteText(screen[3]);
}
예제 #6
0
파일: main.c 프로젝트: bzyx/smiw-rfm70
void printScreenWithCenter(char screen[4][17]) {
	if (isChanged == 1) {
		LCD_Clear();
		isChanged = 0;
	}
	LCD_GoTo(center(screen[0]), 0);
	LCD_WriteText(screen[0]);
	LCD_GoTo(center(screen[1]), 1);
	LCD_WriteText(screen[1]);
	LCD_GoTo(center(screen[2]), 2);
	LCD_WriteText(screen[2]);
	LCD_GoTo(center(screen[3]), 3);
	LCD_WriteText(screen[3]);
}
예제 #7
0
void wczytaj_haslo(int indeks)
{
	unsigned char Tekst[2];
	int i=0;
	char tab[5]={0,0,0,0,0};

	Tekst[0]=0;
	Tekst[1]=0;
	while (i<4)
	{
		Tekst[0]=KBD_ReadKey();
		if (Tekst[0] !=0 )
		{
			tab[i]=Tekst[0];
			i++;
			wyswietl_gwiazdki(i);
			Tekst[0]=0;
		}
		delay_10us();
	}
	tab[4]=0;

	i=0;
	int dobrze=0;
	char dane=0;
	uint16_t adres_hasla=(adres(indeks)+4);
	for(;i<4;i++)
	{
		dane=(Read_24Cxx(adres_hasla,M2404));
		if(tab[i]==dane)
		{
			dobrze++;
		}
		adres_hasla++;
	}

	LCD_WriteCommand(HD44780_CLEAR);
	LCD_GoTo(0,0);

	if(dobrze==4)
	{
		LCD_WriteText((unsigned char *)"Otwieram drzwi");
		Zamek1_On();
	}
	else
	{
		LCD_WriteText((unsigned char *)"Bledne haslo");
	}
 }
예제 #8
0
void wyswietl_gwiazdki(int ile)
{
	LCD_GoTo(0,1);
	int i;
	for (i= 0; i < ile; ++i)
	{
		LCD_WriteText((unsigned char *)"*");
	}
}
예제 #9
0
void LCD_WriteTwoDigit(char posx, char posy, int number)
{
    int offset = 0;
    if (number < 10) {
        string_buff[offset++] = '0';
    }
    itoa(number, &string_buff[offset], 10);
    LCD_GoTo(posx, posy);
    LCD_WriteText(string_buff);
}
예제 #10
0
int main(void)
{
		uint8_t text[8]="hello !";
    init_hardware();
	
		LCD_Init();
		LCD_WriteText(text);
		
    while(1){}
}
예제 #11
0
void show_default_screen(msg_t *msg)
{
    LCD_GoTo(8,0);
    get_time_str(string_buff);
    LCD_WriteText(string_buff);
    LCD_GoTo(4, 0);
    LCD_WriteText("k/h \0");
    int offset = 1;
    switch(msg->type) {
    case MSG_SECOND_CHANGE:
        offset = calculate_speed() > 99 ? 0 : 1;
        break;
    }
    if (offset > 0) {
        LCD_GoTo(0,0);
        LCD_WriteText(" \0");
    }
    get_current_speed(string_buff);
    LCD_GoTo(offset, 0);
    LCD_WriteText(string_buff);
}
예제 #12
0
int main()  {

	ADC_Init();

	USART_Init(9600);

	 LCD_Initalize();
     LCD_Clear();
     LCD_Lightness(20);

	while(1)  {

	 ADCSRA |= (1<<ADSC);		//uruchomienie poj. konwersji
	      while(ADCSRA & (1<<ADSC));	//zakonczenie poj. konwersji

	       char ADC_char[32];
	   	   char volt_char[32];
	   	   float v_in;
	   	   const float v_ref = 5.00f;

	   		  v_in = (ADC*v_ref)/1024.0f;

	   	sprintf(ADC_char, "10bit=%d",ADC);
	    sprintf(volt_char,"U=%1.2fV",(double)v_in);

	   		      LCD_Clear();
	   	          LCD_GoTo(3,0);
	   	      	  LCD_WriteText("Pomiar ADC");
	   	      	  LCD_GoTo(4,1);
	   	      	  LCD_WriteText(volt_char);

	   	      	  USART_publong(ADC_char);
	   	      	  USART_publong("  ");
	   	      	  USART_publong(volt_char);
	   	      	  USART_publong("\n");

      	  _delay_ms(50);
	}

}
예제 #13
0
int main(int argc, char * argv[])
{
	DDRA |= 0xFF;
	DDRB |= 0xFF;
	//PORTB = ~0x01;
	//PORTA = 0x00;
	timer0_init();
	LCD_Initalize();
	LCD_GoTo(0,0);
	LCD_WriteText("Dziao!");
	//AddTask(0,1000, AddSecond, NULL);
	AddTask(0, 1, ObslugaKlawiatury, NULL);
	execute();
}
예제 #14
0
void MPU_self_test(unsigned char mpuAdress){
		char buf[17]="                ";
		TWI_start();
		
		TWI_check_ack(mpuAdress);
		
		TWI_write_data(0x75);
		
		TWI_repeated_start();
		
		TWI_read_address(mpuAdress|0x01);
		
		char response = TWI_read_data();
		
		sprintf(buf,"Response:  %x",response);
		LCD_WriteText(buf);
		
		TWI_stop();
}
예제 #15
0
int main(void)
{
  volatile unsigned long int i;
  int temperatura;
  unsigned char temperaturaTekst[8]={" 0,0 C\0"};
	static const unsigned char stopienSymbol[8] = {0x06,0x09,0x09,0x06,0x00,0x00,0x00,0}; //symbol stopnia

  //konfiguracja systemu
  RCC_Config();   
  GPIO_Config(); 
  NVIC_Config();  
  SPI_Config(); 
  /*Tu nalezy umiescic ewentualne dalsze funkcje konfigurujace system*/
  GPIO_ResetBits(GPIOB, GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);		 

  LCD_Initialize();                                         //Inicjalizacja wysietlacza
  LCD_SetUserChar(1, 1, stopienSymbol);                     //Umiesc symbol stopnia pod kodem =1
  LCD_WriteCommand(HD44780_CLEAR);                          //Wyczysc wyswietlacz
  LCD_WriteText("Temp.:\0");        
  temperaturaTekst[5]=1;
  LCD_WriteTextXY(temperaturaTekst,7,0);                    //Wstaw do tekstu znak stopnia
  
  #define SPI_Mode_Slave_Mask ((unsigned short int)0xFEFB)  //Maska pozwalajaca wyzerowac bity trybu pracy wprost w rejestrzez SPIx->CR1
  while (1) {
    /*Tu nalezy umiescic glowny kod programu*/
    SPI1->CR1 |= SPI_Mode_Master;                           //Ustaw tryb master - wymusi to zmiane stanu NSS na niski
    while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); //Czekaj na dane
    temperatura = SPI_I2S_ReceiveData(SPI1);                //Odczytaj dane
    if ((temperatura&0x04)==0){                             //Sprawdz, czy zakonczono juz pierwszy pomiar po wlaczeniu ukladu TC77
      temperatura=0;                                        //Jesli nie, ustaw temp=0,  wprzeciwnym razie wynik bedzie bledny (>500stC)
    }
    temperatura = temperatura >> 3;                         //Usun 3 LSB
    SPI1->CR1 &= SPI_Mode_Slave_Mask;                       //Ustaw tryb slave - wymusi to zmiane stanu NSS na wysoki

		temperatura = (temperatura * 625)/100;                  //1 bit temperatury odpowiada 0,0625 stopnia
		sprintf((char *)temperaturaTekst, "%2d,%d C ", temperatura / 100, (temperatura % 100)/10 );
    temperaturaTekst[4]=1;                                  //Wstaw do tekstu znak stopnia
    LCD_WriteTextXY(temperaturaTekst,7,0);  
    for (i=0;i<4500000ul;i++); 
    GPIO_WriteBit(GPIOB, GPIO_Pin_15, (BitAction)(1-GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_15)));
  };
  return 0;
}
예제 #16
0
//-----funcja LCD_update_time	### aktualizacja czasu
void LCD_update_time()
{
	unsigned char temp;
	LCD_GoTo(8,1);
	itoa(hours/10,temp,10);
	LCD_WriteText(temp);
	itoa(hours%10,temp,10);
	LCD_WriteText(temp);
	LCD_WriteText(":");
	
	itoa(minutes/10,temp,10);
	LCD_WriteText(temp);
	itoa((minutes%10),temp,10);
	LCD_WriteText(temp);
	LCD_WriteText(":");
	
	itoa(seconds/10,temp,10);
	LCD_WriteText(temp);
	itoa(seconds%10,temp,10);
	LCD_WriteText(temp);
}
예제 #17
0
파일: main.c 프로젝트: bzyx/smiw-rfm70
int main(void) {
	uchar i;
	int intro = 1;
	static char reciveErrorCount = 0;
	static char carrierErrorCount = 0;

	wdt_enable(WDTO_1S);
	/* Even if you don't use the watchdog, turn it off here. On newer devices,
	 * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!
	 * RESET status: all port bits are inputs without pull-up.
	 * That's the way we need D+ and D-. Therefore we don't need any
	 * additional hardware initialization.
	 */

	usbInit();
	usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
	i = 0;
	while (--i) { // fake USB disconnect for > 250 ms
		wdt_reset();
		_delay_ms(1);
	}
	usbDeviceConnect();
	//sei();

	//Ports initialization and other piperials
	LCD_Initalize();
	LCD_Clear();

	/* About project screen */
	//LCD_GoTo(center("SMiW 2011/2012"), 0);
	//LCD_WriteText("SMiW 2011/2012");
	//LCD_GoTo(center("Marcin Jabrzyk"), 2);
	//LCD_WriteText("Marcin Jabrzyk");
	irmp_init(); //IR libary
	timer_init(); //IR timmer and ADC starter
	adc_init(); //ADC configuration

	cli();
	intro = 0;
	if (RFM70_Initialize(0, (uint8_t*) "Smiw2")) {
		LCD_GoTo(center("Init RFM70"), 2);
		LCD_WriteText("Init RFM70");
		_delay_ms(100);
	} else {
		LCD_GoTo(center("ERR init RFM70"), 1);
		LCD_WriteText("ERR init RFM70");
	}

	if (RFM70_Present()) {
		LCD_GoTo(center("RFM70 present"), 3);
		LCD_WriteText("RFM70 present");
	} else {
		LCD_GoTo(center("RFM70 not present"), 3);
		LCD_WriteText("RFM70 not present");
	}

	sei();
	for (;;) { /* main event loop */
		wdt_reset();
		usbPoll();

		if (RFM70_Present()) {
			sprintf(screenDebug[0], screenDebugTemplate[0], "OK");
		} else {
			sprintf(screenDebug[0], screenDebugTemplate[0], "ERROR");
		}

		if (Carrier_Detected()) {
			sprintf(screenDebug[1], screenDebugTemplate[1], "OK");
			carrierErrorCount = 0;
		} else {
			carrierErrorCount++;
		}

		if (carrierErrorCount > 50) {
			sprintf(screenDebug[1], screenDebugTemplate[1], "NONE");
		}

		char* _tempGrzejnik;
		if (Packet_Received()) {
			sprintf(screenDebug[2], screenDebugTemplate[2], "OK");
			Receive_Packet(message);

			//if from grzejnik starts with "a" else from piec
			_tempGrzejnik = strchr(message, 'a');

			if (_tempGrzejnik != NULL ) {
				strncpy(tempFromGrzejnik, _tempGrzejnik, 4);
				sprintf(screenCenter[2], screenCenterTemplate[2],
						_tempGrzejnik);
			} else {
				strncpy(tempFromPiec, message, 4);
				sprintf(screenCenter[1], screenCenterTemplate[1], message);
			}

			reciveErrorCount = 0;
		} else {
			reciveErrorCount++;
		}
		if (reciveErrorCount > 90) {
			sprintf(screenDebug[2], screenDebugTemplate[2], "WAIT");
		}

		if (irmp_get_data(&irmp_data)) { // When IR decodes a new key presed.
			lastKey = irmp_data.command; //Save the key
			itoa(irmp_data.command, lastKeyStr, 10); //Convert it to string
			sprintf(screenCenter[3], screenCenterTemplate[3], lastKeyStr);
			isChanged = 1;
			intro = 0;
		}
		if (intro == 0) {
			switch (lastKey) { //Change the view
			case 69:
				printScreenWithCenter(screenLeft);
				break; //CH-
			case 70:
				printScreen(screenCenter);
				break; //CH
			case 71:
				printScreenWithCenter(screenRight);
				break; //CH+
			case 82:
				printScreen(screenDebug);
				break;
			default:
				printScreen(screenCenter);
				break; //Any other key
			}
		}
		usbPoll();
	}
	return 0;
}
예제 #18
0
int main(void)
{
char temp, i;
LCD_Initialize();
DDRB = 0b00000000;
PORTB = 0b00001111;

DDRA = 0xFF;
ADC_Init();
int value = 0;
int calculations = 0;

	char dzialanie = 0;

	
	int digit = 0;




	do{

	int digit  = getADC(0);

	char sw0 = PINB & 0b00000001;
	char sw1 = PINB & 0b00000010;
	if(sw0 != 0b00000001) {
		state++;
		_delay_ms(300);
	}
	

	  char str[15];


	  sprintf(str, "%15d", lastValue);
	LCD_GoTo(1,0);
	LCD_WriteText(str);


	switch(state){
		case 0:		
			if(sw1 != 0b00000010){
				setNewValue(mappingLogToLinear(digit, digitMap, 10));			
				_delay_ms(300);
			}
				sprintf(str, "%15d", mappingLogToLinear(digit, digitMap,10));
				LCD_GoTo(1,1);
				LCD_WriteText(str);	
			break;
		case 1:
			if(sw1 != 0b00000010){
				setSign(mappingLogToLinear(digit, signMap, 2));
				power = 0;				
				_delay_ms(300);
			}
				switch(mappingLogToLinear(digit, signMap,2)){
					case 0:
					LCD_GoTo(1,1);
					LCD_WriteText("-");
					break;
					case 1:
					LCD_GoTo(1,1);
					LCD_WriteText("+");
					break;
				}
			break;
		case 2:
			if(sw1 != 0b00000010){
				doCalculations(mappingLogToLinear(digit, expressionMap, 4));
				power = 0;
				newValue=0;
				state = 0;			
				_delay_ms(300);
			}
				
				switch(mappingLogToLinear(digit, expressionMap,4)){
					case 0:
					LCD_GoTo(1,1);
					LCD_WriteText("+");
					break;
					case 1:
					LCD_GoTo(1,1);
					LCD_WriteText("-");
					break;
					case 2:
					LCD_GoTo(1,1);
					LCD_WriteText("*");
					break;
					case 3:
					LCD_GoTo(1,1);
					LCD_WriteText("/");
					break;
				}
			break;
		}


/*
	char sw0 = PINB & 0b00000001;
	char sw1 = PINB & 0b00000010;
	char sw2 = PINB & 0b00000100;
	char sw3 = PINB & 0b00001000;

	if(sw0 != 0b00000001) value++;
	if(sw1 != 0b00000010) value--;

	if(sw2 != 0b00000100) {
		if(dzialanie == 0) calculations += value;
		if(dzialanie == 1) calculations -= value;
		if(dzialanie == 2) calculations /= value;
		if(dzialanie == 3) calculations *= value;
			value = 0;
	}


	if(sw3 != 0b00001000) {
		dzialanie++;
		dzialanie = dzialanie % 4;
	}




	  char str[15];


	  sprintf(str, "%15d", calculations);
	LCD_GoTo(1,0);
	LCD_WriteText(str);

	  sprintf(str, "%15d", value);
	LCD_GoTo(1,1);
	LCD_WriteText(str);
	_delay_ms(300);

	
	if(dzialanie == 0){
		LCD_GoTo(0,0);
		LCD_WriteText("+");
	}

	if(dzialanie == 1){
		LCD_GoTo(0,0);
		LCD_WriteText("-");
	}
	
	if(dzialanie == 2){
		LCD_GoTo(0,0);
		LCD_WriteText("/");
	}
	
	if(dzialanie == 3){
		LCD_GoTo(0,0);
		LCD_WriteText("*");
	}*/
	}while(1);

return 0;
}
예제 #19
0
int main(void)
{
	double temp = 0;
	char bufor[16];
	char bufor2[16];
	int zadana = 40;
	int licznik_odczytow = 0;
	short grzanie = 0;
	short p_start = 0;
	short p_start_old = 0;
	//USTAWIENIE PORTU B JAKO WYJSCIE//
	DDRB = 0b11111111;
	//USTAWIENIE PORTU C JAKO WEJSCIE//
	DDRC = 0b0000000;
	PORTC = 0b111111;
	LCD_Initalize();
	
	while (1)
	{
		//WARTOSC<<BIT
		//PORTB |= 1<<0;
		//PORTB &= 0<<0;
		//// ODCZYT STANU PRZYCISKÓW I TEMPERATURY ////
		p_start = !(PINC & (1<<3)) & 0x01;
		if (!(PINC & (1<<5))) {
			zadana = zadana + 1;
		}
		if (!(PINC & (1<<4))) {
			zadana = zadana - 1;
		}
		if ( (p_start == 1) & (p_start_old == 0) ) {
			grzanie = !grzanie;
		}
		p_start_old = p_start;
		if (licznik_odczytow == max_licznik) {
			temp = ds18b20_gettemp();
			dtostrf(temp,5,1,bufor);
		}
		licznik_odczytow++;
		if(licznik_odczytow > max_licznik) {
			licznik_odczytow = 0;
		}
		if (grzanie == 1) {
			if (temp > zadana + histereza) {
				PORTB &= 0<<7;
				PORTB |= 1<<0;
			}
			if (temp < zadana - histereza) {
				PORTB |= 1<<7;
				PORTB |= 1<<0;
			}
		}
		else {
			PORTB &= 0<<0;
			PORTB &= 0<<7;
		}
		
		LCD_Clear();
		LCD_Home();
		sprintf(bufor2,"Z:%d%cC A:     %cC",zadana,0xdf,0xdf);
		LCD_WriteText(bufor2);
		LCD_GoTo(9,0);
		LCD_WriteText(bufor);
		LCD_GoTo(0,1);
		LCD_WriteText("Grzanie:");
		LCD_GoTo(10,1);
		if (grzanie == 1) {
			LCD_WriteText("WL");
		}
		else {
			LCD_WriteText("WYL");
		}
		_delay_ms(140);
		
	}
}
예제 #20
0
int
main(int argc, char* argv[])
{
	volatile FATFS 		fatfs = {0};
	volatile FRESULT 	result;
	uint8_t 			fifo_command = 0;
	uint8_t				file_index = 0;



    ResetRCC();
    RCC_SetClockFrequency(PLLM_macro, PLLN_macro, PLLQ_macro, PLLP_macro);

    //  Enable clocks for the peripherals
    /*
     * 	GPIOA	-	NEC_CONTROLLER, TIM1 PWM, DAC
     * 	GPIOB	- 	SPI2
     * 	GPIOC	-	HD44780 Led Display
     * 	GPIOD	-	LED diodes, USART2(Log)
     */
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN |  RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIODEN;
    RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
    RCC->APB1ENR |= RCC_APB1ENR_TIM7EN | RCC_APB1ENR_SPI2EN | RCC_APB1ENR_USART2EN | RCC_APB1ENR_DACEN;


    /*< Configure board's leds to signal states */
    GPIO_OutputConfigure(GPIOD, PIN_12 | PIN_13 | PIN_14 | PIN_15, gpio_otyper_push_pull, gpio_speed_high, gpio_pupd_pull_down);
    /*< Configure NVIC Interrupt controller */
    //  Set two bits (out of four) as the main priority. The rest bits are used for preemptive priorities
    NVIC_SetPriorityGrouping(NVIC_PriorityGroup_2);
    NVIC_Enable_Interrupts();

    /*< Configure USART2 module to create program log */
    UART_Config(USART2, USART_CR1_UE | USART_CR1_TE, 19200,false);
    GPIO_AlternateFunctionPrepare(GPIOD, PIN_5, gpio_otyper_push_pull, gpio_speed_medium, gpio_pupd_pull_up);
    GPIO_AlternateFunctionSet(GPIOD,PIN_5, AF7);
    Log_Uart("##### LOG START #####\n\r");

    /*<	MCO2 Pin configuration to watch the CPU Clock signal with an oscilloscope*/
    Log_Uart("Clock output pin configuration in progress...\n\r");
    RCC->CFGR |= RCC_CFGR_MCO2PRE_2 | RCC_CFGR_MCO2PRE_1;
    RCC->CFGR &= ~RCC_CFGR_MCO2;
    GPIO_AlternateFunctionPrepare(GPIOC, PIN_9, gpio_otyper_push_pull, gpio_speed_fast, gpio_pupd_no_pull);
    GPIO_AlternateFunctionSet(GPIOC,PIN_9, AF0);

    /*<	SysTick configuration */
    Log_Uart("SysTick configuration in progress...\n\r");
    SysTick_Config(SYSTICK_CLK_DIVIDER);	//	Configure SysTick to make a tick every 1 us
    SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);


    /*< PWM signal configuration */
    Log_Uart("PWM generation module configuration in progress...\n\r");
    GPIO_AlternateFunctionPrepare(GPIOA, PIN_8, gpio_otyper_push_pull, gpio_speed_fast, gpio_pupd_pull_down);
    GPIO_AlternateFunctionSet(GPIOA, PIN_8, AF1);	//	Pin for PWM signal
    TIM_PWMConfigure(TIM1, 168, 5000, 4000, TIM_Channel_1);
    TIM_Start(TIM1);
    /*< HD44780 display configuration */
    LCD_Config();


    /*< Remote controller receiver initialization */
    Log_Uart("IR remote controller configuration in progress...\n\r");
    NEC_Remote_Init();
    TIM_Start(TIM6);

    /*< SPI Module configuration. It is used to communicate with the SD card */
    Log_Uart("SPI module configuration in progress...\n\r");
    SPI_Master_Init(SPI2, SPI_FREQ_PCLK_DIV_256, SPI_CPOL0_CPHA0, SPI_BIT_ORDER_MSB_FIRST, true);

    /*< DAC configuration */
    DAC_Init(dac_dual_channel_simultanous, dac_trigger_tim7, true);

    /*< Timer 7 used to trigger the DAC config */
    TIM_Basic_Continuous_Counting(TIM7, 12);

    /*< Remote Controller command fifo configuration */
    Log_Uart("FIFO configuration in progress...\n\r");
    Fifo_Init(&remote_command_fifo, remote_command_queue, sizeof(remote_command_queue));


    TIM6->CR1 |= TIM_CR1_CEN;	/*< Continuously ticking timer, used in NEC IR remote */

    Log_Uart("Configuration OK!\n\r");




    TCHAR disk[] = "0";
    UINT byte_number;
    result = f_mount(&fatfs, disk, 1);

    uint16_t bytes;
   /* result = SD_Find_File_Name_Containing("/", "*.wav");
    result = SD_Get_File_List("/");
    result = f_open(&sd_current_file, &sd_files_list[3], FA_READ);
    result = Wav_Get_File_Header(&sd_current_file);
*/
    //	Initially, get the files list
    state = STATE_GET_FILES_LIST;

  while(1)
  {
	  switch(state)
	  {
		 /* case STATE_WAIT:
			  break;*/

		  case	STATE_GET_FILES_LIST:
		  {
			  result = SD_Find_File_Name_Containing("/", "*.wav");
			  if(result == FR_NO_FILE)
			  {
				  LCD_WriteText("Brak plikow .wav");
				  // Go to sleep in this case
				  while(1)
				  {
					  __WFI();
				  }
			  }
			  else
			  {
				  LCD_WriteText(sd_files_list[0]);
			  }
			  state = STATE_EXECUTE_USER_REQUESTS;
			  break;
		  }

		  case STATE_READ_SAMPLES:
		  {
			  //	If we didn't get to the end of file yet...
			  if(!f_eof(&sd_current_file))
				  //	... Then read next sample chunk
				  f_read(&sd_current_file, empty_data_buf_ptr, 512, &read_data_byte_counter);
			  else
				  // 	...	Else set the end of file flag
				  wav_eof = true;
			  state = STATE_EXECUTE_USER_REQUESTS;
			  break;
		  }

		  case STATE_EXECUTE_USER_REQUESTS:
		  {
			  do
			  {
				  Fifo_Get(&remote_command_fifo, &fifo_command);

				  switch(fifo_command)
				  {
					  case NEC_CH_PLUS:
					  {
						  //	Disable when the wav_file is currently played
						  if(!wav_file_playing)
						  {
							  wav_file_chosen = false;
							  if(file_index < sd_number_of_files_in_dir-1)
								  file_index++;

							  LCD_WriteText(sd_files_list[file_index]);
						  }
						  break;
					  }
					  case NEC_CH_MINUS:
					  {
						  //	Disable when the wav_file is currently played
						  if(!wav_file_playing)
						  {
							  wav_file_chosen = false;
							  if(file_index > 0)
								  file_index--;
							  LCD_WriteText(sd_files_list[file_index]);
						  }
						  break;
					  }
					  case NEC_CH:
					  {
						  //	Disable when the wav_file is currently played
						  if(!wav_file_chosen)
						  {

							  //	If the file is already opened then close it
							  if(sd_current_file.fs != 0)
								  f_close(&sd_current_file);
							  //	...Open the chosen file
							  f_open(&sd_current_file, sd_files_list[file_index], FA_READ);
							  //	Get the chosen files header
							  WAV_Get_File_Header(&sd_current_file);
							  //	Prepare the triggering timer frequency
							 // WAV_Set_Trigger_Frequency(TIM7);
							  TIM_Set_Timer_Max_Count(TIM7, (uint16_t)(TIM7_FREQ/current_wave_header.byte_field.sample_rate));
							  //	Get the rest audio file info
							  //f_read(&sd_current_file, sd_data_buffer, current_wave_header.byte_field.subchunk_2_size, &read_data_byte_counter);
							  //	Get the first portion of data

							  //	Set the wav_file_chosen flag
							  wav_file_chosen = true;
							  //	Clear the wav_eof flag
							  wav_eof  = false;

						  }
						  break;
					  }
					  case NEC_PLAY_PAUSE:
					  {
						 if(!wav_file_playing && wav_file_chosen)
						 {
							//	Clear the timer's counter
							TIM_Clear(TIM7);
							TIM7->DIER |= TIM_DIER_UIE;
							empty_data_buf_ptr = sd_data_buffer;
							  f_read(&sd_current_file, sd_data_buffer, sizeof(sd_data_buffer), &read_data_byte_counter);

							  f_read(&sd_current_file, sd_data_buffer_additional, sizeof(sd_data_buffer_additional), &read_data_byte_counter);
							//	Start the DAC triggering timer
							TIM_Start(TIM7);
							//	Set the wav_file_playing_flag
							wav_file_playing = true;
						 }
						 else
						 {
							 //	Stop the DAC triggering timer
							 TIM_Stop(TIM7);

							 //	Clear the wav_file_playing_ flag
							 wav_file_playing = false;
						 }
						 break;
					  }

					  default:
						  break;
				  }
				  fifo_command = 0;
			  }while(!Fifo_Empty(&remote_command_fifo));
			  break;
		  }
	  }
  }
}
예제 #21
0
int main(void)
{
    LCD_Initalize();
    LCD_GoTo(0, 0);                     // Set cursor to first char in first line
    LCD_WriteText("-= LCD READY =-");   // Display sample text

#ifdef HEART_BEAT
    SET_BIT(DDRB, PB0);
    SET_BIT(PORTB, PB0);
#endif

//    g_clock.handle_milisec = milisec_handler;
    g_clock.handle_second = second_handler;
    init_clock();
    init_keypad();
    sei();

    msg_t* msg = 0;
    int screen = DEFAULT_SCREEN;
    char screen_changed = 1;

    while(1) {
        while((msg = get_msg())) {
            switch(msg->type) {
            case MSG_INPUT:
                if (msg->size == BTN_0) {
                    if (screen == SETUP_TIME_SCREEN) {
                        set_clock(g_time_screen.hour, g_time_screen.minute);
                    }
                    ++screen;
                    screen %= SCREEN_COUNT;
                    screen_changed = 1;
                }
                break;

            default:
                break;
            }
            if (screen_changed) {
                clear_screen();
            }
            switch (screen) {
            case 0:
                show_default_screen(msg);
                break;

            case 1:
                show_setup_time_screen(screen_changed, msg);
                break;

            case -1:
                show_setup_diameter_screen();
                break;

            default:
            break;
            }
            screen_changed = 0;
            free_msg(&msg);
        }
        sleep_mode();
    }
    return 0;
}
예제 #22
0
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void LCD_WriteTextXY(char * text, u8 x, u8 y)
{
    lcd_gotoxy(x,y);
    LCD_WriteText(text);
}
예제 #23
0
int main(void)
{

//zdefiniowanie rejestrow wej??/wyj??
	DDRB = 0x40; 				
	DDRD = 0xFC; 						
	DDRA = 0xFF;       
	DDRA &=~ (1<<ADCIN);    	        		

	//inicjalizacja wy?wietlacza
	LCD_Initalize();
	LCD_GoTo(4,1);      
 	LCD_WriteText("ISKIERNIK");
   	_delay_ms(1000);
	LCD_GoTo(0,2);
   	LCD_WriteText("Kaza & Krajewski");
   	_delay_ms(2000);
    	LCD_Clear();

//wyzerowanie lub podci?gni?cie pod "1" wej??/wyj??
	PORTB = 0x3F; 		
	PORTD = 0xC3;			
	PORTA = 0x00;		

//zdefiniowanie zmiennych cz?stotliwo?ci sygna?ow steruj?cych silnikami oraz najwa?niejsze //obliczenia
	float fz = 80;		
	float k = 50/12; 			
	float pn1 = 80;
	int ppn1 = round(pn1);
	float pn2 = pn1/k; 		
	int ppn2 = round(pn2);
	float pp = 20;		
	float fp = (pp/60)*400;			
	float fn1 = (pn1/60)*400;
	float fn2 = (pn2/60)*400;
	float f1 = 400;			 
	float p1 = (f1/400)*60; 	
	int pp1 = round(p1);
	float f2 = f1/k; 			
	float p2 = (f2/400)*60; 	
	int pp2 = round(p2);

//Uruchomienie ADC, wewn?trzne napiecie odniesienia, tryb pojedynczej konwersji, preskaler //128, wej?cie PIN5, wynik do prawej
	ADCSRA = (1<<ADEN)|(1<<ADPS0)|(1<<ADPS1)|(1<<ADPS2);
	ADMUX  =  (1<<REFS1)|(1<<REFS0)|(1<<MUX2)|(1<<MUX0); 

//p?tla g?ownego programu
	while(1)
	{
		if(!(PINB & (1<<3)))				//przelacznik TRYB: AUTO / REKA
		{_delay_ms(10);tryb1 = 1;tryb2 = 0;LCD_Clear();s = 0;}

		if(!(PINB & (1<<4)))				//przelacznik TRYB: REKA / AUTO
		{_delay_ms(10);tryb2 = 1;tryb1 = 0;LCD_Clear();s = 0;}

//TRYB AUTO
		while(tryb2 == 1)											LCD_GoTo(5,0);      
			LCD_WriteText("Manual");
			LCD_GoTo(0,1);      
			LCD_WriteText("START");
			LCD_GoTo(0,2);      
			LCD_WriteText("POSITIONING");
			LCD_GoTo(0,3);      
			LCD_WriteText("SETTINGS");
//przycisk "DOWN"
			while(!(PIND &0x40))
			{
				_delay_ms(300);
				s = s - 1;
				if(s<0){s=2;}
			}
//przycisk "UP"
			while(!(PIND &0x80))
			{
				_delay_ms(300);
				s = s + 1;
				if(s>2){s=0;}
			}
//przemieszczanie kursora
			if(s==0)
			{
				LCD_GoTo(15,1);      
				LCD_WriteText("<");
				LCD_GoTo(15,2);      
				LCD_WriteText(" ");
				LCD_GoTo(15,3);      
				LCD_WriteText(" ");
			}
			if(s==1)
			{
				LCD_GoTo(15,1);      
				LCD_WriteText(" ");
				LCD_GoTo(15,2);      
				LCD_WriteText("<");
				LCD_GoTo(15,3);      
				LCD_WriteText(" ");
			}
			if(s==2)
			{
				LCD_GoTo(15,1);      
				LCD_WriteText(" ");
				LCD_GoTo(15,2);      
				LCD_WriteText(" ");
				LCD_GoTo(15,3);      
				LCD_WriteText("<");
			}
//podprogram wystartowania silnikow
			if(((s==0)&&(!(PIND &0x01))))
			{
				start = 1;
				i = 0;
				LCD_Clear();
				LCD_GoTo(0,0);      
			  	LCD_WriteText("Checking...");
				LCD_GoTo(0,2);      
			   	LCD_WriteText("1st motor:");
				LCD_GoTo(0,3);      
			 	LCD_WriteText("2nd motor:");
			  	_delay_ms(1000);
			}
			else
			{start = 0;i = 0;}
//podprogram pozycjonowania silnikow
			if(((s==1)&&(!(PIND &0x01)))) 					
			{
				sync = 1;
				i = 0;
				LCD_Clear();
				LCD_GoTo(0,0);      
			   	LCD_WriteText("Checking...");
				LCD_GoTo(0,2);      
			  	LCD_WriteText("1st motor:");
				LCD_GoTo(0,3);      
			   	LCD_WriteText("2nd motor:");
			    	_delay_ms(1000);
			}
			else
			{sync = 0;i = 0;}
//przej?cie do ustawie?
			if(((s==2)&&(!(PIND &0x01))))
			{
				_delay_ms(300);
				s = 0;
				reg = 1;
				LCD_Clear();
			}
			else
			{reg = 0;}
			if(!(PINB &0x08))	
//prze??cznik TRYB: AUTO / REKA
			{_delay_ms(10);tryb1 = 1;tryb2 = 0;LCD_Clear();s = 0;}

			while(reg == 1)
			{
				LCD_GoTo(4,0);      
			   	LCD_WriteText("Settings");
				LCD_GoTo(0,2);      
			  	LCD_WriteText("R.P.M.:    ");
			   	LCD_WriteText(predkosc1);
				LCD_GoTo(0,3);      
			    	LCD_WriteText("TURNS :    ");
			   	LCD_WriteText(kroki1);
//przej?cie do ustawie? pr?dko?ci obrotowej
				if(((s==0)&&(!(PIND &0x01))))
				{
					_delay_ms(300);
					regp = 1;
					LCD_Clear();
					LCD_GoTo(3,0);     
				    	LCD_WriteText("Set r.p.m.");
					LCD_GoTo(0,2);      
				   	LCD_WriteText("R.P.M.:    ");
				}
//przej?cie do ustawie? liczby obrotow
				if(((s==1)&&(!(PIND &0x01))))
				{
					_delay_ms(300);
					regl = 1;
					LCD_Clear();
					LCD_GoTo(0,0);    
				   	LCD_WriteText("Number of Turns");
					LCD_GoTo(0,2);
				  	LCD_WriteText("TURNS :   ");
				}
				while(regl == 1)
				{
					if(!(PIND &0x40))
					{_delay_ms(300);kr = kr + 10;}
					if(kr<20){kr=20;}
					if(!(PIND &0x80))
					{_delay_ms(300);kr = kr - 10;}
					if(kr>300){kr=300;}
					if(kr<99)
					{
						LCD_GoTo(12,2);
						itoa(kr, kroki1, 10);
						LCD_WriteText(kroki1);
						LCD_GoTo(14,2);
						LCD_WriteText(" ");
					}
					if(kr>99)
					{
						LCD_GoTo(12,2);
						itoa(kr, kroki1, 10);
						LCD_WriteText(kroki1);
					}
					if(!(PIND &0x01))
					{
						_delay_ms(500);
						regl = 0;
						LCD_Clear();
					}
				}
//opcje zmiany pr?dko?ci obrotowej silnikow (przetwornik ADC)
				while(regp == 1)
				{
					ADCSRA |= (1<<ADSC);
					while(ADCSRA & (1<<ADSC));
					fz = ADCW;
					f1 = 400 + (fz/2);
					f2 = f1/k;
					p1 = (f1/400)*60;
					pp1 = round(p1);
					_delay_ms(250);
				   	 if(pp1>99)
				    {
						LCD_GoTo(12,2);
						itoa(pp1, predkosc1, 10);
					  	LCD_WriteText(predkosc1);
				    }
				    if(pp1<100)
				    {
						LCD_GoTo(12,2);
						itoa(pp1, predkosc1, 10);
					  	LCD_WriteText(predkosc1);
					  	LCD_GoTo(14,2);
					    	LCD_WriteText(" ");
				    }
				    if(!(PIND &0x01))
				    {
				    	_delay_ms(500);
				    	regp = 0;
				    	LCD_Clear();
				    }
				}
				while(!(PIND &0x40))
				{
					_delay_ms(300);
					s = s - 1;
					if(s<0){s=2;}
				}
				while(!(PIND &0x80))
				{
					_delay_ms(300);
					s = s + 1;
					if(s>1){s=0;}
				}
//przemieszczanie kursora
				if(s==0)
				{
					LCD_GoTo(15,1); 
					LCD_WriteText(" ");
					LCD_GoTo(15,2);
					LCD_WriteText("<");
					LCD_GoTo(15,3);     
					LCD_WriteText(" ");
				}
				if(s==1)
				{
					LCD_GoTo(15,1);
					LCD_WriteText(" ");
					LCD_GoTo(15,2);      
					LCD_WriteText(" ");
					LCD_GoTo(15,3);      
					LCD_WriteText("<");
				}

				if(!(PIND &0x02))
			    {
			    	_delay_ms(300);
			    	reg = 0;
			    	LCD_Clear();
			    }
			}
//podprogram wystartowania silnikow
			while(start==1)
			{
				LCD_GoTo(0,0);      
			  	LCD_WriteText("Checking...");
				LCD_GoTo(0,2);      
			    	LCD_WriteText("1st motor:");
				LCD_GoTo(0,3);      
			    	LCD_WriteText("2nd motor:");

				while(i==0)		
				{
					TCCR1B = (1<<CS10)|(1<<WGM12); 	
					TCCR1A = (1<<COM1A0); 		
					OCR1A = (((F_CPU/fp)/2))-1; 
					TCCR3B = (1<<CS30)|(1<<WGM32);	
					TCCR3A = (1<<COM3A0); 		
					OCR3A = (((F_CPU/fp)/2))-1; 	
					PORTD |= (1<<PD2)|(1<<PD3);	
					i = 1;
				}
//wykrycie pozycji silnika 1. - czujnik 1.
				if(!(PINB &0x02)) 		
				{
					PORTD &= ~(1<<PD2); 		
					c1 = 1;
					LCD_GoTo(12,2);   
				    	LCD_WriteText("OK");
				}
//wykrycie pozycji silnika 2. - czujnik 2.
				if(!(PINB &0x04)) 	
				{
					PORTD &= ~(1<<PD3);	
					c2 = 1;
					LCD_GoTo(12,3);  
				    	LCD_WriteText("OK");
				}
//zako?czenie pozycjonowania silnikow
				if((c1 == 1) & (c2 == 1))	
				{
					_delay_ms(1000);
					c1 = 0;
					c2 = 0;
					i = 0;
					LCD_Clear();
                    			LCD_GoTo(3,1);
                    			LCD_WriteText("POSITIONING");
                   			LCD_GoTo(4,2);
                    			LCD_WriteText("COMPLETED");
					_delay_ms(1500);
					LCD_Clear();
//wpisanie ustawie? timerow
					while(i==0)	
					{
						PORTD |= (1<<PD2)|(1<<PD3);
						TCCR1B = (1<<CS10)|(1<<WGM12); 
						TCCR1A = (1<<COM1A0); 
						OCR1A = (((F_CPU/f1)/2))-1; 
						TCCR3B = (1<<CS30)|(1<<WGM32);
						TCCR3A = (1<<COM3A0); 	
						OCR3A = (((F_CPU/f2)/2))-1; 
						i = 1;
					}
//podprogram pracy silnikow
					while(j<kr)
					{
					    LCD_GoTo(5,0);   
					    LCD_WriteText("Manual");
					    LCD_GoTo(0,1);    
					    itoa(j, lk, 10);
					    LCD_WriteText("t.:  ");
					    LCD_WriteText(lk);
					    LCD_GoTo(8,1);
					    LCD_WriteText("/");
					    itoa(kr, kroki1, 10);
					    LCD_WriteText(kroki1);
					    LCD_GoTo(0,2);  
					    LCD_WriteText("rpm: ");
					    itoa(pp1, predkosc1, 10);
					    LCD_WriteText(predkosc1);
					    LCD_GoTo(9,2);
					    LCD_WriteText("rev/min");
					    LCD_GoTo(2,3);  
					    LCD_WriteText("--> STOP <--");
//zatrzymanie silnikow
						PORTD |= (1<<PD2)|(1<<PD3);	
						while(!(PIND &0x02))	
						{l = 1;}
							while(l == 1)
							{
								PORTD &= ~(1<<PD2); 	
								PORTD &= ~(1<<PD3);										_delay_ms(10);
//ponowne wystartowanie silnikow
								while(!(PIND &0x01))
								{
									l = 0;
									PORTD |= (1<<PD2)|(1<<PD3);
								}
//wyj?cie z podprogramu pracy silnikow
								while(!(PIND &0x02))
								{start = 0;i = 0;j = 5;l = 0;}
							}
//zliczanie liczby obrotow
						while(!(PINB &0x02))
						{
							_delay_ms(150);
							j=j+1;
						}
					}
//zako?czenie podprogramu pracy silnikow
					if(j==kr)
					{
						start = 0;
						i = 0;
						j = 0;
						PORTD &= ~(1<<PD2); 
						PORTD &= ~(1<<PD3);	
                        LCD_Clear();
                        LCD_GoTo(5,1);
                        LCD_WriteText("FINISH");
                        _delay_ms(1000);
                        LCD_Clear();
					}
				}
			}

			while(sync==1)	
			{
				while(i==0)	
				{
					PORTD |= (1<<PD2)|(1<<PD3);
					TCCR1B = (1<<CS10)|(1<<WGM12); 
					TCCR1A = (1<<COM1A0); 	
					OCR1A = (((F_CPU/fp)/2))-1; 
					TCCR3B = (1<<CS30)|(1<<WGM32);								TCCR3A = (1<<COM3A0); 									OCR3A = (((F_CPU/fp)/2))-1;									i = 1;
				}

				if(!(PINB &0x02)) 	
				{
					PORTD &= ~(1<<PD2); 	
					c1 = 1;
					LCD_GoTo(12,2);   
				   	LCD_WriteText("OK");
				}

				if(!(PINB &0x04)) 			
				{
					PORTD &= ~(1<<PD3);	
					c2 = 1;
					LCD_GoTo(12,3);    
				   	LCD_WriteText("OK");
				}

				if((c1 == 1) & (c2 == 1))	
				{
					_delay_ms(1000);
					sync = 0;
					c1 = 0;
					c2 = 0;
					i = 0;
                    LCD_Clear();
                    LCD_GoTo(3,1);
                    LCD_WriteText("POSITIONING");
                    LCD_GoTo(4,2);
                    LCD_WriteText("COMPLETED");
                    _delay_ms(1500);
                    LCD_Clear();
				}
			}
		}

		while(tryb1 == 1)	
		{
			LCD_GoTo(4,0);    
			LCD_WriteText("Automatic");
			LCD_GoTo(0,1);
			LCD_WriteText("START");
			LCD_GoTo(0,2);
			LCD_WriteText("POSITIONING");

			while(!(PIND &0x40))
			{
				_delay_ms(300);
				s = s - 1;
				if(s<0){s=2;}
			}
			while(!(PIND &0x80))
			{
				_delay_ms(300);
				s = s + 1;
				if(s>1){s=0;}
			}

			if(s==0)
			{
				LCD_GoTo(15,1);      
				LCD_WriteText("<");
				LCD_GoTo(15,2);      
				LCD_WriteText(" ");
				LCD_GoTo(15,3);      
				LCD_WriteText(" ");
			}
			if(s==1)
			{
				LCD_GoTo(15,1);     
				LCD_WriteText(" ");
				LCD_GoTo(15,2);      
				LCD_WriteText("<");
				LCD_GoTo(15,3);      
				LCD_WriteText(" ");
			}

			if(!(PINB &0x10))	
			{_delay_ms(10);tryb2 = 1;tryb1 = 0;LCD_Clear();s = 0;}

			if(((s==0)&&(!(PIND &0x01))))	
			{
				start = 1;
				i = 0;
				LCD_Clear();
				LCD_GoTo(0,0);      
			    	LCD_WriteText("Checking...");
				LCD_GoTo(0,2);    
			   	LCD_WriteText("1st motor:");
				LCD_GoTo(0,3);      
			    	LCD_WriteText("2nd motor:");
			   	_delay_ms(1000);
			}
			else
			{start = 0;i = 0;}

			if(((s==1)&&(!(PIND &0x01)))) 
			{
				sync = 1;
				i = 0;
				LCD_Clear();
				LCD_GoTo(0,0);      
			    	LCD_WriteText("Checking...");
				LCD_GoTo(0,2);      
			   	LCD_WriteText("1st motor:");
				LCD_GoTo(0,3);     
			    	LCD_WriteText("2nd motor:");
			   	_delay_ms(1000);
			}
			else
			{sync = 0;i = 0;}

			while(start==1)
			{
				LCD_GoTo(0,0);      
			   	LCD_WriteText("Checking...");
				LCD_GoTo(0,2);      
			    	LCD_WriteText("1st motor:");
				LCD_GoTo(0,3);      
			    	LCD_WriteText("2nd motor:");

				while(i==0)	
				{
					TCCR1B = (1<<CS10)|(1<<WGM12); 	
					TCCR1A = (1<<COM1A0); 		
					OCR1A = (((F_CPU/fp)/2))-1; 	
					TCCR3B = (1<<CS30)|(1<<WGM32);	
					TCCR3A = (1<<COM3A0); 									OCR3A = (((F_CPU/fp)/2))-1; 	
					PORTD |= (1<<PD2)|(1<<PD3);	 
					i = 1;
				}

				if(!(PINB &0x02)) 					{
					PORTD &= ~(1<<PD2); 										c1 = 1;
					LCD_GoTo(12,2);     
				    	LCD_WriteText("OK");
				}

				if(!(PINB &0x04)) 						{
					PORTD &= ~(1<<PD3);										c2 = 1;
					LCD_GoTo(12,3);    
				    	LCD_WriteText("OK");
				}

				if((c1 == 1) & (c2 == 1))	
				{
					_delay_ms(1000);
					c1 = 0;
					c2 = 0;
					i = 0;
					LCD_Clear();
                    			LCD_GoTo(3,1);
                    			LCD_WriteText("POSITIONING");
                    			LCD_GoTo(4,2);
                    			LCD_WriteText("COMPLETED");
					_delay_ms(1500);
					LCD_Clear();

					while(i==0)	
					{
						PORTD |= (1<<PD2)|(1<<PD3);									TCCR1B = (1<<CS10)|(1<<WGM12); 
						TCCR1A = (1<<COM1A0); 
						OCR1A = (((F_CPU/fn1)/2))-1; 
						TCCR3B = (1<<CS30)|(1<<WGM32);	
						TCCR3A = (1<<COM3A0); 	
						OCR3A = (((F_CPU/fn2)/2))-1; 
						i = 1;
					}

					while(j<100)
					{
						LCD_GoTo(4,0);    
					    	LCD_WriteText("Automatic");
						LCD_GoTo(0,1);   
						itoa(j, kroki, 10);
					    	LCD_WriteText("t. :  ");
					    	LCD_WriteText(kroki);
					    	LCD_GoTo(9,1);
					    	LCD_WriteText("/100");
						LCD_GoTo(0,2);  
					    	LCD_WriteText("rpm:  ");
					    	itoa(ppn1, predkosc, 10);
					    	LCD_WriteText(predkosc);
					   	LCD_GoTo(9,2);
					    	LCD_WriteText("rev/min");
						LCD_GoTo(2,3);   
					    	LCD_WriteText("--> STOP <--");

						PORTD |= (1<<PD2)|(1<<PD3);	
						while(!(PIND &0x02))	
						{l = 1;}
						while(l == 1)
							{
								PORTD &= ~(1<<PD2); 		
								PORTD &= ~(1<<PD3);	
								_delay_ms(10);

								while(!(PIND &0x01))
								{
									l = 0;
									PORTD |= (1<<PD2)|(1<<PD3);
								}

								while(!(PIND &0x02))
								{start = 0;i = 0;j = 100;l = 0;}
							}
						while(!(PINB &0x02))
						{
							_delay_ms(300);
							j=j+1;
						}
					}
					if(j==100)
					{
						start = 0;
						i = 0;
						j = 0;
						PORTD &= ~(1<<PD2); 			
						PORTD &= ~(1<<PD3);	
						_delay_ms(1000);
						j1 = j + 1;
						itoa((j1), krokik, 10);
						LCD_GoTo(5,1);
						LCD_WriteText(krokik);
                        LCD_Clear();
                        LCD_GoTo(5,1);
                        LCD_WriteText("FINISH");
                        _delay_ms(1000);
                        LCD_Clear();
					}
				}
			}

			while(sync==1)		
			{
				while(i==0)	
				{
					PORTD |= (1<<PD2)|(1<<PD3);
					TCCR1B = (1<<CS10)|(1<<WGM12); 
					TCCR1A = (1<<COM1A0); 	
					OCR1A = (((F_CPU/fp)/2))-1;
					TCCR3B = (1<<CS30)|(1<<WGM32);								TCCR3A = (1<<COM3A0); 									OCR3A = (((F_CPU/fp)/2))-1;
					i = 1;
				}

				if(!(PINB &0x02)) 		
				{
					PORTD &= ~(1<<PD2); 		
					c1 = 1;
					LCD_GoTo(12,2);   
				    	LCD_WriteText("OK");
				}

				if(!(PINB &0x04)) 	
				{
					PORTD &= ~(1<<PD3);	
					c2 = 1;
					LCD_GoTo(12,3);    
				    	LCD_WriteText("OK");
				}

				if((c1 == 1) & (c2 == 1))			
				{
					_delay_ms(1000);
					sync = 0;
					c1 = 0;
					c2 = 0;
					i = 0;
                    			LCD_Clear();
                    			LCD_GoTo(3,1);
                   			LCD_WriteText("POSITIONING");
                   			LCD_GoTo(4,2);
                   			LCD_WriteText("COMPLETED");
                    			_delay_ms(1500);
                    			LCD_Clear();
				}
			}
		}
	}
예제 #24
0
void show_setup_time_screen(unsigned char screen_changed, msg_t * msg)
{
    if (screen_changed) {
        g_time_screen.hour = g_clock.current_hour;
        g_time_screen.minute = g_clock.current_minute;
        LCD_GoTo(0,0);
        LCD_WriteText("Set time: ");
        LCD_GoTo(0,1);
        get_time_str(string_buff);
        string_buff[5] = 0;
        LCD_WriteText(string_buff);
        g_time_screen.blink = 0;
        g_time_screen.blink_pos = 4;
    }

    uint32_t inc = 0;
    switch(msg->type) {
    case MSG_SECOND_CHANGE:
        g_time_screen.blink = ~g_time_screen.blink;
        break;

    case MSG_INPUT:
        if (msg->size == BTN_1) {
            inc = 1;
        } else if (msg->size == BTN_2) {
            if (g_time_screen.blink_pos == 4) {
                LCD_WriteTwoDigit(g_time_screen.blink_pos - 1, 1, g_time_screen.minute);
            } else {
                LCD_WriteTwoDigit(g_time_screen.blink_pos - 1, 1, g_time_screen.hour);
            }
            g_time_screen.blink_pos -= 3;
            if (g_time_screen.blink_pos == -2) {
                g_time_screen.blink_pos = 4;
            }
        }
        break;

    default:
        break;
    }

    int time = 99;
    switch(g_time_screen.blink_pos) {
    case 4:
        if (inc) {
            g_time_screen.minute++;
            g_time_screen.minute %= 60;
        }
        time = g_time_screen.minute;
        break;

    case 1:
        if (inc) {
            g_time_screen.hour++;
            g_time_screen.hour %= 24;
        }
        time = g_time_screen.hour;
        break;
    }

    if (g_time_screen.blink && !inc) {
        LCD_GoTo(g_time_screen.blink_pos, 1);
        LCD_WriteText("_\0");
    } else {
        LCD_WriteTwoDigit(g_time_screen.blink_pos-1, 1, time);
    }
}
예제 #25
0
int main(void)
{//petla glowna
		DDRE=0x3C; // port e jako wyjœcie 00111100
		PORTE=0x3C;
		DDRB=0xFD;
		PORTB=0xFD;
		//DDRG=0b00000000;//0x02;
		//PORTG=0b0000010;
		DDRC=0x7F;
		PORTC=0x7F;
		DDRD=0xFC;
		PORTD=0xFF;
		//ADC
		PORTF=0xFA;
		//
		PORTG = (1<<SET_HOUR | 1<<SET_MINUTE); //piny zegara - zmiana wartosci
		//######## konfiguracja ADC ##############
		ADCSRA=(1<<ADEN)|(1<<ADPS0)|(1<<ADPS1)|(1<<ADPS2);
		//ustawienie bitu ADEN=1 - wlaczenie  przetwornika A/C				
		// ustawienie preskalera na 64 // ustawienie
		// czestotliwosc taktowania przetwornika A/C, f=8Mhz/64
		ADMUX=(0<<REFS1)|(0<<REFS0); 	// wybor zewnetrznego napiecia odniesienia
		//###########################################
		//######## konfiguracja timera0 ##############
		TIMSK |= (1<<TOIE2)|(1<<TOIE0)|1<<OCIE1A;          //Przerwanie overflow (przepe³nienie timera)//ICIE1A ---- ZEGAR
		TCCR0 |= (1<<CS02) | (1<<CS01) | (0<<CS00); // Ÿród³em CLK, preskaler 256
		TCNT0 = timer0;//          //Pocz¹tkowa wartoœæ licznika
		//###########################################
		//######## konfiguracja timera2 ##############
		TCCR2 |= (0<<CS22) | (1<<CS21) | (1<<CS20); // Ÿród³em CLK, preskaler 32
		TCNT2 = timer2;//          //Pocz¹tkowa wartoœæ licznika
		//###########################################		
		//######## konfiguracja timera1 ##############
		TCCR1B = (1<<CS12|1<<WGM12);
		OCR1A = 3053-1; //dla 8Mhz ////// 0,5 s
		//###########################################	
		SK1_EN_1; //poczatkowe wartosci
		SK1_DIR_1;
		SK2_EN_1;
		SK2_DIR_1;
		TR_SPRE_0;
		TR_WENT_0;
		TR_EOWZ_ZBIO_0;
		TR_EOZW_SPOW_0;
		TR_A_0;
		TR_EOZR_TUBA_0;
		LCD_Initalize(); //inicjalizacja LCD
		LCD_GoTo(0,0);
		LCD_WriteText("Ps000rpm|Ak00.0V");
		LCD_GoTo(0,1);
		LCD_WriteText("Sp0|___|");
		LCD_GoTo(8,1);
		LCD_WriteText(time);
	for(;;)
	{
		if(bit_is_clear(PIND, ON_OFF_ALL)&~ON_OFF&&cisON_OFF&&bit_is_clear(PINE, SPR_PRES))//uruchomienie
		{
			ON_OFF=true;//gl petla
			cispON_OFF=true;//flaga spr cisnienia
			poczekaj=false;//flaga
		}
		if (wylON_OFF)//wylaczenie
		{
			cli();
			SK1_EN_1;
			SK2_EN_1;
			TR_SPRE_0;
			TR_WENT_0;
			TR_EOWZ_ZBIO_0;
			TR_EOZW_SPOW_0;
			TR_A_0;
			LCD_GoTo(2,0);
			LCD_WriteText("000");
			ON_OFF=false;
			_delay_ms(3000);
			TR_EOZR_TUBA_0;
			wylON_OFF = false;
		}
		//SPR CISNIENIA
		if(bit_is_clear(PINE, SPR_PRES))//cisnienie ok
		{
			TR_SPRE_0;
			LCD_GoTo(2,1);
			LCD_WriteText("0");
			cisON_OFF=true;
			poczekaj=false;
		}
		if(bit_is_set(PINE, SPR_PRES)&&cispON_OFF)//cisnienie za niskie
		{
			TR_SPRE_1;
			LCD_GoTo(2,1);
			LCD_WriteText("1");		
			if (poczekaj)
			{
				_delay_ms(5000);	//czas potrzebny na uzupelnienie ukladu
				poczekaj=false;
			}
			cisON_OFF=false;
		}
		//
		if(bit_is_clear(PIND, O_O_A))//upuszczenie powietrza, krtorkie - tuba, dlugie - wszystko
		{
			cli();//Globalne wylaczenie przerwañ
			LCD_GoTo(2,0);
			LCD_WriteText("000");			
			TR_EOZR_TUBA_1;
			TR_EOZW_SPOW_1;
			LCD_GoTo(4,1);
			LCD_WriteText("T__");
			SK1_EN_1;
			SK2_EN_1;
			TR_SPRE_0;
			LCD_GoTo(2,1);
			LCD_WriteText("0");			
			TR_WENT_0;
			TR_EOWZ_ZBIO_0;
			TR_A_0;
			ON_OFF=false;
			_delay_ms(5000);
			cispON_OFF=false;
			if (bit_is_clear(PIND, O_O_A))
			{	
				TR_EOZR_TUBA_1;
				TR_EOWZ_ZBIO_1;
				TR_EOZW_SPOW_1;
				LCD_GoTo(4,1);
				LCD_WriteText("TZP");				
				_delay_ms(4000);
				TR_EOZR_TUBA_0;
				TR_EOWZ_ZBIO_0;
				TR_EOZW_SPOW_0;
				LCD_GoTo(4,1);
				LCD_WriteText("___");	
			}
			TR_EOZR_TUBA_0;
			TR_EOWZ_ZBIO_0;
			TR_EOZW_SPOW_0;
			LCD_GoTo(4,1);
			LCD_WriteText("___");
			poczekaj=true;
			ON_OFF = false;
			wylON_OFF = false;
			cisON_OFF = false;
			cispON_OFF = true;	
		}
		if(ON_OFF)
		{
			sei();//Globalne uruchomienie przerwañ
			SK1_EN_0; //poczatkowe wartosci
			SK1_DIR_1;
			SK2_DIR_1;
			TR_WENT_1;
			TR_EOWZ_ZBIO_0;
			TR_EOZW_SPOW_0;
			TR_A_0;
			TR_EOZR_TUBA_1;	
			//----ZEGAR
			if(!(PING & (1<<SET_HOUR)))
			{
				hours++;
				if(hours > 23)
				hours = 0;
			}
			if(!(PING & (1<<SET_MINUTE)))
			{
				minutes++;
				if(minutes > 59)
				minutes = 0;
			}

			if (AktuADC)
			{
				ADMUX=(0<<MUX3)|(0<<MUX2)|(0<<MUX1)|(0<<MUX0);			// wyb?r kana?u ADC0
				while(ADCSRA & (1<<ADSC));						//czeka na zako?czenie konwersji
				ADCSRA |= (1<<ADSC);							//uruchomienie pojedynczej konwersji
				pomiar_ADC0=ADC;
				ADMUX=0;
				ADMUX=(0<<MUX3)|(0<<MUX2)|(1<<MUX1)|(0<<MUX0);			// wyb?r kana?u ADC1
				while(ADCSRA & (1<<ADSC));						//czeka na zako?czenie konwersji
				ADCSRA |= (1<<ADSC);							//uruchomienie pojedynczej konwersji
				pomiar_ADC2=ADC;
				ADMUX=0;			
				AktuADC = false;
			}
			if (ChangedADC)
			{
				b++;
				tablicarpm[b]=pomiar_ADC0;
				tablicawol[b]=pomiar_ADC2;
				if(b==11)
				{	
					sr_ADC0=(tablicarpm[1]+tablicarpm[2]+tablicarpm[3]+tablicarpm[4]+tablicarpm[5]+tablicarpm[6]+tablicarpm[7]+tablicarpm[8]+tablicarpm[9]+tablicarpm[10]+tablicarpm[11])/b;
					sr_ADC2=(tablicawol[1]+tablicawol[2]+tablicawol[3]+tablicawol[4]+tablicawol[5]+tablicawol[6]+tablicawol[7]+tablicawol[8]+tablicawol[9]+tablicawol[10]+tablicawol[11])/b;
					timer2=sr_ADC0/5;
					obroty2=9375/((255-timer2));
					wolt=0.0138*sr_ADC2-0.0332;
					b=0;					
				}
				ChangedADC = false;
			}
			if(timeChanged05)
			{		
				LCD_GoTo(0,0);
				LCD_WriteText("Ps00_rpm|Ak00.0V");
				itoa(obroty2, bufor, 10);
				LCD_GoTo(2,0);
				LCD_WriteText(bufor);
				dtostrf(wolt, 3, 1, bufor2);
				LCD_GoTo(11,0);
				LCD_WriteText(bufor2);
				timeChanged05 = false;
			}
			if(timeChanged)
			{	
				if (obroty2<38)
				{
					SK2_EN_1;
					LCD_GoTo(2,0);
					LCD_WriteText("000");
				}
				else
				{
					SK2_EN_0;
				}			
				LCD_update_time();
				timeChanged = false;
			}
		}//if(ON_OFF)
	}//for(;;)	
}//main(void)