Пример #1
0
// Updates the x-y co-ordinates of the Create
// The orientation is indicative of the way it last moved
void updateLocation()
{
	lcd_set_cursor(0x40);
	switch(getOrientation())
	{
		case NORTH:
			++yCoord;
			lcd_write_data('N');		
			break;
		case SOUTH:
			--yCoord;
			lcd_write_data('S');
			break;
		case EAST:
			++xCoord;
			lcd_write_data('E');
			break;
		case WEST:
			--xCoord;
			lcd_write_data('W');
			break;
		default:
			break;
	}

	lcd_set_cursor(0x01);
	lcd_write_1_digit_bcd(xCoord);
	lcd_set_cursor(0x03);
	lcd_write_1_digit_bcd(yCoord);	
}
Пример #2
0
// Looks for any of the red buoy, green buoy, or force field emitted by the home base
// If the Create is in explore mode, remember and display the zone of the victim
// If the Create is in return mode, play a song and display victim found ('V'), and clear victim zone
void lookForVictim()
{
	ser_putch(142);
	ser_putch(17);
	char victim = ser_getch();
		
	if(victim > 241 && victim != 255)
	{
		if(goingHome)
		{
			__delay_ms(1000);
			play_iCreate_song(3);
			__delay_ms(500);
			victimZone = 0;
			lcd_set_cursor(0x09);
			lcd_write_data('V');
			xVictim = xCoord;
			yVictim = yCoord;
		}
		else
		{
			xVictim = xCoord;
			yVictim = yCoord;
			victimZone = getVictimZone(xCoord, yCoord);
			lcd_set_cursor(0x08);
			lcd_write_1_digit_bcd(victimZone);
		}
	}
}
Пример #3
0
void draw_qr_code()
{
    g_fill_white();
    uint8_t mult = 7;
    uint8_t xoff = 44;
    uint8_t yoff = 4;
    lcd_set_cursor(xoff, yoff);
    lcd_write_index(0x022);


    uint16_t row,  col, y, rowi, coli;
    y = yoff;
    for (row = 0; row < 33; row++)
    {
        for (rowi = 0; rowi < mult; rowi++)
        {
            lcd_end_gfx();
            lcd_set_cursor(y, xoff);
            lcd_start_gfx();
            for (col = 0; col < 33; col++)
            {
                for (coli = 0; coli < mult; coli++)
                {
                    lcd_write_data_body(code[row*33 + col]);
                }
            }
            y++;
        }

    }
    lcd_end_gfx();
}
Пример #4
0
void lcd_putc(int c)
{
	// let's process ASCII as fast as possible
	if(c < 127 && c >= 32) {
		lcd_fb_write_raw(&(lcd_chars6x8[c - 32][0]), 6);
	}
	else {
		// cyrillic is a bit slower
		if(c >= 0xC0 && c <= 0xFF)
			// cyrillic starts in font array at index 95
			lcd_fb_write_raw(&(lcd_chars6x8[c - 0xC0 + 95][0]), 6);
		else
			// handle control characters
			switch(c)
			{
			case '\n':
				// new line: new line, then do carriage return
				if(++lcd_state.current_line >= 8)
					// scroll or wrap, depending if we have a framebuffer and scrolling state
					if(lcd_state.framebuffer != NULL && (lcd_state.flags & LCD_FLAG_SCROLL)) {
						lcd_state.current_line = 7;
						lcd_scroll();
					}
			case '\r':
				// carriage return: move cursor to beginning of current line
				lcd_set_cursor(lcd_state.current_line, 0);
				return;
			case '\f':
				// form feed: clear screen
				lcd_clear();
				return;
			default:
				// non-printable character. skip it
				return;
			}
	}
	// advance cursor/scroll
	if((lcd_state.current_column += 6) >= 96) {
		// new line
		lcd_state.current_column = 0;
		if(++lcd_state.current_line >= 8) {
			// scroll or wrap, depending if we have a framebuffer and scrolling state
			if(lcd_state.framebuffer != NULL && (lcd_state.flags & LCD_FLAG_SCROLL)) {
				lcd_state.current_line = 7;
				lcd_scroll();
			}
			else
				lcd_set_cursor(0, 0);
		}
	}
}
Пример #5
0
void adc_task(void) {
    uint8_t update_time = 0;
    adc_init();
    while (1) {
        char light_str[6], temp_str[6], time_str[6];
        uint8_t light = adc_acquire(0);
        uint8_t temperature = adc_acquire(1);
        uint8_t_to_ascii(light, &(light_str[0]));
        uint8_t_to_ascii(temperature, &(temp_str[0]));
        uint8_t_to_ascii(ticks, &(time_str[0]));
        os_semaphore_wait(&lcd_sem);
        lcd_set_cursor(0, 0);
        lcd_putstr("Time: ");
        lcd_putstr(time_str);
        lcd_set_cursor(1, 0);
        lcd_putstr("Light: ");
        lcd_putstr(light_str);
        lcd_set_cursor(2, 0);
        lcd_putstr("Temp: ");
        lcd_putstr(temp_str);
        os_semaphore_signal(&lcd_sem);
        
        os_semaphore_wait(&stt_sem);
        if (state) {
            update_time = 1;
        } else {
            update_time = 0;
        }
        os_semaphore_signal(&stt_sem);
        os_semaphore_wait(&tck_sem);
        if (update_time) {
            ticks++;
        }
        os_semaphore_signal(&tck_sem);
        
        if (state == 1) {
            usart_puts("Time: ");
            usart_puts(time_str);
            usart_puts("\r\n");
            usart_puts("Light: ");
            usart_puts(light_str);
            usart_puts("\r\n");
            usart_puts("Temperature: ");
            usart_puts(temp_str);
            usart_puts("\r\n");
        }
        
        os_delay(os_get_current_pid(), 1000);
    }
}
Пример #6
0
ICACHE_FLASH_ATTR
bool display_time()
{
	bool update_time = false;
	char buff[8];

	uint8_t hour = time_hour();
	uint8_t minute = time_minute();
	uint8_t second = time_second();

	if(current_time.hour != hour)
	{
		current_time.hour = hour;
		bignumbers_print(hour / 10, 0);
		bignumbers_print(hour % 10, 3);
	}

	if(current_time.minute != minute)
	{
		current_time.minute = minute;
		bignumbers_print(minute / 10, 7);
		bignumbers_print(minute % 10, 10);
		update_time = true;
	}

	if(current_time.second != second)
	{
		current_time.second = second;
		lcd_set_cursor(14, 1);
		os_sprintf(buff, "%02d", second);
		lcd_print(buff);
	}

	return update_time;
}
//===============================================================================
//	Main Program
//===============================================================================
void main(void)
{
	//clear data port
	PORTA = 0;
	PORTB = 0;
	PORTC = 0;
	
	// Initialize the I/O port direction.
	TRISA = 0b00000000;
	TRISB = 0b00000001;

	//setup ADC
	ADCON1 = 0b00000110;		//All AN pin become digital pin
	
	LED=0;	//LED is not activated initially

	// LCD in 4-bit mode
	//-----------------------------------
	lcd_init();				//Initialize LCD

	lcd_set_cursor(1,0);	//Set cursor to column 1, line 1
	lcd_putstr("Cytron");	//Display Cytron
	lcd_goto(0x40);		//Set cursor to 2nd line using another function
	lcd_putstr("SK28A :)");	//Display SK28A
	
	while(1)
	{	
		LED ^= 1;		// toggle LED on SK28A
	    	delay_ms(50);	//delay for around 50ms	
			
		while(SW1==0)LED = 0;	//Halt and Off LED when SW1 is press, continue the program when SW1 is released or not pressed
	}

	while(1);	//infinate loop to prevent the program to reset at the end of main
}
Пример #8
0
void blit_rect(uint16_t sx, uint16_t sy, uint16_t width, uint16_t height, uint32_t start_address)
{
    //The X dim is X2 because each column is two byts
    flashstate = fs_full_blit;
    row = sy;
    col = sx*2;
    row_start = sy;
    col_start = sx*2;
    row_stop = sy + height;
    col_stop = (sx + width)*2;
    flash_pix_left = (width);
    flash_pix_left *= (height);
    flash_pix_left *= 2;

    //Start flash read
    flash_deselect();
    flash_select();
    spi2_w_b_xdiscard(0x0B);
    spi2_w_b((start_address >> 16) & 0xFF );
    spi2_w_b((start_address >> 8 ) & 0xFF );
    spi2_w_b((start_address) & 0xFF );
    spi2_rw_b(0xd0); //First dummy byte

    //Start GFX write
    lcd_set_cursor(row, col/2);
    lcd_start_gfx();
}
Пример #9
0
// Finds where there are walls around the Create's location
void findWalls()
{
	rotateIR(24, CCW);	
	lcd_set_cursor(0x0B);

	leftWall = findWall();
	if(leftWall)
		lcd_write_data('L');
	else
		lcd_write_data(' ');

	rotateIR(24, CW);
	frontWall = findWall();

	if(frontWall)
		lcd_write_data('F');
	else
		lcd_write_data(' ');
	
	rotateIR(24, CW);
	rightWall = findWall();
	
	if(rightWall)
	{
		play_iCreate_song(5);
		lcd_write_data('R');
	}else
		lcd_write_data(' ');

	rotateIR(24, CCW);	
}
Пример #10
0
void blit_window(uint16_t img_sx, uint16_t img_sy, uint16_t width, uint16_t height,
                 uint16_t asset_sx, uint16_t asset_sy, uint16_t asset_width, uint16_t asset_height, uint32_t asset_address)
{
    flashstate = fs_window_blit;
    col_start = img_sx*2;
    row_start = img_sy;
    col_stop = (img_sx + width)*2;
    row_stop = img_sy + height;
    row = row_start;
    col = col_start;
    
    flash_pix_per_row = width*2;
    flash_pix_left_in_row = flash_pix_per_row; //We inject the first two reads now
    flash_pix_rows = height;
    flash_pix_row = 0;
    flash_rowstride = asset_width*2;
    flash_base_address = asset_address +
                         (uint32_t)asset_sy*(uint32_t)asset_width*2 +
                         (uint32_t)asset_sx*2;

    flash_begin_read(flash_base_address);

    //Start GFX write
    lcd_set_cursor(row, col/2);
    lcd_start_gfx();
}
Пример #11
0
static void
gfx_set_cursor(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
{
  lcd_set_cursor(
      ctx->translation.x + x1,
      ctx->translation.y + y1,
      ctx->translation.x + x2,
      ctx->translation.y + y2);
}
Пример #12
0
void lcd_set_point(uint16_t x, uint16_t y, uint16_t color){
	
	if( (x >= MAX_X) || (y >= MAX_Y)){
		return;
	}
	
	lcd_set_cursor(x, y);
	lcd_write_reg(0x0022,color);
}
Пример #13
0
void lcd_clear(uint16_t bg){
	
	uint32_t i;
	
	lcd_set_cursor(0,0);
	
	for(i=0;i<MAX_X*MAX_Y;i++){
		lcd_write_data(bg);
	}
}
Пример #14
0
// Checks to see if the robot's current location is the pre-determined final destination
// If it is, set the goingHome bit and display 'return mode' on LCD
void checkForFinalDestination()
{
	if((xCoord == getFinalX()) && (yCoord == getFinalY()))
	{		
		play_iCreate_song(2);
		goingHome = TRUE;
		lcd_set_cursor(0x06);
		lcd_write_data('R');
	}
}
Пример #15
0
void lcd_fb_show(void)
{
	if(lcd_state.framebuffer != NULL) {
		// set pointer to video-RAM beginning
		lcd_write_command(0xB0);
		lcd_write_command(0x10);
		lcd_write_command(0x00);
		// write data
		lcd_write_raw(lcd_state.framebuffer, sizeof(lcd_state.framebuffer));
		lcd_set_cursor(lcd_state.current_line, lcd_state.current_column);
	}
}
Пример #16
0
void lcd_rect(u16 left, u16 top, u16 right, u16 bottom) {
    u16 xs = right - left;
    u16 ys = bottom - top;

    lcd_set_window(left, top, right, bottom);
    lcd_set_cursor(left, top);

    _lcd_select();
    _lcd_tx_reg(0x22);
    for(u32 i = 0; i < xs*ys; i++) {
        _lcd_tx_data(fg_color);
    }
    _lcd_deselect();
}
Пример #17
0
void lcd_fill(u32 color) {
    u16 data = lcd_pixel_from_rgb32(color);

    lcd_set_window(0, 0, 0xffff, 0xffff);
    lcd_set_cursor(0, 0);

    _lcd_select();

    _lcd_tx_reg(0x22);
    for(u32 i = 0; i < LCD_WIDTH*LCD_HEIGHT; i++) {
        _lcd_tx_data(data);
    }

    _lcd_deselect();
}
Пример #18
0
void lcd_clear(void)
{
	int i;
	uint8_t spaceholder = 0, *p = (uint8_t *)lcd_state.framebuffer;

	if(lcd_state.framebuffer != NULL) {
		for(i = 0; i < sizeof(lcd_state.framebuffer); i++)
			*p++ = spaceholder;
		lcd_write_raw(lcd_state.framebuffer, sizeof(lcd_state.framebuffer));
	}
	else
		for(i = 0; i < sizeof(lcd_state.framebuffer); i++)
			lcd_write_raw(&spaceholder, 1);

	lcd_set_cursor(0, 0);
}
Пример #19
0
void g_fill_white()
{
    lcd_set_cursor(0, 0);
    lcd_write_index(0x022);
    uint16_t x, y;

    lcd_start_gfx();
    for (x = 0; x < LCD_X; x++)
    {
        for (y = 0; y < LCD_Y; y++)
        {
            lcd_write_data_body(0xFFFF);
        }
    }
    lcd_end_gfx();
}
Пример #20
0
void show_Resis13(void) {
  uint8_t key_pressed;
  message_key_released(RESIS_13_str);	// "1-|=|-3 .."
#ifndef RMETER_WITH_L
  lcd_set_cursor(0,6);
  lcd_MEM_string(RL_METER_str);	// " [R]" or "[RL]"
#endif
#ifdef POWER_OFF
  uint8_t times;
  for (times=0;times<250;) 
 #else
  while (1)		/* wait endless without the POWER_OFF option */
 #endif
  {
        init_parts();		// set all parts to nothing found 
        GetResistance(TP3, TP1);
        GetResistance(TP1, TP3);
	lcd_line1();		// lcd_set_cursor(0,0);
        if (ResistorsFound != 0) {
           show_resis(TP1,TP3,1);
        } else {		/* no resistor found */
 #ifdef RMETER_WITH_L
           lcd_MEM_string(RESIS_13_str);
           lcd_MEM_string(RL_METER_str+4);	// " [R]" or "[RL]"
 #endif
           lcd_line2();
           lcd_data('?');		// too big
 #if LCD_LINES>2
           lcd_next_line(0);
 #endif
           lcd_clear_line();
        }
 #if defined(POWER_OFF) && defined(BAT_CHECK)
     Bat_update(times);
 #endif
     key_pressed = wait_for_key_ms(1000);
 #ifdef WITH_ROTARY_SWITCH
     if ((key_pressed != 0) || (rotary.incre > 3)) break;
 #else
     if (key_pressed != 0) break;
 #endif
 #if defined(POWER_OFF)
     times = Pwr_mode_check(times);	// no time limit with DC_Pwr_mode
 #endif
  }  /* end for times */
  lcd_clear();
} /* end show_Resis13() */
Пример #21
0
void lcd_display_string (c8_t *pac8string)
{
    // Simply write each character
    while (*pac8string)
    {
        // Hack to add support for linebreak in strings :)
        if (*pac8string == '\n')
        {
            // Jump to the second line
            lcd_set_cursor (1,0);
            pac8string++;
        }
        else
            // Otherwise display the character
            lcd_display_char (*pac8string++);
    }
}
Пример #22
0
void g_fill_rgb()
{
    lcd_set_cursor(0, 0);
    lcd_write_index(0x022);
    uint16_t x, y;

    lcd_select();
    lcd_write_data_start();
    for (x = 0; x < LCD_X; x++)
    {
        for (y = 0; y < LCD_Y; y++)
        {
            lcd_write_data_body((x << 8) | y);
        }
    }
    lcd_end_gfx();
}
Пример #23
0
/**
 * We are taking a different attitude here. We are going to assume
 * that we are moving slowly enough that the TX buffers will
 * always have space. This will be verified via logic analyser
 * later
 */
inline void check_flash_window_blit()
{
    uint8_t b;

    if (flash_pix_left_in_row == 0 && flash_pix_rows > 0)
    {
        flash_pix_left_in_row = flash_pix_per_row;
        flash_pix_rows--;
        flash_pix_row++;
        flash_begin_read(flash_base_address + (uint32_t)flash_rowstride*flash_pix_row);
    }
    if (flash_pix_left_in_row > 0)
    {   while (GFX_TX_FULL);
        while (FL_TX_FULL);
        FL_REG = 0xdb;

        flash_pix_left_in_row--;
    }

    //Check if we need to send a cursor sequence
    if (col == col_stop)
    {
        col = col_start;
        row++;
        if (row == row_stop)
        {
            flashstate = fs_idle;
            flash_deselect();
            lcd_end_gfx();
            return;
        }
        lcd_end_gfx();
        poll_tp();
        lcd_set_cursor(row, col/2);
        lcd_start_gfx();
    }

    while (GFX_TX_FULL);
    while (FL_RX_EMPTY);
    while (!GFX_RX_EMPTY) b = GFX_REG;
    col++;
    b = FL_REG;
    GFX_REG = b;

}
Пример #24
0
int main(void){
	DDRD = 0xFF;
	lcd_4bit_init();
	lcd_write_command(LCDBLINK);
	lcd_write_string("testtext", 8);
	
	lcd_set_cursor(5, 2);
	
	/*
	while (1)
	{
		PORTD ^= (1<<7);	// Toggle PORTD.7
		_delay_ms( 250 );
	}
	*/

	return 1;
}
Пример #25
0
int main(int argc, char **argv) {
    spi_init();
    _delay_ms(20);
    lcd_reset();

    while (1) {
        lcd_reset();
        _delay_ms(10);
        lcd_set_cursor(1, 1);
        lcd_send_str_p(string_1);
        _delay_ms(3000);
        lcd_clear();

        demo_circles();
        demo_lines();
        demo_pixel_set();
        demo_checker_board();
    }
}
Пример #26
0
void lcd_put_char_at(u32 data, u16 x, u16 y) {
    u8 xsize, ysize;
    u8 *char_img;
    lcd_get_char(data, &xsize, &ysize, &char_img);

    lcd_set_cursor(x, y);
    lcd_set_window(x, y, x + xsize, y + ysize);

    _lcd_select();
    _lcd_tx_reg(0x22);
    // works only for 8xN fonts
    for(u8 i = 0; i < ysize; i++) {
        u8 str = char_img[i];
        for(u8 j = 0; j < xsize; j++) {
            _lcd_tx_data((str&(1<<(xsize-j-1)))?fg_color:bg_color);
        }
    }
    _lcd_deselect();
}
Пример #27
0
//initialize the display
void lcd_init()
{
  printf("initialize lcd...");

  i2c_enable();
  const char init_commands[] = {0x38, 0x39, 0x14, 0x74, 0x54, 0x6f, 0x0c, 0x01};
  i2c_transmitinit(LCD_ADDR,8,init_commands);
  wait_for_transfer();
  cursor = 0x0f;
  line = 0x00;
  
  // turn backlight on
  lcd_backlight(1);

  lcd_print("hello boss :)");
  lcd_set_cursor(1,0);
  lcd_print("contiki booted!");

  printf("[OK]\n\r");
}
Пример #28
0
void check_flash_overlay_blit()
{
    uint8_t b;
    if (flash_pix_left > 0)
    {
        flash_pix_left--;
        FL_REG = 0xdb;
    }
    else
    {
        lcd_end_gfx();
        flashstate = fs_idle;
        flash_deselect();
        return;
    }
    while (FL_RX_EMPTY);
    b = FL_REG;
    if (b == OV_SENTINEL)
    {
        FL_REG = 0xdb;
        FL_REG = 0xdb;
        while (FL_RX_EMPTY);
        col = FL_REG;
        while (FL_RX_EMPTY);
        row = FL_REG;
        FL_REG = 0xdb;
        flash_pix_left -= 3;
        lcd_end_gfx();
        poll_tp();
        //Image stream has the thingy at the beginning
        lcd_set_cursor(row + row_start, col + col_start);
        lcd_start_gfx();
        while (FL_RX_EMPTY);
        b = FL_REG;
    }
    
    GFX_REG = b;
    while (!GFX_RX_EMPTY) b = GFX_REG;
}
Пример #29
0
	//begin of transistortester program
	int main(void) {
	  uint8_t ii;
	  unsigned int max_time;
	#ifdef SEARCH_PARASITIC
	  unsigned long n_cval;		// capacitor value of NPN B-E diode, for deselecting the parasitic Transistor
	  int8_t n_cpre;		// capacitor prefix of NPN B-E diode
	#endif
	#ifdef WITH_GRAPHICS
	  unsigned char options;
	#endif
        uint8_t vak_diode_nr;		// number of the protection diode of BJT
        union {
        uint16_t pw;
        uint8_t pb[2];
        } rpins;
        uint8_t x, y, z;
	  //switch on
	  ON_DDR = (1<<ON_PIN);			// switch to output
	  ON_PORT = (1<<ON_PIN); 		// switch power on 
	#ifndef PULLUP_DISABLE
	  RST_PORT |= (1<<RST_PIN); 	// enable internal Pullup for Start-Pin
	#endif
	  uint8_t tmp;
	  //ADC-Init
	  ADCSRA = (1<<ADEN) | AUTO_CLOCK_DIV;	//prescaler=8 or 64 (if 8Mhz clock)
	#ifdef __AVR_ATmega8__
	// #define WDRF_HOME MCU_STATUS_REG
	 #define WDRF_HOME MCUCSR
	#else
	 #define WDRF_HOME MCUSR
	 #if FLASHEND > 0x3fff
	  // probably was a bootloader active, disable the UART
	  UCSR0B = 0;		// disable UART, if started with bootloader
	 #endif
	#endif
          wait500ms();

	#if (PROCESSOR_TYP == 644) || (PROCESSOR_TYP == 1280)
	 #define BAUD_RATE 9600
//	  UBRR0H = (F_CPU / 16 / BAUD_RATE - 1) >> 8;
//	  UBRR0L = (F_CPU / 16 / BAUD_RATE - 1) & 0xff;
//	  UCSR0B = (1<<TXEN0);
//	  UCSR0C = (1<<USBS0) | (3<<UCSZ00);	// 2 stop bits, 8-bit
//	  while (!(UCSR0A & (1<<UDRE0))) { };	// wait for send data port ready 
         #ifdef SWUART_INVERT
	  SERIAL_PORT &= ~(1<<SERIAL_BIT);
         #else
	  SERIAL_PORT |= (1<<SERIAL_BIT);
         #endif
          SERIAL_DDR |= (1<<SERIAL_BIT);
	#endif

	  tmp = (WDRF_HOME & ((1<<WDRF)));	// save Watch Dog Flag
	  WDRF_HOME &= ~(1<<WDRF);	 	//reset Watch Dog flag
	  wdt_disable();			// disable Watch Dog
	#ifndef INHIBIT_SLEEP_MODE
	  // switch off unused Parts
	 #if PROCESSOR_TYP == 644
          #ifdef PRUSART1
	  PRR0 = (1<<PRTWI) |  (1<<PRSPI) | (1<<PRUSART1);
          #else
	  PRR0 = (1<<PRTWI) |  (1<<PRSPI) ;
          #endif
	//  PRR1 =  (1<<PRTIM3) ;
	 #elif PROCESSOR_TYP == 1280
	  PRR0 = (1<<PRTWI) |  (1<<PRSPI) | (1<<PRUSART1);
	  PRR1 = (1<<PRTIM5) | (1<<PRTIM4) | (1<<PRTIM3) | (1<<PRUSART3) | (1<<PRUSART2) | (1<<PRUSART3);
	 #else
	  PRR = (1<<PRTWI) | (1<<PRSPI) | (1<<PRUSART0);
	 #endif
//	disable digital inputs of Analog pins, but TP1-3 digital inputs must be left enabled for VGS measurement
	  DIDR0 = ((1<<ADC5D) | (1<<ADC4D) | (1<<ADC3D) | (1<<ADC2D) | (1<<ADC1D) | (1<<ADC0D)) & ~((1<<TP3) | (1<<TP2) | (1<<TP1));	
	  TCCR2A = (0<<WGM21) | (0<<WGM20);		// Counter 2 normal mode
	  TCCR2B = CNTR2_PRESCALER;	//prescaler set in autoconf
	#endif		/* INHIBIT_SLEEP_MODE */
	  sei();				// enable interrupts
	  lcd_init();				//initialize LCD
		
	//  ADC_PORT = TXD_VAL;
	//  ADC_DDR = TXD_MSK;
	  if(tmp) { 
	     // check if  Watchdog-Event 
	     // this happens, if the Watchdog is not reset for 2s
	     // can happen, if any loop in the Program doen't finish.
	     lcd_line1();
             lcd_MEM_string(TestTimedOut);	//Output Timeout
	     wait_about3s();			// time to read the Timeout message
	     switch_tester_off();
	     return 0;
	  }

	#ifdef PULLUP_DISABLE
	 #ifdef __AVR_ATmega8__
	  SFIOR = (1<<PUD);		// disable Pull-Up Resistors mega8
	 #else
	  MCUCR = (1<<PUD);		// disable Pull-Up Resistors mega168 family
	 #endif
	#endif

	//#if POWER_OFF+0 > 1
	  // tester display time selection
	#ifndef USE_EEPROM
	  EE_check_init();		// init EEprom, if unset
	#endif
	#ifdef WITH_ROTARY_SWITCH
	//  rotary_switch_present = eeprom_read_byte(&EE_RotarySwitch);
	  rotary.ind = ROT_MSK+1;		//initilize state history with next call of check_rotary()
	#endif
#ifdef WITH_HARDWARE_SERIAL
//	ii = 60;
	ii = 30;
#else
	#if 1
	  for (ii=0; ii<60; ii++) {
		if (RST_PIN_REG & (1 << RST_PIN))
			break;	// button is released
	     wait_about10ms();
	  }
	#else
	  ii = 0;
	  if (!(RST_PIN_REG & (1<<RST_PIN))) {
	     // key is still pressed
	     ii = wait_for_key_ms(700);	
	  }
	#endif
	  display_time = OFF_WAIT_TIME;		// LONG_WAIT_TIME for single mode, else SHORT_WAIT_TIME
	  if (ii > 30) {
	     display_time = LONG_WAIT_TIME;	// ... set long time display anyway
	  }
#endif // WITH_HARDWARE_SERIAL
	#if POWER_OFF+0 > 1
	  empty_count = 0;
	  mess_count = 0;
	#endif
	  ADCconfig.RefFlag = 0;
	  Calibrate_UR();		// get Ref Voltages and Pin resistance
	#ifdef WDT_enabled
	  wdt_enable(WDTO_2S);		//Watchdog on
	#endif
	#ifdef WITH_MENU
	  if (ii >= 60) {
		while(function_menu());		// selection of function
	  }
	#endif

	//*****************************************************************
	//Entry: if start key is pressed before shut down
	loop_start:
	#if ((LCD_ST_TYPE == 7565) || (LCD_ST_TYPE == 1306))
	  lcd_command(CMD_DISPLAY_ON);
	  lcd_command(CMD_SET_ALLPTS_NORMAL);		// 0xa4
	#endif
	  lcd_clear();			// clear the LCD
	  ADC_DDR = TXD_MSK;		// activate Software-UART 
          init_parts();			// reset parts info to nothing found
	  Calibrate_UR();		// get Ref Voltages and Pin resistance
	  lcd_line1();			// Cursor to 1. row, column 1
	  
	#ifdef BAT_CHECK
	  // Battery check is selected
        Battery_check();
	#else
	  lcd_MEM_string(VERSION_str);		// if no Battery check, Version .. in row 1
	#endif	/* BAT_CHECK */

	  // begin tests
	#if FLASHEND > 0x1fff
	  if (WithReference) {
	     /* 2.5V precision reference is checked OK */
	 #if POWER_OFF+0 > 1
	     if ((mess_count == 0) && (empty_count == 0))
	 #endif
	     {
		 /* display VCC= only first time */
		 lcd_line2();
		 lcd_MEM_string(VCC_str);		// VCC=
		 Display_mV(ADCconfig.U_AVCC,3);	// Display 3 Digits of this mV units
		 lcd_refresh();			// write the pixels to display, ST7920 only
		 wait_about1s();		// time to read the VCC= message
	     }
	  }
	#endif
	#ifdef WITH_VEXT
	  unsigned int Vext;
	  // show the external voltage
	  while (!(RST_PIN_REG & (1<<RST_PIN))) {
	     lcd_clear_line2();
	     lcd_MEM_string(Vext_str);		// Vext=
	     ADC_DDR = 0;		//deactivate Software-UART
	     Vext = W5msReadADC(TPext);	// read external voltage 
	//     ADC_DDR = TXD_MSK;		//activate Software-UART 
	    uart_newline();		// MAURO replaced uart_putc(' ') by uart_newline(), 'Z'
	 #if EXT_NUMERATOR <= (0xffff/U_VCC)
	     Display_mV(Vext*EXT_NUMERATOR/EXT_DENOMINATOR,3);	// Display 3 Digits of this mV units
	 #else
             DisplayValue((unsigned long)Vext*EXT_NUMERATOR/EXT_DENOMINATOR,-3,'V',3);  // Display 3 Digits of this mV units
	 #endif
	     lcd_refresh();		// write the pixels to display, ST7920 only
	     wait_about300ms();		// delay to read the Vext= message
	  }
	#endif /* WITH_VEXT */

	#ifndef DebugOut
	  lcd_line2();			//LCD position row 2, column 1
	#endif
	  EntladePins();		// discharge all capacitors!
	  if(PartFound == PART_CELL) {
	    lcd_clear();
	    lcd_MEM_string(Cell_str);	// display "Cell!"
	#if FLASHEND > 0x3fff
	    lcd_line2();		// use LCD line 2
	    Display_mV(cell_mv[0],3);
	    lcd_space();
	    Display_mV(cell_mv[1],3);
	    lcd_space();
	    Display_mV(cell_mv[2],3);
	#endif
	#ifdef WITH_SELFTEST
	    lcd_refresh();			// write the pixels to display, ST7920 only
	    wait_about2s();
	    AutoCheck(0x11);		// full Selftest with "Short probes" message
	#endif
	    goto tt_end;
	  }

	#ifdef WITH_SELFTEST
	 #ifdef AUTO_CAL
	  lcd_cursor_off();
	  UnCalibrated = (eeprom_read_byte(&c_zero_tab[3]) - eeprom_read_byte(&c_zero_tab[0]));
	  if (UnCalibrated != 0) {
	     // if calibrated, both c_zero_tab values are identical! c_zero_tab[3] is not used otherwise
	     lcd_cursor_on();
	  }
	 #endif
	 #ifdef WITH_MENU
	  AutoCheck(0x00);			//check, if selftest should be done, only calibration
	 #else
	  AutoCheck(0x01);			//check, if selftest should be done, full selftest without MENU
	 #endif
	#endif
	#if FLASHEND > 0x1fff
          lcd_clear_line2();			//LCD position row2, column 1
        #else
          lcd_line2();				//LCD position row2, column 1
        #endif
	  lcd_MEM_string(TestRunning);		//String: testing...
	  lcd_refresh();			// write the pixels to display, ST7920 only
	 #ifdef WITH_UART
	    uart_putc(0x03);		// ETX, start of new measurement 
	    uart_newline();			 // MAURO Added
	 #endif
//
	  // check all 6 combinations for the 3 pins 
	//         High  Low  Tri
	  CheckPins(TP1, TP2, TP3);
	  CheckPins(TP2, TP1, TP3);

	  CheckPins(TP1, TP3, TP2);
	  CheckPins(TP3, TP1, TP2);

	  CheckPins(TP2, TP3, TP1);
	  CheckPins(TP3, TP2, TP1);

	  // Capacity measurement is only possible correctly with two Pins connected.
	  // A third connected pin will increase the capacity value!
	//  if(((PartFound == PART_NONE) || (PartFound == PART_RESISTOR) || (PartFound == PART_DIODE)) ) {
	  if(PartFound == PART_NONE) {
	     // If no part is found yet, check separate if is is a capacitor
#ifdef DebugOut
	     lcd_data('C');
#endif
	     EntladePins();		// discharge capacities
	     //measurement of capacities in all 3 combinations
	     ReadCapacity(TP3, TP1);
#ifdef DebugOut
	     lcd_data('K');
#endif
	#if DebugOut != 10
	     ReadCapacity(TP3, TP2);
#ifdef DebugOut
	     lcd_data('K');
#endif
	     ReadCapacity(TP2, TP1);
#ifdef DebugOut
	     lcd_data('K');
#endif
	#endif
	  }

#ifdef WITH_UJT
// check for UJT
        if (PartFound==PART_DIODE       
            && NumOfDiodes==2                // UJT is detected as 2 diodes E-B1 and E-B2...
//            && ResistorsFound==1             // ...and a resistor B1-B2
            && diodes.Anode[0]==diodes.Anode[1]      // check diodes have common anode
//            && (unsigned char)(ResistorList[0]+diodes.Anode[0])==2    // and resistor is between cathodes
           ) 
           // note: there also exist CUJTs (complementary UJTs); they seem to be (even) rarer than UJTs, and are not supported for now
           {
            CheckUJT();
        }
#endif		/* defined WITH_UJT */

#ifdef WITH_XTAL
        if (PartFound==PART_NONE || ((PartFound==PART_CAPACITOR) && (cap.cpre_max == -12))) {
           // still not recognized anything? then check for ceramic resonator or crystal
           // these tests are time-consuming, so we do them last, and only on TP1/TP3
           sampling_test_xtal();
        }
#endif

	  //All checks are done, output result to display

	#ifdef DebugOut 
	  // only clear two lines of LCD

	  lcd_clear_line1();
	#else
	  lcd_clear();				// clear total display
	#endif

	  _trans = &ntrans;			// default transistor structure to show
	  if (PartFound == PART_THYRISTOR) {
#ifdef WITH_GRAPHICS
            lcd_big_icon(THYRISTOR|LCD_UPPER_LEFT);
            lcd_draw_trans_pins(-8, 16);
            lcd_set_cursor(0,TEXT_RIGHT_TO_ICON);		// position behind the icon, Line 1
	    lcd_MEM_string(Thyristor);		//"Thyristor"
#else
	    lcd_MEM_string(Thyristor);		//"Thyristor"
            PinLayout(Cathode_char,'G','A'); 	// CGA= or 123=...
#endif
            goto TyUfAusgabe;
          }

  if (PartFound == PART_TRIAC) {
#ifdef WITH_GRAPHICS
    lcd_big_icon(TRIAC|LCD_UPPER_LEFT);
    lcd_draw_trans_pins(-8, 16);
    lcd_set_cursor(0,TEXT_RIGHT_TO_ICON);		// position behind the icon, Line 1
    lcd_MEM_string(Triac);		//"Triac"
#else
    lcd_MEM_string(Triac);		//"Triac"
    PinLayout('1','G','2'); 	// CGA= or 123=...
#endif
    goto TyUfAusgabe;
  }

#ifdef WITH_PUT
   if (PartFound == PART_PUT) {
      static const unsigned char PUT_str[] MEM_TEXT = "PUT";
      lcd_MEM_string(PUT_str);
      _trans=&ptrans;
      PinLayout('A','G',Cathode_char);
      goto TyUfAusgabe;
   }
#endif

#ifdef WITH_UJT
   if (PartFound == PART_UJT) {
      static const unsigned char UJT_str[] MEM_TEXT = "UJT";
      lcd_MEM_string(UJT_str);
      PinLayout('1','E','2');
 #ifdef SamplingADC
      static const unsigned char eta_str[] MEM_TEXT = " eta=";
      lcd_next_line(0);
      ResistorChecked[ntrans.e - TP_MIN + ntrans.c - TP_MIN - 1] = 0;	// forget last resistance measurement
      GetResistance(ntrans.c, ntrans.e);	// resistor value is in ResistorVal[resnum]
      DisplayValue(ResistorVal[ntrans.e - TP_MIN + ntrans.c - TP_MIN - 1],-1,LCD_CHAR_OMEGA,2);
      lcd_MEM_string(eta_str);		//"eta="
      DisplayValue(ntrans.gthvoltage,0,'%',3);
 #else /* ! SamplingADC */
      static const unsigned char R12_str[] MEM_TEXT = "R12=";
      lcd_next_line(0);
      lcd_MEM_string(R12_str);		//"R12="
      DisplayValue(ResistorVal[ntrans.e - TP_MIN + ntrans.c - TP_MIN - 1],-1,LCD_CHAR_OMEGA,2);
      lcd_data(',');
      DisplayValue(((RR680PL * (unsigned long)(ADCconfig.U_AVCC - ntrans.uBE)) / ntrans.uBE)-RRpinPL,-1,LCD_CHAR_OMEGA,3);
 #endif	 /* SamplingADC */
      goto tt_end;
   }
#endif /* WITH_UJT */

  if (PartFound == PART_CAPACITOR) {
#if FLASHEND > 0x3fff
     if ((cap.ca + cap.cb) == (TP1 + TP3)) {
        show_Cap13();		// repeated capacity measurement
        goto shut_off;		// key was pressed or timeout
     }
     show_cap(0);		// show capacity in normal way and measure additional parameters
#else
     show_cap_simple();		// show capacity in normal way and measure additional parameters
#endif
     goto tt_end;
  } /* end PartFound == PART_CAPACITOR */

#ifdef WITH_XTAL
  if (PartFound == PART_CERAMICRESONATOR) {
//      static const unsigned char cerres_str[] MEM_TEXT = "Cer.resonator  ";
      lcd_MEM_string(cerres_str);
      if (sampling_measure_xtal()) goto loop_start;
      goto tt_end;
  }
  if (PartFound == PART_XTAL) {
//      static const unsigned char xtal_str[] MEM_TEXT = "Crystal  ";
      lcd_MEM_string(xtal_str);
      if (sampling_measure_xtal()) goto loop_start;
      goto tt_end;
  }
#endif

  // ========================================
  if(PartFound == PART_DIODE) {
  // ========================================
     if(NumOfDiodes == 1) {		//single Diode
//        lcd_MEM_string(Diode);		//"Diode: "
#if FLASHEND > 0x1fff
        // enough memory (>8k) to sort the pins and additional Ir=
        DiodeSymbol_withPins(0);
	GetIr(diodes.Cathode[0],diodes.Anode[0]);	// measure and output Ir=x.xuA
#else
        // too less memory to sort the pins
        DiodeSymbol_withPins(0);
#endif
        UfAusgabe(0x70);		// mark for additional resistor and output Uf= in line 2
#ifndef SamplingADC
        /* load current of capacity is (5V-1.1V)/(470000 Ohm) = 8298nA */
        ReadCapacity(diodes.Cathode[0],diodes.Anode[0]);	// Capacity opposite flow direction
        if (cap.cpre < -3) {	/* capacity is measured */
 #if (LCD_LINES > 2)
           lcd_line3();		// output Capacity in line 3
 #endif
           lcd_MEM_string(Cap_str);	//"C="
 #if LCD_LINE_LENGTH > 16
           DisplayValue(cap.cval,cap.cpre,'F',3);
 #else
           DisplayValue(cap.cval,cap.cpre,'F',2);
 #endif
        }
#else  // SamplingADC
showdiodecap:
        cap.cval=sampling_cap(diodes.Cathode[0],diodes.Anode[0],0);   // at low voltage
        lcd_next_line_wait(0);		// next line, wait 5s and clear line 2
        DisplayValue(cap.cval,sampling_cap_pre,'F',2);
 #ifdef PULLUP_DISABLE
        lcd_data('-');
        cap.cval=sampling_cap(diodes.Cathode[0],diodes.Anode[0],1);   // at high voltage
        if (cap.cval < 0) cap.cval = 0;		// don't show negativ value
        DisplayValue(cap.cval,sampling_cap_pre,'F',2);
  #if LCD_LINE_LENGTH > 16
        lcd_MEM_string(AT05volt);	// " @0-5V"
  #else
        lcd_MEM_string(AT05volt+1);	// "@0-5V"
  #endif
        uart_newline();			// MAURO Diode ('A')
 #else
  #warning Capacity measurement from high to low not possible for diodes without PULLUP_DISABLE option!
 #endif  /* PULLUP_DISABLE */
#endif
        goto end3;
     } else if(NumOfDiodes == 2) { // double diode
        lcd_data('2');
        lcd_MEM_string(Dioden);		//"diodes "
        if(diodes.Anode[0] == diodes.Anode[1]) { //Common Anode
           DiodeSymbol_CpinApin(0);	// 1-|<-2
           DiodeSymbol_ACpin(1);	//  ->|-3
           UfAusgabe(0x01);
#ifdef SamplingADC
           goto showdiodecap;   // double diodes are often varicap; measure capacitance of one of them
#else
           goto end3;
#endif
        } 
        if(diodes.Cathode[0] == diodes.Cathode[1]) { //Common Cathode
           DiodeSymbol_ApinCpin(0);	// 1->|-2
           DiodeSymbol_CApin(1);	//  -|<-3
           UfAusgabe(0x01);
#ifdef SamplingADC
           goto showdiodecap;   // double diodes are often varicap; measure capacitance of one of them
#else
           goto end3;
#endif
//        else if ((diodes.Cathode[0] == diodes.Anode[1]) && (diodes.Cathode[1] == diodes.Anode[0])) 
        } 
        if (diodes.Cathode[0] == diodes.Anode[1]) {
           // normaly two serial diodes are detected as three diodes, but if the threshold is high
           // for both diodes, the third diode is not detected.
           // can also be Antiparallel
           diode_sequence = 0x01;	// 0 1
           SerienDiodenAusgabe();
           goto end3;
        } 
        if (diodes.Cathode[1] == diodes.Anode[0]) {
           diode_sequence = 0x10;	// 1 0
           SerienDiodenAusgabe();
           goto end3;
        }
     } else if(NumOfDiodes == 3) {
        //Serial of 2 Diodes; was detected as 3 Diodes 
        diode_sequence = 0x33;	// 3 3
        /* Check for any constellation of 2 serial diodes:
          Only once the pin No of anyone Cathode is identical of another anode.
          two diodes in series is additionally detected as third big diode.
        */
			if (diodes.Cathode[0] == diodes.Anode[1]) {
           diode_sequence = 0x01;	// 0 1
          }
			if (diodes.Anode[0] == diodes.Cathode[1]) {
           diode_sequence = 0x10;	// 1 0
          }
			if (diodes.Cathode[0] == diodes.Anode[2]) {
           diode_sequence = 0x02;	// 0 2
          }
			if (diodes.Anode[0] == diodes.Cathode[2]) {
           diode_sequence = 0x20;	// 2 0
          }
			if (diodes.Cathode[1] == diodes.Anode[2]) {
           diode_sequence = 0x12;	// 1 2
          }
			if (diodes.Anode[1] == diodes.Cathode[2]) {
           diode_sequence = 0x21;	// 2 1
          }
//        if((ptrans.b<3) && (ptrans.c<3)) 
        if(diode_sequence < 0x22) {
           lcd_data('3');
           lcd_MEM_string(Dioden);	//"Diodes "
           SerienDiodenAusgabe();
           goto end3;
        }
     }  // end (NumOfDiodes == 3)
     lcd_MEM_string(Bauteil);		//"Bauteil"
     lcd_MEM_string(Unknown); 		//" unbek."
     lcd_line2(); //2. row 
     lcd_data(NumOfDiodes + '0');
     lcd_data('*');
     lcd_MEM_string(AnKat_str);		//"->|-"
     lcd_MEM_string(Detected);		//" detected"
     goto not_known;
     // end (PartFound == PART_DIODE)
  // ========================================
  } else if (PartFound == PART_TRANSISTOR) {
  // ========================================
#ifdef SEARCH_PARASITIC
    if ((ptrans.count != 0) && (ntrans.count !=0)) {
       // Special Handling of NPNp and PNPn Transistor.
       // If a protection diode is built on the same structur as the NPN-Transistor,
       // a parasitic PNP-Transistor will be detected. 
       ReadCapacity(ntrans.e, ntrans.b);	// read capacity of NPN base-emitter
       n_cval = cap.cval;			// save the found capacity value
       n_cpre  = cap.cpre;			// and dimension
       ReadCapacity(ptrans.b, ptrans.e);	// read capacity of PNP base-emitter
       // check if one hfe is very low. If yes, simulate a very low BE capacity
       if ((ntrans.hfe < 500) && (ptrans.hfe >= 500)) n_cpre = -16; // set NPN BE capacity to low value
       if ((ptrans.hfe < 500) && (ntrans.hfe >= 500)) cap.cpre = -16; // set PNP BE capacity to low value

       if (((n_cpre == cap.cpre) && (cap.cval > n_cval))
					|| (cap.cpre > n_cpre)) {
          // the capacity value or dimension of the PNP B-E is greater than the NPN B-E
          PartMode = PART_MODE_PNP;
       } else {
          PartMode = PART_MODE_NPN;
       }
    }  /* end ((ptrans.count != 0) && (ntrans.count !=0)) */
#endif
    // not possible for mega8, change Pin sequence instead.
		if ((ptrans.count != 0) && (ntrans.count != 0)
				&& (!(RST_PIN_REG & (1 << RST_PIN)))) {
       // if the Start key is still pressed, use the other Transistor
#if 0
       if (PartMode == PART_MODE_NPN) {
          PartMode = PART_MODE_PNP;	// switch to parasitic transistor
       } else {
          PartMode = PART_MODE_NPN;	// switch to parasitic transistor
       }
#else
       PartMode ^= (PART_MODE_PNP - PART_MODE_NPN);
#endif
    }

#ifdef WITH_GRAPHICS
    lcd_set_cursor(0,TEXT_RIGHT_TO_ICON);			// position behind the icon, Line 1
    lcd_big_icon(BJT_NPN|LCD_UPPER_LEFT);	// show the NPN Icon at lower left corner
    if(PartMode == PART_MODE_NPN) {
//       _trans = &ntrans;  is allready selected a default
       lcd_MEM_string(NPN_str);		//"NPN "
       if (ptrans.count != 0) {
          lcd_data('p');		// mark for parasitic PNp
       }
    } else {
       _trans = &ptrans;		// change transistor structure
       lcd_update_icon(bmp_pnp);	// update for PNP
       lcd_MEM_string(PNP_str);		//"PNP "
       if (ntrans.count != 0) {
          lcd_data('n');		// mark for parasitic NPn
       }
    }
#else 	/* only character display */
    if(PartMode == PART_MODE_NPN) {
//       _trans = &ntrans;  is allready selected a default
       lcd_MEM_string(NPN_str);		//"NPN "
       if (ptrans.count != 0) {
          lcd_data('p');		// mark for parasitic PNp
       }
    } else {
       _trans = &ptrans;		// change transistor structure
       lcd_MEM_string(PNP_str);		//"PNP "
       if (ntrans.count != 0) {
          lcd_data('n');		// mark for parasitic NPn
       }
    }
    lcd_space();
#endif

    // show the protection diode of the BJT
    vak_diode_nr = search_vak_diode();
    if (vak_diode_nr < 5) {
    // no side of the diode is connected to the base, this must be the protection diode   
#ifdef WITH_GRAPHICS
       options = 0;
       if (_trans->c != diodes.Anode[vak_diode_nr])
          options |= OPT_VREVERSE;
       lcd_update_icon_opt(bmp_vakdiode,options);	// show the protection diode right to the Icon
#else    /* only character display, show the diode in correct direction */    
       char an_cat;			// diode is anode-cathode type
       an_cat = 0;
 #ifdef EBC_STYLE
  #if EBC_STYLE == 321
       // Layout with 321= style
       an_cat = (((PartMode == PART_MODE_NPN) && (ntrans.c < ntrans.e)) ||
                 ((PartMode != PART_MODE_NPN) && (ptrans.c > ptrans.e)));
  #else
       // Layout with EBC= style
       an_cat = (PartMode == PART_MODE_NPN);
  #endif
 #else
       // Layout with 123= style
       an_cat = (((PartMode == PART_MODE_NPN) && (ntrans.c > ntrans.e))
		|| ((PartMode != PART_MODE_NPN) && (ptrans.c < ptrans.e)));
 #endif
       if (an_cat) {
          lcd_MEM_string(AnKat_str);	//"->|-"
       } else {
          lcd_MEM_string(KatAn_str);	//"-|<-"
       }
#endif    /* !WITH_GRAPHICS */
    }  /* endif vak_diode_nr < 6 */

#ifdef WITH_GRAPHICS
    lcd_draw_trans_pins(-7, 16);	// show the pin numbers
    lcd_next_line(TEXT_RIGHT_TO_ICON);	// position behind the icon, Line 2
    lcd_MEM_string(hfe_str);		//"B="  (hFE)
    DisplayValue(_trans->hfe,-2,0,3);

    lcd_next_line(TEXT_RIGHT_TO_ICON+1-LOW_H_SPACE); // position behind the icon+1, Line 3
    lcd_data('I');
    if (_trans->current >= 10000) {
       lcd_data('e');				// emitter current has 10mA offset
       _trans->current -= 10000;
    } else {
       lcd_data('c');
    }
    lcd_equal();			// lcd_data('=');
    DisplayValue16(_trans->current,-6,'A',2);	// display Ic or Ie current

    lcd_next_line(TEXT_RIGHT_TO_ICON); // position behind the icon, Line 4
    lcd_MEM_string(Ube_str);		//"Ube="
    Display_mV(_trans->uBE,3-LOW_H_SPACE);
    last_line_used = 1;

 #ifdef SHOW_ICE
    if (_trans->ice0 > 0) {
       lcd_next_line_wait(TEXT_RIGHT_TO_ICON-1-LOW_H_SPACE); // position behind the icon, Line 4 & wait and clear last line
       lcd_MEM2_string(ICE0_str);		// "ICE0="
       DisplayValue16(_trans->ice0,-6,'A',2);	// display ICEO
    }
    if (_trans->ices > 0) {
       lcd_next_line_wait(TEXT_RIGHT_TO_ICON-1-LOW_H_SPACE); // position behind the icon, Line 4 & wait and clear last line
       lcd_MEM2_string(ICEs_str);		// "ICEs="
       DisplayValue16(_trans->ices,-6,'A',2);	// display ICEs
    }
 #endif
#else		/* character display */
    PinLayout('E','B','C'); 		//  EBC= or 123=...
    lcd_line2(); //2. row 
    lcd_MEM_string(hfe_str);		//"B="  (hFE)
    DisplayValue(_trans->hfe,-2,0,3);
 #if FLASHEND > 0x1fff
    lcd_space();

    lcd_data('I');
    if (_trans->current >= 10000) {
       lcd_data('e');				// emitter current has 10mA offset
       _trans->current -= 10000;
    } else {
       lcd_data('c');
    }
    lcd_equal();			// lcd_data('=');
    DisplayValue16(_trans->current,-6,'A',2);	// display Ic or Ie current
 #endif

 #if defined(SHOW_ICE)
    lcd_next_line_wait(0);		// next line, wait 5s and clear line 2
    lcd_MEM_string(Ube_str);		//"Ube=" 
    Display_mV(_trans->uBE,3);

    if (_trans->ice0 > 0) {
       lcd_next_line_wait(0);		// next line, wait 5s and clear line 2
       lcd_MEM2_string(ICE0_str);		// "ICE0="
       DisplayValue16(_trans->ice0,-6,'A',3);
    }
    if (_trans->ices > 0) {
       lcd_next_line_wait(0);		// next line, wait 5s and clear line 2
       lcd_MEM2_string(ICEs_str);		// "ICEs="
       DisplayValue16(_trans->ices,-6,'A',3);
    }
 #endif
#endif  /* WITH_GRAPHICS */
#ifdef SHOW_VAKDIODE
    if (vak_diode_nr < 5) {
       lcd_next_line_wait(0); 		// next line, wait 5s and clear line 2/4
       DiodeSymbol_withPins(vak_diode_nr);
       lcd_MEM_string(Uf_str);			//"Uf="
       mVAusgabe(vak_diode_nr);
       uart_newline();			// MAURO not verified ('D')
    } /* end if (vak_diode_nr < 5) */
#endif
#ifdef WITH_GRAPHICS
    PinLayoutLine('E','B','C'); 		//  Pin 1=E ...
    uart_newline();			// MAURO OK BJT ('E')
#endif
    goto tt_end;
    // end (PartFound == PART_TRANSISTOR)

  // ========================================
  } else if (PartFound == PART_FET) {	/* JFET or MOSFET */
  // ========================================
#ifdef WITH_GRAPHICS
    unsigned char fetidx = 0;
    lcd_set_cursor(0,TEXT_RIGHT_TO_ICON);	// position behind the icon, Line 1
#endif
    if((PartMode&P_CHANNEL) == P_CHANNEL) {
       lcd_data('P');			//P-channel
       _trans = &ptrans;
#ifdef WITH_GRAPHICS
       fetidx = 2;
#endif
    } else {
       lcd_data('N');			//N-channel
//       _trans = &ntrans;	is allready selected as default
    }
    lcd_data('-');		// minus is used for JFET, D-MOS, E-MOS ...

    uint8_t part_code;
    part_code = PartMode&0x0f;
#ifdef WITH_GRAPHICS
    if (part_code == PART_MODE_JFET) {
       lcd_MEM_string(jfet_str);	//"JFET"
       lcd_big_icon(N_JFET|LCD_UPPER_LEFT);
       if (fetidx != 0) {
          lcd_update_icon(bmp_p_jfet); // update the n_jfet bitmap to p_jfet
       }
    } else {		// no JFET
       if ((PartMode&D_MODE) == D_MODE) {
          lcd_data('D');			// N-D or P-D
          fetidx += 1;
       } else {
          lcd_data('E');			// N-E or P-E
       }
       if (part_code == (PART_MODE_IGBT)) {
          lcd_MEM_string(igbt_str);	//"-IGBT"
          lcd_big_icon(N_E_IGBT|LCD_UPPER_LEFT);
          if (fetidx == 1)  lcd_update_icon(bmp_n_d_igbt);
          if (fetidx == 2)  lcd_update_icon(bmp_p_e_igbt);
          if (fetidx == 3)  lcd_update_icon(bmp_p_d_igbt);
       } else {
          lcd_MEM_string(mosfet_str);	//"-MOS "
          lcd_big_icon(N_E_MOS|LCD_UPPER_LEFT);
          if (fetidx == 1)  lcd_update_icon(bmp_n_d_mos);
          if (fetidx == 2)  lcd_update_icon(bmp_p_e_mos);
          if (fetidx == 3)  lcd_update_icon(bmp_p_d_mos);
       }
    } /* end PART_MODE_JFET */
#else	/* normal character display */
    if (part_code == PART_MODE_JFET) {
       lcd_MEM_string(jfet_str);	//"-JFET"
    } else {		// no JFET
       if ((PartMode&D_MODE) == D_MODE) {
          lcd_data('D');			// N-D or P-D
       } else {
          lcd_data('E');			// N-E or P-E
       }
       if (part_code == (PART_MODE_IGBT)) {
          lcd_MEM_string(igbt_str);	//"-IGBT"
       } else {
          lcd_MEM_string(mosfet_str);	//"-MOS "
       }
    } /* end PART_MODE_JFET */

    if (part_code == PART_MODE_IGBT) {
       PinLayout('E','G','C'); 		//  SGD= or 123=...
    } else if (part_code == PART_MODE_JFET) {
       PinLayout('?','G','?'); 		//  ?G?= or 123=...
    } else {
       PinLayout('S','G','D'); 		//  SGD= or 123=...
    }
#endif  /* WITH_GRAPHICS */

    vak_diode_nr = search_vak_diode();
    if(vak_diode_nr < 5) {
       //MOSFET with protection diode; only with enhancement-FETs

#ifndef WITH_GRAPHICS
 #if FLASHEND <= 0x1fff
       char an_cat;			// diode is anode-cathode type
       an_cat = 0;
  #ifdef EBC_STYLE
   #if EBC_STYLE == 321
       // layout with 321= style
       an_cat = (((PartMode&P_CHANNEL) && (ptrans.c > ptrans.e)) || ((!(PartMode&P_CHANNEL)) && (ntrans.c < ntrans.e)));
   #else
       // Layout with SGD= style
       an_cat = (PartMode&P_CHANNEL);	/* N or P MOS */
   #endif
  #else /* EBC_STYLE not defined */
       // layout with 123= style
			an_cat = (((PartMode & P_CHANNEL) && (ptrans.c < ptrans.e))
					|| ((!(PartMode & P_CHANNEL)) && (ntrans.c > ntrans.e)));
  #endif /* end ifdef EBC_STYLE */
       //  show diode symbol in right direction  (short form for less flash memory)
       if (an_cat) {
          lcd_data(LCD_CHAR_DIODE1);	//show Diode symbol >|
       } else {
          lcd_data(LCD_CHAR_DIODE2);	//show Diode symbol |<
       }
 #endif
#endif  /* not WITH_GRAPHICS */
#ifdef WITH_GRAPHICS
       options = 0;
       if (_trans->c != diodes.Anode[vak_diode_nr])
          options |= OPT_VREVERSE;
       lcd_update_icon_opt(bmp_vakdiode,options);	// update Icon with protection diode
#endif

    } /* end if NumOfDiodes == 1 */

#ifdef WITH_GRAPHICS
    lcd_draw_trans_pins(-7, 16);	// update of pin numbers must be done after diode update
    lcd_next_line(TEXT_RIGHT_TO_ICON);	// position text behind the icon, Line 2
 #if LCD_LINES > 6
       lcd_next_line(TEXT_RIGHT_TO_ICON);	// double line
 #endif
    if((PartMode&D_MODE) != D_MODE) {	//enhancement-MOSFET
       lcd_MEM_string(vt_str+1);		// "Vt="
       Display_mV(_trans->gthvoltage,2);	//Gate-threshold voltage
	//Gate capacity
       ReadCapacity(_trans->b,_trans->e);	//measure capacity
       lcd_next_line(TEXT_RIGHT_TO_ICON);	// position text behind the icon, Line 3
       lcd_show_Cg();	// show Cg=xxxpF
 #ifdef SHOW_R_DS
       lcd_show_rds(TEXT_RIGHT_TO_ICON-1); 	// show RDS at column behind the icon -1
 #endif
    } else {   /* depletion mode */
       if ((PartMode&0x0f)  != PART_MODE_JFET) {     /* kein JFET */
          ReadCapacity(_trans->b,_trans->e);	//measure capacity
          lcd_show_Cg();	// show Cg=xxxpF
  #ifdef FET_Idss
       } else { 	// it is a JFET
          // display the I_DSS, if measured
          if (_trans->uBE!=0) {
             static const unsigned char str_Idss[] MEM_TEXT = "Idss=";
             lcd_MEM_string(str_Idss);
             DisplayValue16(_trans->uBE,-6,'A',2);
          }
  #endif
       }
       // set cursor below the icon
  #define LINE_BELOW_ICON ((ICON_HEIGHT/8)/((FONT_HEIGHT+7)/8))
 #if LCD_LINES > 6
       lcd_set_cursor((LINE_BELOW_ICON + 1) * PAGES_PER_LINE,0);
 #else
       lcd_set_cursor(LINE_BELOW_ICON * PAGES_PER_LINE,0);
 #endif
       lcd_data('I');
 #if (LCD_LINE_LENGTH > 17)
       lcd_data('d');
 #endif
       lcd_equal();			// lcd_data('=');
       DisplayValue16(_trans->current,-6,'A',2);
       lcd_MEM_string(Vgs_str);		// "@Vg="
       Display_mV(_trans->gthvoltage,2);	//Gate-threshold voltage

 #ifdef SHOW_ICE
       // Display also the cutoff gate voltage, idea from Pieter-Tjerk
       if (_trans->ice0<4800) { // can't trust cutoff voltage if close to 5V supply voltage, since then the transistor may not have been cut off at all
          lcd_next_line_wait(0);
          lcd_data('I');
  #if (LCD_LINE_LENGTH > 17)
          lcd_data('d');
  #endif
          lcd_equal();			// lcd_data('=');
          DisplayValue16(0,-5,'A',2);
          lcd_MEM_string(Vgs_str);		// "@Vg="
          Display_mV(_trans->ice0,2);	// cutoff Gate voltage
 #endif
       }
 #ifdef SHOW_R_DS
       lcd_show_rds(0);                // show Drain-Source resistance RDS at column 0
 #endif
    }	/* end of enhancement or depletion mode WITH_GRAPHICS */
#else	/* character display */
    if((PartMode&D_MODE) != D_MODE) {	//enhancement-MOSFET
	//Gate capacity
       lcd_line2();		// line 2
       ReadCapacity(_trans->b,_trans->e);	//measure capacity
       lcd_show_Cg();	// show Cg=xxxpF
       lcd_MEM_string(vt_str);		// " Vt="
       Display_mV(_trans->gthvoltage,2);	//Gate-threshold voltage
  #ifdef SHOW_R_DS
       lcd_show_rds(0);                // show Drain-Source resistance RDS at column 0
  #endif
    } else {
      // depletion
 #if FLASHEND > 0x1fff
       if ((PartMode&0x0f)  != PART_MODE_JFET) {     /* kein JFET */
          lcd_next_line(0);		// line 2
          ReadCapacity(_trans->b,_trans->e);	//measure capacity
          lcd_show_Cg();	// show Cg=xxxpF
  #ifdef FET_Idss
       } else {     // it is a JFET
          // display the I_DSS, if measured
          if (_trans->uBE!=0) {
             lcd_next_line(0);
             static const unsigned char str_Idss[] MEM_TEXT = "Idss=";
             lcd_MEM_string(str_Idss);
             DisplayValue16(_trans->uBE,-6,'A',2);
          }
  #endif
       }
       lcd_next_line_wait(0);		// line 2 or 3, if possible & wait and clear last line
 #endif
       lcd_data('I');			// show I=xmA@Vg=y.yV at line 2 or 3
 #if (LCD_LINE_LENGTH > 17)
       lcd_data('d');
 #endif
       lcd_equal();			// lcd_data('=');
       DisplayValue16(_trans->current,-6,'A',2);
       lcd_MEM_string(Vgs_str);		// "@Vg="
       Display_mV(_trans->gthvoltage,2);	//Gate-threshold voltage
 #ifdef SHOW_ICE
       // Display also the cutoff gate voltage, idea from Pieter-Tjerk
       if (_trans->ice0<4800) { // can't trust cutoff voltage if close to 5V supply voltage, since then the transistor may not have been cut off at all
          lcd_next_line_wait(0);
          lcd_data('I');
  #if (LCD_LINE_LENGTH > 17)
          lcd_data('d');
  #endif
          lcd_equal();			// lcd_data('=');
          DisplayValue16(0,-5,'A',2);
          lcd_MEM_string(Vgs_str);		// "@Vg="
          Display_mV(_trans->ice0,2);	// cutoff Gate voltage
       }
 #endif
 #ifdef SHOW_R_DS
       lcd_show_rds(0);                // show Drain-Source resistance RDS at column 0
 #endif
    }   /* end of enhancement or depletion mode */
Пример #30
0
 // not enough Flash space for ShowIcons at ATmega328
// Show all Icons on the screen, up to four at one screen
void ShowIcons(void) {
#define ShowTime 15000  /* 15 seconds wait time, or key press, or rotary encoder movement */
 uint8_t cc;
 lcd_clear();
 lcd_big_icon(BJT_NPN|LCD_UPPER_LEFT);
 lcd_update_icon_opt(bmp_vakdiode, OPT_VREVERSE);
 lcd_big_icon(BJT_NPN|LCD_UPPER_RIGHT);
 lcd_update_icon(bmp_pnp);	// update for PNP
 lcd_set_cursor(5,0);
 lcd_MEM_string(NPN_str);
 lcd_set_cursor(5,(LCD_LINE_LENGTH / 2));
 lcd_MEM_string(PNP_str);
 wait_for_key_ms(ShowTime);

 lcd_clear();
 lcd_big_icon(N_JFET|LCD_LOWER_LEFT);
 lcd_big_icon(N_JFET|LCD_LOWER_RIGHT);
 lcd_update_icon(bmp_p_jfet);	// update to P_JFET
 lcd_set_cursor(2,1);
 lcd_data('N');		// N-Type
 lcd_data('-');
 lcd_MEM_string(jfet_str);
 lcd_set_cursor(2,1+(LCD_LINE_LENGTH / 2));
 lcd_data('P');		// P-Type
 lcd_data('-');
 lcd_MEM_string(jfet_str);
 wait_for_key_ms(ShowTime);

 lcd_clear();
 lcd_big_icon(N_E_IGBT|LCD_UPPER_LEFT);
 lcd_big_icon(N_E_IGBT|LCD_UPPER_RIGHT);
 lcd_update_icon(bmp_p_e_igbt);	// update to P-E-IGBT
 lcd_set_cursor(5,0);
 lcd_data('N');		// N-Type
 lcd_data('-');
 lcd_data('E');		// Enhancement Type
 lcd_MEM_string(igbt_str);
 lcd_set_cursor(6,(LCD_LINE_LENGTH / 2));
 lcd_data('P');		// P-Type
 lcd_data('-');
 lcd_data('E');		// Enhancement Type
 lcd_MEM_string(igbt_str);
 wait_for_key_ms(ShowTime);

 lcd_clear();
 lcd_big_icon(N_E_IGBT|LCD_LOWER_LEFT);
 lcd_update_icon(bmp_n_d_igbt);	// update to N-D-IGBT
 lcd_big_icon(N_E_IGBT|LCD_LOWER_RIGHT);
 lcd_update_icon(bmp_p_d_igbt);	// update to P-D-IGBT
 lcd_set_cursor(1,0);
 lcd_data('N');		// N-Type
 lcd_data('-');
 lcd_data('D');		// Depletion Type
 lcd_MEM_string(igbt_str);
 lcd_set_cursor(2,(LCD_LINE_LENGTH / 2));
 lcd_data('P');		// P-Type
 lcd_data('-');
 lcd_data('D');		// Depletion Type
 lcd_MEM_string(igbt_str);
 wait_for_key_ms(ShowTime);

 lcd_clear();
 lcd_big_icon(N_E_MOS|LCD_UPPER_LEFT);
 lcd_big_icon(N_E_MOS|LCD_UPPER_RIGHT);
 lcd_update_icon(bmp_p_e_mos);  // update to P-E-MOS
 lcd_set_cursor(5,0);
 lcd_data('N');		// N-Type
 lcd_data('-');
 lcd_data('E');		// Enhancement Type
 lcd_MEM_string(mosfet_str);
 lcd_set_cursor(6,(LCD_LINE_LENGTH / 2));
 lcd_data('P');		// P-Type
 lcd_data('-');
 lcd_data('E');		// Enhancement Type
 lcd_MEM_string(mosfet_str);
 wait_for_key_ms(ShowTime);

 lcd_clear();
 lcd_big_icon(N_E_MOS|LCD_LOWER_LEFT);
 lcd_update_icon(bmp_n_d_mos);  // update to N-D-MOS
 lcd_big_icon(N_E_MOS|LCD_LOWER_RIGHT);
 lcd_update_icon(bmp_p_d_mos);  // update to P-D-MOS
 lcd_set_cursor(1,1);
 lcd_data('N');		// N-Type
 lcd_data('-');
 lcd_data('D');		// Depletion Type
 lcd_MEM_string(mosfet_str);
 lcd_set_cursor(2,1+(LCD_LINE_LENGTH / 2));
 lcd_data('P');		// P-Type
 lcd_data('-');
 lcd_data('D');		// Depletion Type
 lcd_MEM_string(mosfet_str);
 wait_for_key_ms(ShowTime);
 #if (ICON_ELEMENTS == 14)
 lcd_clear();
 lcd_big_icon(TRIAC|LCD_UPPER_LEFT);
 lcd_big_icon(THYRISTOR|LCD_UPPER_RIGHT);
 wait_for_key_ms(ShowTime);

 lcd_clear();
 lcd_big_icon(INDUCTOR|LCD_LOWER_LEFT);
 lcd_big_icon(CAPACITOR|LCD_LOWER_RIGHT);
 lcd_big_icon(RESISTOR|LCD_UPPER_LEFT);
 lcd_big_icon(RESISTORS|LCD_UPPER_RIGHT);
 wait_for_key_ms(ShowTime);

 lcd_clear();
 lcd_big_icon(DIODE_C_A|LCD_UPPER_LEFT);
 lcd_big_icon(DIODES_C_A_C_A|LCD_UPPER_RIGHT);
 lcd_big_icon(DIODES_A_C_C_A|LCD_LOWER_LEFT);
 lcd_big_icon(DIODES_C_A_A_C|LCD_LOWER_RIGHT);
 wait_for_key_ms(ShowTime);
 #endif

 
 lcd_clear();
 lcd_line1();
 lcd_MEM_string(Resistor_str);    // -[=]-
 lcd_line2();
 lcd_MEM_string(Inductor_str);         // -ww-
 lcd_line3();
 lcd_MEM_string(CapZeich);          // capacitor sign
 lcd_line4();
 lcd_MEM_string(AnKat_str);       //"->|-"
 lcd_space();
 lcd_MEM_string(KatAn_str);       //"-|<-"


// show character set
 for (cc=0;cc<(0x7f-0x20);cc++) {
   if ((cc%16) == 0) {
     // begin new line
     if((cc%64) == 0) {
       wait_for_key_ms(ShowTime);
       lcd_clear();
     }
     lcd_set_cursor(((cc/16)%4)*2,0);
   }
  lcd_data(cc+0x20);
 } /* end for cc */
 wait_for_key_ms(ShowTime);

 lcd_clear();
  #ifdef LCD_CYRILLIC
 for (cc=0;cc<((Cyr_ja+1-Cyr_B)+(Cyr_schtsch+1-Cyr_D));cc++) {
   if ((cc%16) == 0) {
     // begin new line
     lcd_set_cursor(((cc/16)%4)*2,0);
   }
   if (cc <= (Cyr_ja-Cyr_B))
   {
     lcd_data(cc + Cyr_B);
   } else {
     lcd_data(cc + Cyr_D - (Cyr_ja + 1 - Cyr_B));
   }
 } /* end for cc */
 wait_for_key_ms(ShowTime);

 lcd_clear();
  #endif

}