Example #1
0
static void eeprom_test(void)
{
    uint8_t sp[DS18X20_SP_SIZE], th, tl;

    uart_puts_P( NEWLINESTR "DS18x20 EEPROM support test for first sensor" NEWLINESTR );
    // DS18X20_eeprom_to_scratchpad(&gSensorIDs[0][0]); // already done at power-on
    th_tl_dump( sp );
    th = sp[DS18X20_TH_REG];
    tl = sp[DS18X20_TL_REG];
    tl++;
    th++;
    DS18X20_write_scratchpad( &gSensorIDs[0][0], th, tl, DS18B20_12_BIT );
    uart_puts_P( "TH+1 and TL+1 written to scratchpad" NEWLINESTR );
    th_tl_dump( sp );
    DS18X20_scratchpad_to_eeprom( DS18X20_POWER_PARASITE, &gSensorIDs[0][0] );
    uart_puts_P( "scratchpad copied to DS18x20 EEPROM" NEWLINESTR );
    DS18X20_write_scratchpad( &gSensorIDs[0][0], 0, 0, DS18B20_12_BIT );
    uart_puts_P( "TH and TL in scratchpad set to 0" NEWLINESTR );
    th_tl_dump( sp );
    DS18X20_eeprom_to_scratchpad(&gSensorIDs[0][0]);
    uart_puts_P( "DS18x20 EEPROM copied back to scratchpad" NEWLINESTR );
    DS18X20_read_scratchpad( &gSensorIDs[0][0], sp, DS18X20_SP_SIZE );
    if ( ( th == sp[DS18X20_TH_REG] ) && ( tl == sp[DS18X20_TL_REG] ) ) {
        uart_puts_P( "TH and TL verified" NEWLINESTR );
    } else {
        uart_puts_P( "verify failed" NEWLINESTR );
    }
    th_tl_dump( sp );
}
Example #2
0
static void th_tl_dump(uint8_t *sp)
{
    DS18X20_read_scratchpad( &gSensorIDs[0][0], sp, DS18X20_SP_SIZE );
    uart_puts_P( "TH/TL in scratchpad of sensor 1 now : " );
    uart_put_int( sp[DS18X20_TH_REG] );
    uart_puts_P( " / " );
    uart_put_int( sp[DS18X20_TL_REG] );
    uart_puts_P( NEWLINESTR );
}
uint8_t Sensornummer(uint8_t index)
{
	uint8_t tempScratchPad[9];
	if  ((DS18X20_read_scratchpad(&gSensorIDs[index][0], tempScratchPad ))== DS18X20_OK)
	{
		lcd_gotoxy(14,1);
		lcd_puts("GUT\0");
		return tempScratchPad[2]; // Byte 2: Nummer des Sensors
	}
	
	else 
	{
			lcd_gotoxy(14,1);
		lcd_puts("BAD\0");

		return 0xFF;
	}
}
uint8_t Sensornummerlesen(uint8_t index, uint8_t* nummer)
{
	uint8_t tempScratchPad[9];
	if  ((DS18X20_read_scratchpad(&gSensorIDs[index][0], tempScratchPad ))== DS18X20_OK)
	{
			lcd_gotoxy(14,1);
		lcd_puts("GUT\0");

		*nummer=tempScratchPad[2];
		return DS18X20_OK;
	}
	
	else 
	{
				lcd_gotoxy(14,1);
		lcd_puts("BAD\0");

		*nummer=0xFF;
		return DS18X20_ERROR;
	}
}
int main (void)
{
	/* INITIALIZE */
//	LCD_DDR |=(1<<LCD_RSDS_PIN);
//	LCD_DDR |=(1<<LCD_ENABLE_PIN);
//	LCD_DDR |=(1<<LCD_CLOCK_PIN);
	
	slaveinit();
	
   SPI_Init();
   
	lcd_initialize(LCD_FUNCTION_8x2, LCD_CMD_ENTRY_INC, LCD_CMD_ON);
	lcd_puts("Guten Tag\0");
	delay_ms(1000);
   
	lcd_cls();
   lcd_gotoxy(0,0);
	lcd_puts("MASTER\0");
	
	// DS1820 init-stuff begin
	// DS1820 init-stuff end
   
   volatile char incoming=0;
   volatile uint8_t outcounter=0;
   
   sei();
#pragma mark while
	while (1) 
	{
		loopCount0 ++;
		//_delay_ms(2);
		//LOOPLED_PORT ^= (1<<LOOPLED_PIN);
      //incoming = SPDR;
		if (loopCount0 >=0x0F)
		{
			LOOPLED_PORT ^= (1<<LOOPLED_PIN);
			loopCount1++;
         //SPDR = loopCount2;
         
  			if ((loopCount1 >0x0002F) )//&& (!(Programmstatus & (1<<MANUELL))))
			{
            SPI_PORT &= ~(1<<SPI_CS); // SS LO, Start
            
            //_delay_us(100);
            uint8_t outindex=0;
            textpos=0;
            inbuffer[0] = '\0';
            //outbuffer[0] = '\0';
            
            text[0] = 0x30+(outcounter & 0x07);
            for (outindex=0;outindex < strlen(text);outindex++)
            {
               SPDR = text[outindex];
               while(!(SPSR & (1<<SPIF)) && spiwaitcounter<0xFFF)
               {
                  spiwaitcounter++;
               }
               spiwaitcounter=0;
               incoming = SPDR;
               inbuffer[outindex] = incoming;
               outbuffer[outindex] = text[outindex];
               
            }
            
            inbuffer[outindex] = '\0';
            //outbuffer[outindex] = '\0';
            //char rest = SPDR;
            SPI_PORT |= (1<<SPI_CS); // SS HI End

            
            lcd_gotoxy(8,0);
            lcd_putc('i');
            lcd_putc(' ');
            lcd_puts((char*)inbuffer);
            
            lcd_gotoxy(8,1);
            lcd_putc('o');
             lcd_putc(' ');
            lcd_puts((char*)outbuffer);
            
            outcounter++;
            if (outcounter > 9)
            {
               //outcounter =0;
            }
            
            /*
            if (textpos == 0)
            {
               
               SPI_PORT &= ~(1<<SPI_SS); // SS LO
            }
            
            SPDR = text[textpos];
            while(!(SPSR & (1<<SPIF)) && spiwaitcounter<0xFFF)
            {
               spiwaitcounter++;
            }
            incoming = SPDR;
            spiwaitcounter=0;
            
            textpos++;
            if (textpos >= strlen(text))
            {
               textpos=0;
               SPI_PORT |= (1<<SPI_SS); // SS HI
               //SPI_PORT &= ~(1<<SPI_SS); // SS LO
            }
            */
            loopCount2++;
            /*
            lcd_gotoxy(inpos,1);
            
            lcd_putc(incoming);
            inpos++;
            if (inpos >= 19)
            {
               inpos=0;
            }
            */
            
            
            //lcd_gotoxy(18,0);
            //lcd_puthex(loopCount2);
            //LOOPLED_PORT ^= (1<<LOOPLED_PIN);
				
            //LOOPLED_PORT ^= (1<<LOOPLED_PIN);
            loopCount1=0;
            /*
             if ((SPSR & (1<<SPIF)) > 0) // checks to see if the SPI bit is clear
             {
             
             data='a'; // send the data
             }
             */
            //char incoming = SPI_get_put_char('A');
            
            
            
            
				// DS1820 loop-stuff begin
            /*
             start_temp_meas();
             delay_ms(800);
             read_temp_meas();
             
             //Sensor 1
             lcd_gotoxy(0,1);
             lcd_puts("1:\0");
             if (gTempdata[0]/10>=100)
             {
             lcd_gotoxy(1,1);
             lcd_putint((gTempdata[0]/10));
             }
             else
             {
             lcd_gotoxy(2,1);
             lcd_putint2((gTempdata[0]/10));
             }
             
             lcd_putc('.');
             lcd_putint1(gTempdata[0]%10);
             
             // Sensor 2
             lcd_gotoxy(7,1);
             lcd_puts("2:\0");
             if (gTempdata[1]/10>=100)
             {
             lcd_gotoxy(8,1);
             lcd_putint((gTempdata[1]/10));
             }
             else
             {
             lcd_gotoxy(9,1);
             lcd_putint2((gTempdata[1]/10));
             }
             
             lcd_putc('.');
             lcd_putint1(gTempdata[1]%10);
             
             // Sensor 3
             lcd_gotoxy(14,1);
             lcd_puts("3:\0");
             if (gTempdata[2]/10>=100)
             {
             lcd_gotoxy(15,1);
             lcd_putint((gTempdata[2]/10));
             }
             else
             {
             lcd_gotoxy(16,1);
             lcd_putint2((gTempdata[2]/10));
             }
             
             lcd_putc('.');
             lcd_putint1(gTempdata[2]%10);
             
             
             
             lcd_gotoxy(15,0);
             lcd_puts("   \0");
             lcd_gotoxy(15,0);
             lcd_puthex(gTemp_measurementstatus);
             
             */
				
				// DS1820 loop-stuff end
				
				
				//lcd_putint(gTempdata[1]);
				//lcd_putint(gTempdata[2]);
				//delay_ms(1000);
			}
			
			loopCount0 =0;
		}
      
      
		if (!(PINB & (1<<PB0))) // Taste 0
		{
			lcd_gotoxy(10,1);
			lcd_puts("P0 Down\0");
         lcd_puthex(TastenStatus);
			
			if (! (TastenStatus & (1<<PB0))) //Taste 0 war nicht nicht gedrueckt
			{
            lcd_gotoxy(10,1);
            lcd_puts("P0 neu \0");
				TastenStatus |= (1<<PB0);
            delay_ms(1000);
				Tastencount=0;
				//lcd_gotoxy(3,1);
				//lcd_puts("P0 \0");
				//lcd_putint(Servoimpulsdauer);
				//delay_ms(800);
				SPDR = 'x';
            while(!(SPSR & (1<<SPIF)) && spiwaitcounter<0xFFF)
            {
               spiwaitcounter++;
            }
            spiwaitcounter=0;
            delay_ms(1000);
            //lcd_gotoxy(10,1);
				//lcd_puts("       \0");
            lcd_gotoxy(19,1);
            lcd_putc('+');
			}
			else
			{
				lcd_gotoxy(19,1);
            lcd_putc('$');
				//lcd_puts("*         *\0");
				
				Tastencount ++;
				if (Tastencount >= Tastenprellen)
				{
					Tastencount=0;
					TastenStatus &= ~(1<<PB0);
               lcd_gotoxy(10,1);
               lcd_puts("*         *\0");
               

               
				}
			}//	else
			
		} // Taste 0

		
#pragma mark Tastatur 
		/* ******************** */
		initADC(TASTATURPIN);
		Tastenwert=(readKanal(TASTATURPIN)>>2);
		
//		lcd_gotoxy(3,1);
//		lcd_putint(Tastenwert);
//		Tastenwert=0;
		if (Tastenwert>5)
		{
			/*
			 0:											1	2	3
			 1:											4	5	6
			 2:											7	8	9
			 3:											x	0	y
			 4: Schalterpos -
			 5: Manuell ein
			 6: Schalterpos +
			 7: 
			 8: 
			 9: 
			 
			 12: Manuell aus
			 */
			 
			TastaturCount++;
			if (TastaturCount>=200)
			{
				
				 
				 //lcd_gotoxy(17,1);
				 //lcd_puts("T:  \0");
				 //lcd_putint(Tastenwert);
				 
				uint8_t Taste=Tastenwahl(Tastenwert);
				//Taste=0;
				 //lcd_gotoxy(19,1);
				 //lcd_putint1(Taste);
				 //delay_ms(600);
				// lcd_clr_line(1);
				 

				TastaturCount=0;
				Tastenwert=0x00;
				uint8_t i=0;
				uint8_t pos=0;
//				lcd_gotoxy(18,1);
//				lcd_putint2(Taste);
				continue;
				switch (Taste)
				{
					case 0:// Schalter auf Null-Position
					{ 
						if (Programmstatus & (1<<MANUELL))
						{
							Manuellcounter=0;
							Programmstatus |= (1<<MANUELLNEU);
							/*
							lcd_gotoxy(13,0);
							lcd_puts("S\0");
							lcd_gotoxy(19,0);
							lcd_putint1(Schalterposition); // Schalterstellung
							lcd_gotoxy(0,1);
							lcd_puts("SI:\0");
							lcd_putint(ServoimpulsdauerSpeicher); // Servoimpulsdauer
							lcd_gotoxy(5,0);
							lcd_puts("SP\0");
							lcd_putint(Servoimpulsdauer); // Servoimpulsdauer
							*/
						}
						
					}break;
						
					case 1:	//	
					{ 
					if (Programmstatus & (1<<MANUELL))
						{
						uint8_t i=0;
						lcd_gotoxy(0,0);
						lcd_puts("Sens\0");
						lcd_putc('1');
						lcd_putc(' ');
						for (i=0;i<OW_ROMCODE_SIZE;i++)
						{
						lcd_puthex(gSensorIDs[0][i]);
						if (i==3)
						{
						lcd_gotoxy(0,1);
						}
						lcd_putc(' ');
						}
						Manuellcounter=0;
						
						}
					}break;
						
					case 2://
					{ 
					
						if (Programmstatus & (1<<MANUELL))
						{
						uint8_t i=0;
						lcd_gotoxy(0,0);
						lcd_puts("Sens\0");
						lcd_putc('1');
						lcd_putc(' ');
						for (i=0;i<OW_ROMCODE_SIZE;i++)
						{
						lcd_puthex(gSensorIDs[1][i]);
						if (i==3)
						{
						lcd_gotoxy(0,1);
						}
						lcd_putc(' ');
						}
						Manuellcounter=0;
						
						
						}
						
					}break;
						
					case 3: //	Uhr aus
					{ 
						if (Programmstatus & (1<<MANUELL))
						{
						uint8_t i=0;
						lcd_gotoxy(0,0);
						lcd_puts("Sens\0");
						lcd_putc('1');
						lcd_putc(' ');
						for (i=0;i<OW_ROMCODE_SIZE;i++)
						{
						lcd_puthex(gSensorIDs[2][i]);
						if (i==3)
						{
						lcd_gotoxy(0,1);
						}
						lcd_putc(' ');
						}
						Manuellcounter=0;
						

						}
					}break;
						
					case 4://
					{ 
						DS18X20_read_scratchpad(&gSensorIDs[0][0], gScratchPad );
												uint8_t i=0;
						lcd_gotoxy(0,0);
						lcd_puts("Sens\0");
						lcd_putc('0');
						lcd_putc(' ');
						for (i=0;i<OW_ROMCODE_SIZE;i++)
						{
						lcd_puthex(gScratchPad[i]);
						if (i==3)
						{
						lcd_gotoxy(0,1);
						}
						lcd_putc(' ');
						}

					}break;
						
					case 5://
					{ 
						Programmstatus |= (1<<MANUELL);	// MANUELL ON
						Manuellcounter=0;
						MANUELL_PORT |= (1<<MANUELLPIN);
						Programmstatus |= (1<<MANUELLNEU);
						lcd_clr_line(1);
						/*
							lcd_gotoxy(13,0);
							lcd_puts("S\0");
							lcd_putint1(Schalterposition); // Schalterstellung
							lcd_gotoxy(0,1);
							lcd_puts("SP:\0");
							lcd_putint(ServoimpulsdauerSpeicher); // Servoimpulsdauer
							lcd_gotoxy(5,0);
							lcd_puts("SI\0");
							lcd_putint(Servoimpulsdauer); // Servoimpulsdauer
						*/
					}break;
						
					case 6://
					{ 
					sensornummer=0xAF;
					Sensornummerlesen(0,&sensornummer);
						lcd_gotoxy(0,0);
						lcd_puts("Sens\0");
						lcd_putc('1');
						lcd_putc(' ');
						lcd_puthex(sensornummer);
					
					}break;
						
					case 7:// Schalter rückwaerts
					{ 
					sensornummer=0x00;
					Sensornummerlesen(0,&sensornummer);
						lcd_gotoxy(0,0);
						lcd_puts("Sens\0");
						lcd_putc('0');
						lcd_putc(' ');
						lcd_puthex(sensornummer);
					
					}break;
						
					case 8://
					{ 
					sensornummer=0x00;
					Sensornummerlesen(1,&sensornummer);
						lcd_gotoxy(0,0);
						lcd_puts("Sens\0");
						lcd_putc('1');
						lcd_putc(' ');
						lcd_puthex(sensornummer);
					

					}break;
						
					case 9:// Schalter vorwaerts
					{ 
					sensornummer=0x00;
					Sensornummerlesen(2,&sensornummer);
						lcd_gotoxy(0,0);
						lcd_puts("Sens\0");
						lcd_putc('2');
						lcd_putc(' ');
						lcd_puthex(sensornummer);
					
					}break;

					case 10:// *
					{ 
						
					}break;

					case 11://
					{ 
						
					}break;
						
					case 12: // # Normalbetrieb einschalten
					{
						Programmstatus &= ~(1<<MANUELL); // MANUELL OFF
						Programmstatus &= ~(1<<MANUELLNEU);
						MANUELL_PORT &= ~(1<<MANUELLPIN);
					}
						
				}//switch Tastatur
				
//				delay_ms(400);
//				lcd_gotoxy(18,1);
//				lcd_puts("  ");		// Tastenanzeige loeschen

			}//if TastaturCount	
			
		}
	}
	
	
	return 0;
}