void lcd_test()
{
    lcdCursor      (lcdHandle, FALSE) ;
    lcdCursorBlink (lcdHandle, FALSE) ;
    lcdClear       (lcdHandle) ;

    lcdPutBigNumber(0, 0, 0);
    lcdPutBigNumber(3, 0, 1);
    lcdPutBigNumber(6, 0, 2);
    lcdPutBigNumber(9, 0, 3);
    lcdPutBigNumber(12, 0, 4);

    waitForEnter () ;

    lcdClear       (lcdHandle) ;

    lcdPutBigNumber(0, 0, 5);
    lcdPutBigNumber(3, 0, 6);
    lcdPutBigNumber(6, 0, 7);
    lcdPutBigNumber(9, 0, 8);
    lcdPutBigNumber(12, 0, 9);

    waitForEnter () ;

    lcdClear       (lcdHandle) ;

    lcdPutBigNumber(0, 0, 0);
    lcdPutBigNumber(4, 0, 1);
    lcdPutBigNumber(8, 0, 2);
    lcdPutBigNumber(12, 0, 3);
    lcdPutBigNumber(16, 0, 4);

    waitForEnter () ;

    lcdClear       (lcdHandle) ;

    lcdPutBigNumber(0, 0, 5);
    lcdPutBigNumber(4, 0, 6);
    lcdPutBigNumber(8, 0, 7);
    lcdPutBigNumber(12, 0, 8);
    lcdPutBigNumber(16, 0, 9);

    waitForEnter () ;

    lcdClear       (lcdHandle) ;

    lcdPutBigSpecialChar(0, 0, ':');

    waitForEnter () ;
}
Exemplo n.º 2
0
int main (int argc, char *argv[])
{
  int i ;
  int lcd ;
  int bits, rows, cols ;

  struct tm *t ;
  time_t tim ;

  char buf [32] ;

  if (argc != 4)
    return usage (argv [0]) ;

  printf ("Raspberry Pi LCD test\n") ;
  printf ("=====================\n") ;

  bits = atoi (argv [1]) ;
  cols = atoi (argv [2]) ;
  rows = atoi (argv [3]) ;

  if (!((rows == 1) || (rows == 2) || (rows == 4)))
  {
    fprintf (stderr, "%s: rows must be 1, 2 or 4\n", argv [0]) ;
    return EXIT_FAILURE ;
  }

  if (!((cols == 16) || (cols == 20)))
  {
    fprintf (stderr, "%s: cols must be 16 or 20\n", argv [0]) ;
    return EXIT_FAILURE ;
  }

  wiringPiSetup () ;

  if (bits == 4)
    lcdHandle = lcdInit (rows, cols, 4, 11,10, 4,5,6,7,0,0,0,0) ;
  else
    lcdHandle = lcdInit (rows, cols, 8, 11, 10, 0,1,2,3,4,5,6,7) ;

  if (lcdHandle < 0)
  {
    fprintf (stderr, "%s: lcdInit failed\n", argv [0]) ;
    return -1 ;
  }

  lcdPosition (lcdHandle, 0, 0) ; lcdPuts (lcdHandle, "Gordon Henderson") ;
  lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, "  wiringpi.com  ") ;

  waitForEnter () ;

  if (rows > 1)
  {
    lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, "  wiringpi.com  ") ;

    if (rows == 4)
    {
      lcdPosition (lcdHandle, 0, 2) ;
      for (i = 0 ; i < ((cols - 1) / 2) ; ++i)
        lcdPuts (lcdHandle, "=-") ;
      lcdPuts (lcdHandle, "=3") ;

      lcdPosition (lcdHandle, 0, 3) ;
      for (i = 0 ; i < ((cols - 1) / 2) ; ++i)
        lcdPuts (lcdHandle, "-=") ;
      lcdPuts (lcdHandle, "-4") ;
    }
  }

  waitForEnter () ;

  lcdCharDef  (lcdHandle, 2, newChar) ;

  lcdClear    (lcdHandle) ;
  lcdPosition (lcdHandle, 0, 0) ;
  lcdPuts     (lcdHandle, "User Char: ") ;
  lcdPutchar  (lcdHandle, 2) ;

  lcdCursor      (lcdHandle, TRUE) ;
  lcdCursorBlink (lcdHandle, TRUE) ;

  waitForEnter () ;

  lcdCursor      (lcdHandle, FALSE) ;
  lcdCursorBlink (lcdHandle, FALSE) ;
  lcdClear       (lcdHandle) ;

  for (;;)
  {
    scrollMessage (0, cols) ;
    
    if (rows == 1)
      continue ;

    tim = time (NULL) ;
    t = localtime (&tim) ;

    sprintf (buf, "%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec) ;

    lcdPosition (lcdHandle, (cols - 8) / 2, 1) ;
    lcdPuts     (lcdHandle, buf) ;

    if (rows == 2)
      continue ;

    sprintf (buf, "%02d/%02d/%04d", t->tm_mday, t->tm_mon + 1, t->tm_year+1900) ;

    lcdPosition (lcdHandle, (cols - 10) / 2, 2) ;
    lcdPuts     (lcdHandle, buf) ;

    pingPong (lcd, cols) ;
  }

  return 0 ;
}
Exemplo n.º 3
0
int main(int argc, char *argv[]) {
  struct tm *t;
  time_t tim;
  char buf[32];

  const char* programName = argv[0];
  const char* displayMessage = argv[1];

  if(argc < 2) {
    fprintf(stderr, "Usage: %s display_message\n", programName);
    return -1;
  }

  /* initialize WiringPi */
  wiringPiSetupSys();

  /* initalize LCD */
  lcdHandle = lcdInit(ROWS, COLUMNS, 4, AF_RS, AF_E, AF_D1, AF_D2, AF_D3, AF_D4, 0, 0, 0, 0);
  if(lcdHandle < 0) {
    fprintf(stderr, "lcdInit failed\n");
    return -1;
  }

  /* initalize PCF8574 module, NOTE that the device address must be right & can be acquired by "i2cdetect -y 1" command */
  pcf8574Setup(AF_BASE, 0x3f);

  /* turn on LCD backlight */
  pinMode(AF_BL, OUTPUT);
  digitalWrite(AF_BL, 1);

  /* set LCD into write mode */
  pinMode(AF_RW, OUTPUT);
  digitalWrite(AF_RW, 0);

  /* then we start to display various messages on the LCD screen */
  lcdClear(lcdHandle);             // clear the screen
  lcdPosition(lcdHandle, 3, 0);    // set the cursor on the the 4th column & 1st row
  lcdPuts(lcdHandle, "RPi");       // print the text on the LCD at current cursor postion
  lcdPosition(lcdHandle, 4, 1);    // set the cursor on the the 5th column & 2nd row
  lcdPuts(lcdHandle, "codelast");

  waitForEnter();

  lcdClear(lcdHandle);             // clear the screen
  lcdPosition(lcdHandle, 0, 0);    // set the cursor on the 1st column & 1st row
  lcdCursor(lcdHandle, true);      // turn the cursor on
  lcdCursorBlink(lcdHandle, true); // turn the cursor blink on

  waitForEnter();

  lcdCursor(lcdHandle, false);       // turn the cursor off
  lcdCursorBlink(lcdHandle, false);  // turn the cursor blink off
  lcdClear(lcdHandle);               // clear the screen
  lcdPuts(lcdHandle, "Will scroll...");

  waitForEnter();

  while(true) {
    scrollMessage(0, COLUMNS, displayMessage);  // scroll the specified message on the 1st row

    /* display current time on LCD */
    tim = time(NULL);
    t = localtime(&tim);
    sprintf(buf, "%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec);

    lcdPosition(lcdHandle, (COLUMNS - 8) / 2, 1);
    lcdPuts(lcdHandle, buf);
  }
  
  return 0;
}
Exemplo n.º 4
0
Arquivo: demo1.c Projeto: Iryaz/leso6
int main() {
	//! Инициализация портов для светодиодов.
	DDRF |= (1 << DDF0 | 1 << DDF1 | 1 << DDF2 | 1 << DDF3);
	//! Инициализация порта для пьезоизлучателя.
	DDRB |= (1 << DDB0);
	//! Инициализация портов для строк клавиатуры. Строки на ввод.
	DDRD &= ~(1 << DDD4 | 1 << DDD5 | 1 << DDD6 | 1 << DDD7);
	//! Инициализация портов для строк клавиатуры. Поддяжка к питанию.
	PORTD |= (1 << PD4 | 1 << PD5 | 1 << PD6 | 1 << PD7);
	//! Инициализация портов для столбцоы клавиатуры. столбцы на вывод.
	DDRG |= (1 << DDG0 | 1 << DDG1 | 1 << DDG2);

	//! Инициализация таймера для излучателя звука.
	TCCR3A = 0;
	TCCR3A = 0;
	TCCR3B = 0;
	TCCR3B_struct.cs3 = 0x01;		// Предделитель: F_CPU/1
	TIMSK3_struct.toie3 = 1;		// Разрешаем прерывание по переполнению
	TCNT3 = -8000;					// 8000 тактов центрального проессора ~ 500 мкс.

	//! Инициализация таймера для смены режимов.
	TCCR4A = 0;
	TCCR4A = 0;
	TCCR4B = 0;

	uint8_t key1, key2 = 0;			//!< Переменные для хранения кода нажатых клавишь.
	uint8_t i;
	char tx_buff_str[16];


	//! Структура для чтения времени.
	//! Перед первым использованием должна быть инициализирована.
	ds18b20_memory_t ds18b20_memory = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
	int16_t temper = 0;

	//! Структура для чтения времени.
	//! Перед первым использованием должна быть инициализирована.
	rtc_data_r_t time = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
	//rtc_data_w_t time_w = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; //!< Структура для установки времени.
	uint8_t sec;

	I2C_Master_Initialise(); 			//!< Инициализация I2C интерфейса.
	ds18b20_convert();					//!< Запуск преобразование температуры.
	uart_init();						//!< Инициализируем UART.
	uart_set_input_cb(uart_rx_cb);// Устанавливаем функцию обратного вызова на прием байта по UART.

	printf("\n\rLESO laboratory (c) 2014\r\nDemo test program\r\n");
	printf("LESO6 ATMEGA128RFA1\r\n");
	fprintf(stderr, "stderr: NO ERRORS\r\n");

	//! Массив с описанием символа градуса.
	uint8_t ch[8] = {
	0x06, /*x x x 0 0 1 1 0*/
	0x09, /*x x x 0 1 0 0 1*/
	0x09, /*x x x 0 1 0 0 1*/
	0x06, /*x x x 0 0 1 1 0*/
	0x00, /*x x x 0 0 0 0 0*/
	0x00, /*x x x 0 0 0 0 0*/
	0x00, /*x x x 0 0 0 0 0*/
	0x00  /*x x x 0 0 0 0 0*/
	};

	//! Управлящая структура для ЖКИ.
	lcd_t lcd = { 0, 0, 0, 0, 0 };
	lcdInit(&lcd);								//!< Инициализируем ЖКИ;
	lcdCursor(&lcd, 0);							//!< Выключаем курсор.
	lcdCursorBlink(&lcd, 0);					//!< Выключаем мерцание курсора.
	sprintf(tx_buff_str, " LESO6 \n 2014%c  ", 0xb4);
	lcdPuts(&lcd, tx_buff_str);
	lcdCharDef(&lcd, 1, ch);					//!< Определяем новый символ.

	for (i = 0; i < 75; i++)
		_delay_ms(10);
	getTimeDS1338(&time);						//!< Читаем время.
	ds18b20_read(&ds18b20_memory);				//!< Читаем температуру.
	sec = time.Second;

	TIMSK3_struct.toie3 = 0;// Запрещаем прерывание при переполнении таймера 3.
	off(BIP);									// Выключаем звук.

	lcdClear(&lcd);
	lcdCursor(&lcd, 1);
	lcdPuts(&lcd, "Text:\n");
	while (1) {
		while (key_mode)		// В режиме набора текст:
		{
			key1 = getKeyChar();
			for(i=0; i<5; i++) _delay_ms(10);
			key2 = getKeyChar();

			if (key1 == '\n') continue;
			else if (key1 != key2) continue;

			TCNT4 = 0;				// Дополнительное время работы в этом режиме
			if((lcd.cx) == lcd.cols)// закончились символы в строке
			{
				lcdPuts(&lcd,"\r        \r");// стираем строку, возвращаем курсор в начало
				printf("\r\033[0K");// стираем строку в терминале
			}
			lcdPutchar(&lcd, key1);
			LEDS &= ~0x0F;
			LEDS |= 0x0F&key1;
			putchar(key1);
			TIMSK3_struct.toie3 = 1;			// пик
			for(i=0; i<20; i++) _delay_ms(10);
			TIMSK3_struct.toie3 = 0;
		}

		printf("\r\033[0K%02u:%02u:%02u",time.Hour, time.Minute ,time.Second);
		sprintf(tx_buff_str, "%02u:%02u:%02u\n",time.Hour, time.Minute ,time.Second);
		lcdHome(&lcd);
		lcdPuts(&lcd, tx_buff_str);

		if(ds18b20_crc8((uint8_t *)&ds18b20_memory, sizeof(ds18b20_memory)))
		fprintf(stderr,"ERROR read DS18B20\r\n");
		else
		{
			temper = (ds18b20_memory.temper_MSB << 8) | ds18b20_memory.temper_LSB;
			printf(" T= %d.%u",temper>>4, ((temper&0xf)*1000)/(16));
			sprintf(tx_buff_str,"%02d.%u%cC  ",temper>>4, ((temper&0xf)*1000)/(16), 0x01);
			lcdPuts(&lcd, tx_buff_str);
		}

		ds18b20_convert();		// Запуск преобразование температуры.
		while(sec == time.Second)
		{
			if (getTimeDS1338(&time))
			{
				fprintf(stderr,"ERROR: read date fail..!\n\r");
				continue;
			}

			key1 = getKeyChar();
			if (key1 != '\n')
			{
				key_mode = 1;
				lcdClear(&lcd);
				lcdCursor(&lcd, 1);
				lcdPuts(&lcd,"Text:\n");

				TCCR4B_struct.cs4 = 0x04;		// Предделитель: F_CPU/256
				TIMSK4_struct.toie4 = 1;// Разрешаем прерывание по переполнению
				TCNT4 = 0;
				printf("\r\033[0K");// стираем строку в терминале
				break;
			}
			for(i=0; i<20; i++) _delay_ms(10);
		}
		sec = time.Second;
		ds18b20_read(&ds18b20_memory);
		if(ds18b20_crc8((uint8_t *)&ds18b20_memory, sizeof(ds18b20_memory)))
		fprintf(stderr,"ERROR read DS18B20\r\n");
	}

	return 0;
}