예제 #1
0
/*
 * This method is called continouusly, i.e. in a while(1) loop. This is
 * where the exciting stuff happens. Well, "exciting" depends on your
 * point of view and level of experience, I guess.
 */
void loop() {
	// Place the cursor in the second line of the display and output the current
	// sensor values. Note that I didn't bother to translate those values to
	// an actual light level and temperature - I only scaled the light sensor's
	// output so it looked nicer on the display.
	// I use hex codes instead of decimal because it's more 31337.
	lcd_setcursor(0,2);
	int ldrValue = map(getAnalogValue(SEN_LDR_PIN), 0x050, 0x3ff, 0x000, 0xfff);
	int trmValue = getAnalogValue(SEN_TRM_PIN);

	sprintf(buffer, "LDR %03x  TRM %03x", ldrValue, trmValue);
	lcd_string(buffer);

	// Show the sensor readings for some time ...
	_delay_ms(TIME_AWAKE);

	// ... then say that we're sleepy ...
	lcd_home();
	lcd_string("Sleep ...");
	_delay_ms(TIME_BEFORE_SLEEP);

	// ... switch off the LCD and put the processor in deep sleep mode.
	lcd_light_state(0);

	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	sleep_mode();

	// When the button is pressed, the program will resume right here after
	// the interrupt handler has been executed. A good moment for reactivating
	// the LCD.
	lcd_home();
	lcd_string("Wake up! ");
	lcd_light_state(1);
}
예제 #2
0
int8_t Fan_State_Dur(uint8_t fan, int8_t input){
	// Wert bearbeiten?
	if (input == MENU_INPUT_PUSH) {
		Fan_edit ^= 1;
		eeprom_write_byte((void*) &Fan_fansE[fan].dur, Fan_fans[fan].dur);
	}
	if (Fan_edit && (input == MENU_INPUT_DOWN)) {
		Fan_fans[fan].dur = (Fan_fans[fan].dur < FAN_DUR_MAX) ? (Fan_fans[fan].dur+1) : (FAN_DUR_MAX);
	}
	if (Fan_edit && (input == MENU_INPUT_UP)) {
		Fan_fans[fan].dur = (Fan_fans[fan].dur > FAN_DUR_MIN) ? (Fan_fans[fan].dur-1) : (FAN_DUR_MIN);
	}
	// Ausgabe
	lcd_clear();
	lcd_home();
	if (Fan_edit)
		lcd_data('*');
	else
		lcd_data('>');
	lcd_string_P(MENU_STR_DURATION);
	lcd_number(Fan_fans[fan].dur, 2, ' ');
	lcd_string_P(MENU_STR_MIN);
	lcd_setcursor(0, 2);
	lcd_data(' ');
	lcd_string_P(MENU_STR_BACK);
	return Fan_edit;
}
예제 #3
0
int8_t Fan_State_Humi(uint8_t fan, int8_t input) {
	// Wert bearbeiten?
	if (input == MENU_INPUT_PUSH) {
		Fan_edit ^= 1;
		eeprom_write_byte((void*) &Fan_fansE[fan].humi, Fan_fans[fan].humi);
	}
	if (Fan_edit && (input == MENU_INPUT_DOWN)) {
		Fan_fans[fan].humi = (Fan_fans[fan].humi < FAN_HUMI_MAX) ? (Fan_fans[fan].humi+1) : (FAN_HUMI_MAX);
	}
	if (Fan_edit && (input == MENU_INPUT_UP)) {
		Fan_fans[fan].humi = (Fan_fans[fan].humi > FAN_HUMI_MIN) ? (Fan_fans[fan].humi-1) : (FAN_HUMI_MIN);
	}
	// Ausgabe
	lcd_clear();
	lcd_home();
	if (Fan_edit)
		lcd_data('*');
	else
		lcd_data('>');
	lcd_string_P(MENU_STR_HUMIDITY);
	lcd_number(Fan_fans[fan].humi, 2, ' ');
	lcd_data('%');
	lcd_setcursor(0, 2);
	lcd_data(' ');
	lcd_string_P(MENU_STR_ONTIME);
	lcd_number(Fan_fans[fan].timeH, 2, ' ');
	lcd_data(':');
	lcd_number(Fan_fans[fan].timeM, 2, '0');
	return Fan_edit;
}
예제 #4
0
static void print_time(uint8_t blink)
{
	char digits[6];
	uint8_t i;
	uint32_t f;

	lcd_setcursor(0,2);
	lcd_string("t=");

	f = time;

	digits[0] = f/1e3; f -= digits[0]*1e3;
	digits[1] = f/1e2; f -= digits[1]*1e2;
	digits[2] = f/1e1; f -= digits[2]*1e1;
	digits[3] = f/1e0; f -= digits[3]*1e0;
	digits[4] = 0;

	for(i=0;i<4;i++)
		digits[i] += 48;

	if(blink)
	{
		if(selectionState == state_select_time_4)
			digits[0] = ' ';
		if(selectionState == state_select_time_3)
			digits[1] = ' ';
		if(selectionState == state_select_time_2)
			digits[2] = ' ';
		if(selectionState == state_select_time_1)
			digits[3] = ' ';
	}
	lcd_string(digits);
}
예제 #5
0
void disp_show_buf(char *buf) {
    uint8_t i;
    lcd_clear();
    lcd_home();
    for(i=0;i<16;i++)lcd_data(buf[i]);
    lcd_setcursor(0,2);
    for(;i<32;i++)lcd_data(buf[i]);
}
예제 #6
0
int8_t Menu_Version(int8_t input) {
	lcd_clear();
	lcd_home();
	lcd_string_P(MENU_STR_VER);
	lcd_data(':');
	lcd_setcursor(0, 2);
	lcd_string_P(GITVERSION);
	return 0;
}
예제 #7
0
int main(void)
{
	uint8_t			data = 0x55;
	uint32_t		prevms = 0;
	PCF8574_STATUS	st;

	sei();
	i2c_begin();

	TCCR2A = 0;						//t2: stop
	TCCR2B = 0;
	GTCCR = _BV(PSRASY);			//t2: prescaler reset
	TCNT2 = 0;						//t2: reset counter

	TCCR2A = _BV(WGM21);			//t2: CTC mode
	OCR2A = 124;					//t2: 62.5*128*125 = 1000000 ns = 1 ms
	TIMSK2 = _BV(OCIE2A);			//t2 enable Timer2 Interrupt

	TCCR2B = _BV(CS20) | _BV(CS22);	//t2: prescaler 128 (start)

//	pcf8574_init(&st, 0x20, 0xff);

	_delay_ms(500);  //Initiaize LCD
	lcd_init();
	_delay_ms(200);
	lcd_clear();
	lcd_setcursor(1, 0);
	display("Hi");
	display(" There....");
	lcd_setcursor(0, 1);
	display("Circuits4You.com");


	while(1)
	{
//		pcf8574_write8(&st, data);
//		pcf8574_read8(&st, &data);
//		data ^= 0xff;
//		while(millis() - prevms < 1000 );
//		prevms += 1000;
	}
}
예제 #8
0
int8_t Fan_State_Back(uint8_t fan, int8_t input) {
	lcd_clear();
	lcd_home();
	lcd_data(' ');
	lcd_string_P(MENU_STR_DURATION);
	lcd_number(Fan_fans[fan].dur, 2, ' ');
	lcd_string_P(MENU_STR_MIN);
	lcd_setcursor(0, 2);
	lcd_data('>');
	lcd_string_P(MENU_STR_BACK);
	return 0;
}
예제 #9
0
int main(void)
{
	lcd_init();
	lcd_clear();
	char* buf[20];

    const char *parray = (const char*) pgm_read_word (&getranke_namen[17]); // Lese die Adresse des i-ten Strings aus array[]
    strcpy_P (buf, parray); // Kopiere den Inhalt der Zeichenkette vom Flash ins RAM
	//lcd_string(buf); // Ausgabe des Textes 
	
	
	void lcd_schnaps(uint8_t bereich)
	{
		lcd_clear();
		lcd_string("Asbach");
		lcd_setcursor(10,1); 
		lcd_string("Wodka");
		lcd_setcursor(0,2); 
		lcd_string("Whisky");
		lcd_setcursor(10,2); 
		lcd_string("Rum");
	
	}
예제 #10
0
int8_t Fan_State_On(uint8_t fan, int8_t input) {
	// Wert bearbeiten?
	if (input == MENU_INPUT_PUSH) {
		Fan_edit ^= 1;
		eeprom_write_byte((void*) &Fan_fansE[fan].timeM, Fan_fans[fan].timeM);
		eeprom_write_byte((void*) &Fan_fansE[fan].timeH, Fan_fans[fan].timeH);
	}
	if (Fan_edit && (input == MENU_INPUT_DOWN)) {
		if (Fan_fans[fan].timeM < 55) {
			Fan_fans[fan].timeM += 5;
		} else if (Fan_fans[fan].timeH < 23) {
			Fan_fans[fan].timeM = 0;
			Fan_fans[fan].timeH++;
		}
	}
	if (Fan_edit && (input == MENU_INPUT_UP)) {
		if (Fan_fans[fan].timeM > 0) {
			Fan_fans[fan].timeM -= 5;
		} else if (Fan_fans[fan].timeH > 0) {
			Fan_fans[fan].timeM = 55;
			Fan_fans[fan].timeH--;
		}
	}
	// Ausgabe
	lcd_clear();
	lcd_home();
	if (Fan_edit)
		lcd_data('*');
	else
		lcd_data('>');
	lcd_string_P(MENU_STR_ONTIME);
	lcd_number(Fan_fans[fan].timeH, 2, ' ');
	lcd_data(':');
	lcd_number(Fan_fans[fan].timeM, 2, '0');
	lcd_setcursor(0, 2);
	lcd_data(' ');
	lcd_string_P(MENU_STR_REPEAT);
	lcd_number(Fan_fans[fan].rep, 2, ' ');
	lcd_data('h');
	return Fan_edit;
}
예제 #11
0
int8_t Fan_State_Ctrl(uint8_t fan, int8_t input) {
	// Wert bearbeiten?
	if (input == MENU_INPUT_PUSH) {
		Fan_edit ^= 1;
		eeprom_write_byte((void*) &Fan_fansE[fan].ctrl, Fan_fans[fan].ctrl);
	}
	if (Fan_edit && (input == MENU_INPUT_DOWN)) {
		Fan_fans[fan].ctrl = (Fan_fans[fan].ctrl < FAN_CTRL_MAX) ? (Fan_fans[fan].ctrl+1) : (FAN_CTRL_MAX);
	}
	if (Fan_edit && (input == MENU_INPUT_UP)) {
		Fan_fans[fan].ctrl = (Fan_fans[fan].ctrl > FAN_CTRL_MIN) ? (Fan_fans[fan].ctrl-1) : (FAN_CTRL_MIN);
	}
	// Ausgabe
	lcd_clear();
	lcd_home();
	if (Fan_edit)
		lcd_data('*');
	else
		lcd_data('>');
	lcd_string_P(MENU_STR_CTRL);
	switch (Fan_fans[fan].ctrl) {
		case FAN_CTRL_OFF:
			lcd_string_P(MENU_STR_CTRL_OFF);
			break;
		case FAN_CTRL_HUMI:
			lcd_string_P(MENU_STR_CTRL_HUMI);
			break;
		case FAN_CTRL_TIME:
			lcd_string_P(MENU_STR_CTRL_TIME);
			break;
		case FAN_CTRL_REP:
			lcd_string_P(MENU_STR_CTRL_REP);
			break;
	}
	lcd_setcursor(0, 2);
	lcd_data(' ');
	lcd_string_P(MENU_STR_HUMIDITY);
	lcd_number(Fan_fans[fan].humi, 2, ' ');
	lcd_data('%');
	return Fan_edit;
}
예제 #12
0
static void print_f1(uint8_t blink)
{
	char digits[7];
	uint8_t i;
	uint32_t f;

	lcd_setcursor(0,1);
	lcd_string("LSweep f1=");

	f = f1;
	digits[0] = f/1e8; f -= digits[0]*1e8;
	digits[1] = f/1e7; f -= digits[1]*1e7;
	digits[2] = f/1e6; f -= digits[2]*1e6;
	digits[3] = '.';
	digits[4] = f/1e5; f -= digits[4]*1e5;
	digits[5] = f/1e4; f -= digits[5]*1e4;
	digits[6] = 0;

	for(i=0;i<6;i++)
		digits[i] += 48;
	digits[3] = '.';
	if(blink)
	{
		if(selectionState == state_select_f1_3_mhz)
			digits[0] = ' ';
		if(selectionState == state_select_f1_2_mhz)
			digits[1] = ' ';
		if(selectionState == state_select_f1_1_mhz)
			digits[2] = ' ';
		if(selectionState == state_select_f1_3_khz)
			digits[4] = ' ';
		if(selectionState == state_select_f1_2_khz)
			digits[5] = ' ';
	}
	lcd_string(digits);
}
예제 #13
0
void show(char data[6][4]){
	lcd_clear();
	
	lcd_setcursor( 1, 1 );
	lcd_string(data[4]);
	
	lcd_setcursor( 6, 1 );
	lcd_string(data[3]);
	
	lcd_setcursor( 11, 1 );
 	lcd_string(data[2]);

	lcd_setcursor( 1, 2 );
	lcd_string(data[1]);
	
	lcd_setcursor( 6, 2 );
	lcd_string(data[0]);
	
	//PWM Signal:
	lcd_setcursor( 11, 2 );
	lcd_string(data[5]);
}
예제 #14
0
파일: main.c 프로젝트: jobquiroz/MieruSDK
int main(int argc, char *argv[]){
    int oldx, oldy;
    lcd_init();
    lcd_setcursor(1);

    if( argc != 2 ){
        lcd_printf("emin [filename]\n");
        return 0;
    }

    oldx = lcd_getcurx();
    oldy = lcd_getcury();
    lcd_setshowpage(2);
    lcd_setdrawpage(2);
    lcd_locate(0,0);
    init(argv[1]);

    uchar key;
    while(!quit){
        key = mpc_getchar();

        if(key != 0){
            if( !mpc_oncontrol() && !mpc_onalt() ){
                if(key == MKS_Enter){
                    emin_enter();

                }else if(key == MKS_BackSpace || key == MKS_Delete){
                    emin_backspace();

                }else if(0x20 <= key && key < 0x7f){
                    emin_type(key);
                }

            }else if( mpc_oncontrol() ){
                if(key == 'f'){
                    Cursor_move_right(&cursor);
                }else if(key == 'b'){
                    Cursor_move_left(&cursor);
                }else if(key == 'p'){
                    Cursor_move_up(&cursor);
                }else if(key == 'n'){
                    Cursor_move_down(&cursor);
                }else if(key == 'a'){
                    Cursor_move_head(&cursor);
                }else if(key == 'e'){
                    Cursor_move_end(&cursor);
                }else if(key == 'l'){
                    View_redraw(&cursor);
                }else if(key == 'h'){
                    emin_backspace();
                }else if(key == 'x'){
                    emin_command(key);
                }
                

            }else if( mpc_onalt() ){

            }
            
            //Cursor_on(&cursor);
            Cursor_set(&cursor);
        }
        
        mpc_usleep(1000);
    }

    lcd_cls();
    lcd_setshowpage(0);
    lcd_setdrawpage(0);
    lcd_locate(oldx, oldy);

    return 0;
}
예제 #15
0
파일: main.c 프로젝트: penma/fallblatt
int main (void) {
	debug_init();

	config_read();

	motor_init();
	lightsensor_init();

	find_start_position();

	debug_fstr("done");
	lcd_setcursor(2,2);
	debug_fstr("durr ");
	debug_hex8(conf_address);

	/* now listen on the bus and wait for data */
	si2cs_init();
	sei();

	/* we're done with setup. activate watchdog */
	wdt_enable(WDTO_4S);

	while (1) {
		/* moving to a new position */

		motor_current_active();

		uint16_t steps_since_start = 0;

		while (current_pos != target_pos) {
			/* do one step */
			motor_step();

			/* update current position.
			 * overflow of the current position is handled by the
			 * light sensor interrupt
			 */
			current_pos++;

			/* acceleration */
			if (steps_since_start > 20 && steps_until_done > 20) {
				_delay_ms(3);
			} else if (steps_since_start > 10 && steps_until_done > 10) {
				_delay_ms(6);
			} else if (steps_since_start > 5 && steps_until_done > 5) {
				_delay_ms(9);
			} else {
				_delay_ms(10);
			}
			steps_since_start++;
			steps_until_done--;

			wdt_reset();
		}

		/* holding the current position */

		motor_current_idle();

		while (current_pos == target_pos) {
			_delay_ms(20);

			wdt_reset();
		}
	}
}
예제 #16
0
uint8_t fileParser_parseNextBlock(unsigned long filesize)
{

	switch(fileParser_parseState)
	{
		case INFO_HEADER:
		{
			//--- read info header ---
			struct InfoHeader *tmpHeader;
			tmpHeader = (struct InfoHeader *) &sd_buffer[0];
			infoHeader = *tmpHeader;

			if(	(infoHeader.headerId[0] != 'S') ||
				(infoHeader.headerId[1] != 'P') ||
				(infoHeader.headerId[2] != 'F') ||
				(infoHeader.headerId[3] != 'I')
			)
			{
				//header not right -> abort
				
				lcd_clear();
				lcd_home();
				lcd_string("header error");
				
				while(1);
				return 0;
			}
		
		
			fileParser_bytesRead += 512;
			
			if ((fileParser_bytesRead) >= filesize )
			{
				
				lcd_setcursor(0,2);
				lcd_string("EOF error");
				while(1);
			}		
			
			fileParser_parseState = AVR_DATA;
		}			
		break;
	
		case AVR_DATA:
		{
			//--- read avr code ---
			//program data into flash (512 bytes data to 4 pages a 128 bytes -> mega32 SPM_PAGESIZE = 128
			//program data into flash (512 bytes data to 2 pages a 256 bytes -> mega644 SPM_PAGESIZE = 256
			
			
			for(int i=0; (i<(512/SPM_PAGESIZE)) && (fileParser_bytesRead < (infoHeader.avrCodeSize +  512)); i++ )
			{
				
				boot_program_page(fileParser_pagesWritten,(uint8_t *)&sd_buffer[0+i*SPM_PAGESIZE]);

				fileParser_bytesRead += SPM_PAGESIZE;
				fileParser_pagesWritten+=SPM_PAGESIZE;
			}
							
			//increment the byte counter
			//fileParser_bytesRead += 512
			if ((fileParser_bytesRead) >= filesize )
			{
				 return 0;
			}				 
			
			//check if AVR code end is reached
			if(fileParser_bytesRead >= (infoHeader.avrCodeSize +  512) )
			{
				//reset cortex chip
				lcd_home();
				lcd_string("updating...(1/2)");
				lcd_setcursor(0,2);
				lcd_command(LCD_CURSOR_ON);
				
				fileParser_resetCortex();
				
				//initialize the cortex bootloader
				//try 10 times to give the cortex some time to boot and answer
				int i=0;
				for(;;)
				{
					uart_tx(INIT_BOOTLOADER);
					_delay_ms(1000);
					//if received data is available
#ifdef MEGA32					
					if( (UCSRA & (1<<RXC)) )
#else
					if( (UCSR0A & (1<<RXC0)) )
#endif
					{
						uint8_t data = uart_rxWait();	
						
						if(data == ACK)
						{
							//bootloader successfully initialized
							//it is now waiting for commands
							break;
						}
					}
					
					dout_updateOutputs();
				}
				
				//check if init is ok (ACK received)
				if(i>=10)
				{
					//an error occured
					//could not initialize bootloader
					lcd_home();
					lcd_string("mainboard error");
					while(1);
					return 0;
				}
				
				//now we can send the cortex bootloader commands and data
				fileParser_parseState = CORTEX_DATA;
				
				
				
				//give the cortex time to erase the flash
				lcd_home();
				lcd_string("updating...(2/2)");
				return 1;
			}
			}			
		break;
		
		case CORTEX_DATA:
			//--- read cortex code ---
			
			//we have 512 bytes of data
			//data is 32 bit unsigned int
			//we increment with 4 because in each run we send out 4 bytes => 1 32 bit int message
			for(int i=0;i<512;i+=4)
			{
				
				uint16_t crc;
			
				// send the address
				
				crc = calcCrc(WRITE_ADDRESS,(uint8_t*)&addressCounter);
				//send next address packet until ACK received
				do 
				{
					uart_tx(WRITE_ADDRESS);
					//lcd_home();
					//lcd_string("cmd");
					uart_tx(addressCounter>>24);
					uart_tx(addressCounter>>16);
					uart_tx(addressCounter>>8);
					uart_tx(addressCounter);

					//send calculated CRC
					uart_tx(crc>>8);
					uart_tx(crc&0xff);

				} 
				while (uart_checkAck()!=ACK);	
				
			
				//calc crc for data block
				crc = calcCrc(WRITE_DATA,&sd_buffer[i]);
				//send next data packet until ACK received
				do 
				{
					//send command
					uart_tx(WRITE_DATA);
					//after the command, send the 4 data bytes
					uart_tx(sd_buffer[i+3]);
					uart_tx(sd_buffer[i+2]);
					uart_tx(sd_buffer[i+1]);
					uart_tx(sd_buffer[i]);

					//send calculated CRC
					uart_tx(crc>>8);
					uart_tx(crc&0xff);
				} 
				while (uart_checkAck()!=ACK);
				
				//transfer succeeded
				addressCounter++;
			}	
			dout_updateOutputs();			
				
			fileParser_bytesRead+=512;
			//send cortex bootloader data
				
			if ((fileParser_bytesRead) >= filesize )
			{
				lcd_clear();
				lcd_home();
				lcd_string("success!");
				lcd_setcursor(0,2);
				lcd_string("please reboot...");
				lcd_command(LCD_CURSOR_OFF);
				uart_tx(END_BOOTLOADER);
				while(1);
				 return 0;
			}		
		break;
	}

	return 1;
}
예제 #17
0
int main (void) {            // (2)
   ledidx_t i;

   DDRB  = 0xFF;  // Port B: 1 = output
   PORTB = 0x01;  //bootup 1

   //_delay_ms(1000);

   // Initialize LCD Display
   DDRC |= (1<<PC1) | (1<<PC3); //PC1 = R/W, PC3 = Backlight control
   PORTC &= ~(1<<PC1);
   //Switch Backlight on:
   PORTC |= (1<<PC3);

   _delay_ms(10); lcd_init();

   PORTB = 0x02;  //bootup 2
   _delay_ms(100);
   lcd_string_P(PSTR("blinkylight 0.3 "));
   lcd_setcursor(0,2);
   lcd_string_P(PSTR("Booting ...     "));
   //PORTB = 0x03;  //bootup 3
   //_delay_ms(1000);

   uart_init();
   uart_putc('p'); uart_putc('w'); uart_putc('r'); uart_putc('O'); uart_putc('N'); uart_putc('\n');
   //PORTB = 0x04;  //bootup 4



   //PORTB = 0x05;  //bootup 5

   // Enable Interrupts
   sei();
   PORTB = 0x06;  //bootup 6

   // muss vor ws2801_init stehen, da dieser PA1 und PA2 als output schaltet
   DDRA  = 0x00; // Port A: 0 = input
   PORTA = 0x00;  //        0 = pull-ups off

   //PORTB = 0x0a;  //bootup a


   PORTB = 0x00;  //bootup d
   lcd_setcursor(0,2);
   lcd_string_P(PSTR("Boot complete  "));
   _delay_ms(10);

   //Switch Backlight off:
   PORTC &= ~(1<<PC3);

   // Enter main loop
   uint8_t dezisek = 0;
#define DEZISEKTHRES 4
   while(1) {                // (5)
     /* "leere" Schleife*/   // (6)
     _delay_ms(25);
     //pb_scroll <<= 1;
     //if (pb_scroll == 0b00010000) pb_scroll = 0b00000001;
     //PORTB &= 0b11110000;
     //PORTB |= pb_scroll;
     PORTB ^= (1<<PB2);
     if (dezisek > DEZISEKTHRES) {
       if (relay_timer > 0) {
         relay_timer --;
         if (relay_timer == 0) relay_reset = 1;
         else {
           PORTB ^= ( 1 << PB5 )|(1<<PB6)|(1<<PB7);
         }
       }
     }
     dezisek++;
     if (disp_set) {
       lcd_clear();
       lcd_home();

       for(i=0;i<16;i++)lcd_data(disp_buf[i]);
       lcd_setcursor(0,2);
       for(;i<32;i++)lcd_data(disp_buf[i]);

       disp_set = 0;
       _delay_ms(250);
     }
     if (relay_set) {
       PORTB |= (1<<PB4);
       PORTB |= (1<<PB5)|(1<<PB6)|(1<<PB7);
       relay_set = 0;
     }
     if (relay_reset) {
       PORTB &= ~(1<<PB4);
       PORTB &= ~((1<<PB5)|(1<<PB6)|(1<<PB7));
       relay_reset = 0; relay_timer = 0;
     }
     if (PINA & (1<<PA7)) {
       uart_putc('5');
     }
     if (PINA & (1<<PA6)) {
       uart_putc('4');
     }
     if (PINA & (1<<PA5)) {
       uart_putc('3');
     }
     if (PINA & (1<<PA4)) {
       uart_putc('2');
     }
     if (measure_temp == 1) {
       //PORTC ^= (1<<PC3);
       uint8_t sensor_id[OW_ROMCODE_SIZE];
       uint8_t diff = OW_SEARCH_FIRST;
       ow_reset();
       DS18X20_find_sensor(&diff, &sensor_id[0]);
       if (diff == OW_PRESENCE_ERR)
           strcpy_P(&disp_tmp_buf[0], PSTR("Err:Presence     "));
       else if (diff == OW_DATA_ERR)
           strcpy_P(&disp_tmp_buf[0], PSTR("Err:Data         "));
       else {
         if ( DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL ) == DS18X20_OK) {
           _delay_ms( DS18B20_TCONV_12BIT );
           int16_t decicelsius;
           if ( DS18X20_read_decicelsius( &sensor_id[0], &decicelsius) == DS18X20_OK ) {
             disp_tmp_buf[0]='T'; disp_tmp_buf[1]='e'; disp_tmp_buf[2]='m'; disp_tmp_buf[3]='p'; disp_tmp_buf[4]=':'; disp_tmp_buf[5]=' ';
             DS18X20_format_from_decicelsius( decicelsius, &disp_tmp_buf[6], 8 );
           } else {
             strcpy_P(&disp_tmp_buf[0], PSTR("Err: Read        "));
           }
         } else {
             strcpy_P(&disp_tmp_buf[0], PSTR("Err: StartMeasure"));
         }
       }
       sprintf(&disp_tmp_buf[16], "%d bytes recv.", recv_len);
       //disp_show_buf(&disp_tmp_buf[0]);
       for(i=0;i<20;i++) uart_putc(disp_tmp_buf[i]);
       measure_temp=0;
     }
     if (PINA & (1<<PA3)) {
       relay_set = 1;
       relay_timer = 10;
       uart_putc('1');
     }
     //uart_putc('+');
//     uart_putc('\n');
   }                         // (7)
   /* wird nie erreicht */
   return 0;                 // (8)
}
예제 #18
0
int8_t Menu_Root(int8_t input) {
	lcd_clear();
	lcd_home();
	switch (Menu_currState) {
		case MENU_STATE_STATUS:
			lcd_number(Clock_getHour(), 2, '0');
			lcd_data( 0x3A ); // :
			lcd_number(Clock_getMinute(), 2, '0');
			lcd_data( 0x3A ); // :
			lcd_number(Clock_getSecond(), 2, '0');
			lcd_data(' ');
			lcd_string_P(MENU_STR_OCLOCK);
			lcd_setcursor(0, 2);
			static uint8_t blink;
			if (Alarm_wasTriggered() && (blink++ & 4)) {
				lcd_data(LCD_GC_CHAR0);
				lcd_string_P(MENU_STR_ALARM_STATUS);
			} else {
				switch (Sensor_getType()) {
					case SENSOR_TYPE_SEARCHING:
						lcd_string_P(MENU_STR_SEARCHING);
						break;
					default:
					case SENSOR_TYPE_NONE:
						lcd_string_P(MENU_STR_NO_SENSOR);
						break;
					case SENSOR_TYPE_ERROR:
						lcd_string_P(MENU_STR_SENSOR_ERROR);
						break;
					case SENSOR_TYPE_SHT1X:
					case SENSOR_TYPE_HYT131:
						lcd_number(Sensor_getTemp() / 100, 2, '0');
						lcd_data(',');
						lcd_number(Sensor_getTemp() % 100, 2, '0');
						lcd_data( 0xDF ); // °
						lcd_data('C');
						lcd_data(' ');
						lcd_data(' ');
						lcd_data(' ');
						lcd_number(Sensor_getHumi() / 100, 2, '0');
						lcd_data(',');
						lcd_number(Sensor_getHumi() % 100, 2, '0');
						lcd_data('%');
						break;
				}
			}
			break;
		case MENU_STATE_FAN1:
			lcd_data('>');
			lcd_string_P(MENU_STR_FAN1);
			lcd_setcursor(0, 2);
			lcd_data(' ');
			lcd_string_P(MENU_STR_FAN2);
			break;
		case MENU_STATE_FAN2:
			lcd_data('>');
			lcd_string_P(MENU_STR_FAN2);
			lcd_setcursor(0, 2);
			lcd_data(' ');
			lcd_string_P(MENU_STR_FAN3);
			break;
		case MENU_STATE_FAN3:
			lcd_data('>');
			lcd_string_P(MENU_STR_FAN3);
			lcd_setcursor(0, 2);
			lcd_data(' ');
			lcd_string_P(MENU_STR_FAN4);
			break;
		case MENU_STATE_FAN4:
			lcd_data('>');
			lcd_string_P(MENU_STR_FAN4);
			lcd_setcursor(0, 2);
			lcd_data(' ');
			lcd_string_P(MENU_STR_ALARM);
			break;
		case MENU_STATE_ALARM:
			lcd_data('>');
			lcd_string_P(MENU_STR_ALARM);
			lcd_setcursor(0, 2);
			lcd_data(' ');
			lcd_string_P(MENU_STR_CAL);
			break;
		case MENU_STATE_CAL:
			lcd_data('>');
			lcd_string_P(MENU_STR_CAL);
			lcd_setcursor(0, 2);
			lcd_data(' ');
			lcd_string_P(MENU_STR_TIME);
			break;
		case MENU_STATE_TIME:
			lcd_data('>');
			lcd_string_P(MENU_STR_TIME);
			lcd_setcursor(0, 2);
			lcd_data(' ');
			lcd_string_P(MENU_STR_VER);
			break;
		case MENU_STATE_VER:
			lcd_data('>');
			lcd_string_P(MENU_STR_VER);
			lcd_setcursor(0, 2);
			lcd_data(' ');
			lcd_string_P(MENU_STR_BACK);
			break;
		case MENU_STATE_BACK:
			lcd_data(' ');
			lcd_string_P(MENU_STR_VER);
			lcd_setcursor(0, 2);
			lcd_data('>');
			lcd_string_P(MENU_STR_BACK);
			break;
	}
	return 0;
}
예제 #19
0
int main(void)
{
    int8_t byte_str[4];	    // Wird benutzt um hier ein Byte als String abzulegen

    // LCD Display intialisieren
    lcd_init();

    // Startmeldung ausgeben
    show_start_message();

    // Stepper Initialisieren
    init_stepper();

    // Motor Initialisieren
    init_motor();

    // Steursignale BYTE_READY, SYNC und SOE Initialisieren
    init_controll_signals();

    // Schreibschutz setzen
    clear_wps();

    // Timer0 --> GCR senden
    init_timer0();

    // Tasten Initialisieren
    init_keys();

    // Timer2 --> wird alle 1ms aufgerufen
    // z.B. zu Tasten entprellen
    init_timer2();

    // Meldung ausgeben, das auf SD Karte gewartet wird
    lcd_setcursor(0,2);
    lcd_string("Wait for SD-Karte...");

    // SD Karte initialisieren
    // Partition und Filesystem öffnen
    // Warten bis alles O.K. ist
    while(init_sd_card()){}

    lcd_clear();

    view_dir_entry(0,&file_entry);

#ifdef DEBUG_MODE
    lcd_setcursor(0,4);
    lcd_string("T:");

    lcd_setcursor(5,4);
    lcd_string("M:");

    lcd_setcursor(9,4);
    lcd_string("K:");

    lcd_setcursor(2,4);
    sprintf(byte_str,"%d",akt_half_track >> 1);
    lcd_string(byte_str);
#endif

    // Interrupts erlauben
    sei();

    while(1)
    {
	// Auf Steppermotor aktivität prüfen
	// und auswerten

	if(stepper_signal_r_pos != stepper_signal_w_pos)
	{
	    uint8_t stepper = stepper_signal_puffer[stepper_signal_r_pos++]>>2 | stepper_signal_puffer[stepper_signal_r_pos-1];

	    switch(stepper)
	    {
	    case 0x30: case 0x40: case 0x90: case 0xE0:
		// DEC
		stepper_dec();
		    stepper_signal_time = 0;
		    stepper_signal = 1;
		break;

	    case 0x10: case 0x60: case 0xB0: case 0xC0:
		// INC
		stepper_inc();
		    stepper_signal_time = 0;
		    stepper_signal = 1;
		break;
	    }
#ifdef DEBUG_MODE
	    lcd_setcursor(2,4);
	    lcd_string("   ");
	    lcd_setcursor(2,4);
	    sprintf(byte_str,"%d",akt_half_track >> 1);
	    lcd_string(byte_str);
#endif
	}
	else if(stepper_signal && (stepper_signal_time >= STEPPER_DELAY_TIME))
예제 #20
0
파일: lcd.c 프로젝트: jkriege2/QuickFit3
void lcd_init(char cursor_onoff, char cursor_blinking) {
#if (LCD_USED_CONTROLLER==LCD_CONTROLLER_KS0066) || (LCD_USED_CONTROLLER==LCD_CONTROLLER_HD44780)
    #warning "                 LCD library uses KS0066 or HD44780 controller"
    LCDPORTS_OUT();
    LCD_RS_DDR |= (1<<LCD_RS);
#if LCD_RW_CONNECTED!=0
    LCD_RW_DDR |= (1<<LCD_RW);
#endif
    LCD_EN_DDR |= (1<<LCD_EN);
    _delay_ms(40);

    // muss 3mal hintereinander gesendet werden zur Initialisierung

    RW0();        // set RW=0
    RS0();        // RS auf 0 setzen
    EN0();        // RS auf 0 setzen
    _delay_ms(40);

    if (LCD_DATASTART==0) {
        LCD_PORT &= 0xF0;
        LCD_PORT |= 0x03;               // setzen
    } else {
        LCD_PORT &= 0x0F;
        LCD_PORT |= (0x03<<4);               // setzen
    }

    LCD_RS_PORT &= ~(1<<LCD_RS);      // RS auf 0
    lcd_enable();

    _delay_ms(1);
    lcd_enable();

    _delay_ms(5);
    lcd_enable();
    _delay_ms(5);

    // 4 Bit Modus aktivieren
    if (LCD_DATASTART==0) {
        LCD_PORT &= 0xF0;
        LCD_PORT |= 0x02;               // setzen
    } else {
        LCD_PORT &= 0x0F;
        LCD_PORT |= (0x02<<4);               // setzen
    }
    lcd_enable();
    _delay_ms(5);

    // 4Bit / 2 Zeilen / 5x7
    lcd_command(0x28);

    // Display ein / Cursor aus / kein Blinken
    lcd_command(0x0C);

    // inkrement / kein Scrollen
    lcd_command(0x06);

    lcd_clear();
#elif (LCD_USED_CONTROLLER==LCD_CONTROLLER_ST7036)
    #warning "                 LCD library uses ST7036 controller"
    // set 4 data ports as outputs and all control signals as outputs
    LCDPORTS_OUT();
    LCD_RS_DDR |= (1<<LCD_RS);
    LCD_RW_DDR |= (1<<LCD_RW);
    LCD_EN_DDR |= (1<<LCD_EN);
    _delay_ms(20);

    RW0();
    RS0();
    EN0();
    _delay_ms(100);

    #if (LCD_INTERFACE == LCD_INTERFACE_4BIT)
        #warning "                 4 Bit Interface"
            // init 4-bit by sending 0b0011XXXX three times to the display
            lcd_data_out(0x03);
            _delay_ms(10);
            //lcd_enable();
            lcd_data_out(0x03);
            _delay_ms(10);
            lcd_data_out(0x03);
            _delay_ms(10);

            lcd_data_out(0x02); // function set 0b0010XXXX
            _delay_ms(10);
    #elif (LCD_INTERFACE == LCD_INTERFACE_8BIT || LCD_INTERFACE == LCD_INTERFACE_8BIT_SHIFTREG)
        #warning "                 8 Bit Interface"
            lcd_data_out(0x39);
            _delay_us(LCD_SHORTDELAY);
            lcd_data_out(0x39);
            _delay_us(LCD_SHORTDELAY);
    #endif
    uint8_t c=0x31;
    #if (LCD_VOLTAGE == LCD_VOLTAGE_5V)
        #warning "                 5V supply voltage"
        #if (LCD_LINECOUNT>1)
        c=c + 0x08;
        #endif
        lcd_command(c);    // function set        0b0011<N><DH><IS2><IS1>
                           //                     0b0011 N  0   0    1    =0x31 & (N*0x08)
        lcd_command(0x1D); // intern. osc freq.   0b0001<BS><F2><F1><F0>
                           //                     0b0001 1   1   0   1    =0x1D
        lcd_command(0x50); // power/ICON/contrast 0b0101<Ion><Bon><C5><C4>
                           //                     0b0101 0    0    0   0    =0x50
        lcd_command(0x6C); // follower control    0b0110<Fon><Rab2><Rab1><Rab0>
                           //                     0b0110  1    1     0     0    =0x6C
        lcd_command(0x7C); // contrast set        0b0111<C3><C2><C1><C0>
                           //                     0b0111 1   1   0   0    =0x7C
    #elif (LCD_VOLTAGE == LCD_VOLTAGE_3V)
        #warning "                 3V supply voltage"
        #if (LCD_LINECOUNT>1)
        c=c + 0x08;
        #endif
        lcd_command(c);    // function set        0b0011<N><DH><IS2><IS1>
                           //                     0b0011 N  0   0    1    =0x31 & (N*0x08)
        lcd_command(0x15); // intern. osc freq.   0b0001<BS><F2><F1><F0>
                           //                     0b0001 0   1   0   1    =0x15
        lcd_command(0x55); // power/ICON/contrast 0b0101<Ion><Bon><C5><C4>
                           //                     0b0101 0    1    0   1    =0x55
        lcd_command(0x6E); // follower control    0b0110<Fon><Rab2><Rab1><Rab0>
                           //                     0b0110  1    1     1     0    =0x6E
        lcd_command(0x72); // contrast set        0b0111<C3><C2><C1><C0>
                           //                     0b0111 0   0   1   0    =0x72
    #endif

    lcd_command(c & 0b11111100); // switch back to instruction table 0  0b0011<N>000  =0x38


#endif
    lcd_setcursor(1, cursor_onoff, cursor_blinking);
    lcd_setcontrast(LCD_DEFAULTCONTRAST);
    lcd_clear();
    lcd_home();
}
예제 #21
0
파일: diskIo.c 프로젝트: lodsb/LXR
//-------------------------------------------------------------------------
DSTATUS disk_initialize (BYTE drive)/* Physical drive number */
{

	unsigned char error,i;
	

	
	
	if (drive) return STA_NOINIT;		/* Supports only single drive */
	Stat |= STA_NOINIT;
	
	//init spi port for SD card
	spi_init();
//	lcd_home();
//	lcd_string_F(PSTR("spi init"));
	
	//init SD card for (i=0; i<10; i++)
	for (i=0; i<10; i++)
	{
		error = SD_init();
		if(!error) break;
	}


	if(error)
	{
		
		lcd_home();
		lcd_clear();
		lcd_string_F(PSTR("SD card"));
		lcd_setcursor(0,2);
		if(error == 1) {
			
			lcd_string_F(PSTR("not detected!"));
		}		
		else if(error == 2) lcd_string_F(PSTR("init error"));
		
		else lcd_string_F(PSTR("unknown error"));
		_delay_ms(2000);
		
		return Stat;
		

		//while(1);  //wait here forever if error in SD init 
	}
	else
	{
		lcd_home();	
		lcd_string_F(PSTR("SD card OK"));
		
	
		SPI_HIGH_SPEED;
		_delay_ms(5);

	}
	
	Stat &= ~STA_NOINIT;
	
	return Stat;

};