Пример #1
0
//**************************************************************************
void eeprom_apply_settings(void)
{
  if(eeprom_read(contrast_address)!=Settings.contrast)       
	{
		display_off();
		delay_ms(200);
		display_on();
	}
	// -------------------------------------------------------------------
  if(eeprom_read(Display_reverse_address)!=Settings.Display_reverse)
	{
		display_off();
		delay_ms(200);
		display_on();
	}
	// -------------------------------------------------------------------
  if(eeprom_read(v4_target_pump_address)!=Settings.v4_target_pump)
	{
		reset_TIM_prescallers_and_Compare();	
	}
	// -------------------------------------------------------------------
	if(eeprom_read(Geiger_voltage_address) !=Settings.Geiger_voltage) 
 	{
		dac_reload(); //перезагрузить в ЦАП новое напряжение отсечки накачки
 	}
	// -------------------------------------------------------------------
	if(eeprom_read(LSI_freq_address)       !=Settings.LSI_freq)
  {
		if(Settings.LSI_freq != 0x00) // если запустился кварц, попытки сохранения игнорировать
		{
			eeprom_write(LSI_freq_address,Settings.LSI_freq);   NVIC_SystemReset();
		}
	}
}
Пример #2
0
int 
MAX72XX::putchar(char c)
{
  // Check for illegal characters
  if (c < 0) return (-1);

  // Check for special characters
  if (c < ' ') {

    // Carriage-return: move to start of line
    if (c == '\r') {
      set_cursor(0, m_y);
      return (c);
    }
    // Form-feed: clear the display or line-feed: clear line
    if ((c == '\f') || (c == '\n')) {
      display_clear();
      return (c);
    }

    // Horizontal tab
    if (c == '\t') {
      uint8_t x = m_x + m_tab - (m_x % m_tab);
      uint8_t y = m_y + (x >= WIDTH);
      set_cursor(x, y);
      return (c);
    }

    // Back-space: move cursor back one step (if possible)
    if (c == '\b') {
      set_cursor(m_x - 1, m_y);
      return (c);
    }

    // Alert: blink the backlight
    if (c == '\a') {
      display_off();
      delay(32);
      display_on();
      return (c);
    }
  }

  // Write character
  uint8_t segments;
  if (c == '.') {
    c = m_latest;
    segments = pgm_read_byte(m_font + c - ' ') | 0x80;
  }
  else {
    if (m_x == WIDTH) putchar('\n');
    m_x += 1;
    m_latest = c;
    segments = pgm_read_byte(m_font + c - ' ');
  }
  set((Register) m_x, segments);

  return (c & 0xff);
}
Пример #3
0
void game_init(){
	int8u no;
	int8u count;
	
	display_off();
	pattern_fill(0x3800, 0, (BG_HIGH + BG_PAL1 + BG_TOP), 32 * 28 * 2);

	actors_clear();

	scene_wait = 0;
	player_create(0);
	alive_players = 1;
	smoke_wait = 0;
	scene_type = SCENE_GAME_PLAYING;

	vram_store(0x3000, fopen("bmp/font.ptn"), 0x0800);

	/*  load pattern */
	switch(stage){
	case 0:
		vram_store(0x2000, fopen("bmp/castle.ptn"), 0x1000);
		vram_store(0x0000, fopen("bmp/sp_castle.ptn"), 0x2000);
		break;
	case 1:
		vram_store(0x2000, fopen("bmp/summer.ptn"), 0x1000);
		vram_store(0x0000, fopen("bmp/sp_summer.ptn"), 0x2000);
		break;
	case 2:
		vram_store(0x2000, fopen("bmp/jungle.ptn"), 0x1000);
		vram_store(0x0000, fopen("bmp/sp_castle.ptn"), 0x2000);
		break;
	default:
		vram_store(0x2000, fopen("bmp/winter.ptn"), 0x1000);
		vram_store(0x0000, fopen("bmp/sp_castle.ptn"), 0x2000);
		break;
	}
	
	/* load palette */
	load_palette(stage, 0);

	/* set enemy */
	enemies_rotation_count = level << 3;
	for(count = stage; count != 0; count--){
		/* 8 charactors * 3 levels * stage 2 */
		enemies_rotation_count += 8 * 3;
	}
	enemies_rotation_limit = enemies_rotation_count + 8;

	enemies_count = ACTORS_INITINAL_COUNT;
	enemies_alive = 0;
	enemies_left = 6 + stage;
	for(count = 0; count < enemies_count; count++){
		no = actors_get_null();
		actor_create_random(no);
	}

	display_on();
}
Пример #4
0
int main(void)
{
    analogvalue_t delay;

    setup();
    setup_timer0();

    // setup_int0();

    // display_off(&display);
    setup_timer2();

    analog_init(&delay);
    potentiometer_read(&delay);

    display_set(&display, delay.v);
    display_on(&display, 1);

    /* if ((PIND & _BV(PIN_SW1)) == 0) */
    /*     pin = PIN_LED_RED; */

    for (;;) {
        if ((PIND & _BV(PIN_BUTTON2)) == 0) {
            PORTB &= _BV(PIN_LED);
        } else {
            PORTB |= _BV(PIN_LED);
        }



/*
        if ((PIND & _BV(PIN_SW1)) == 0) {
            long tmax = 1000L * delay.v;
            while (micros() - t0 < tmax)
                ;
            PORTD |= _BV(pin);
        } else {
            PORTD &= ~_BV(pin);
            enable_int0();
        }

        if ((PIND & _BV(PIN_SW2)) == 0) {
            settle_on_low(&PIND, PIN_SW2);
            loop_until_bit_is_set(PIND, PIN_SW2);
            display_toggle(&display);
        }
*/

        potentiometer_read(&delay);
        if (delay.v != display.value) {
            display_set(&display, delay.v);
        }
    }

    return 0;
}
Пример #5
0
void initialize()
{
	ON = 1;
	BLON = 0;
	clear_display();
	set_entry();
	function_set();
	display_on();
	
}
Пример #6
0
bool 
MAX72XX::begin()
{
  set(DECODE_MODE, NO_DECODE);
  set(SCAN_LIMIT, 7);
  display_contrast(7);
  display_clear();
  display_on();
  return (true);
}
Пример #7
0
/* ----------------------------------------------------------------------------------- */
void gameover_main(char *message){
	int8u c;

	display_off();

	palette_store( 0, fopen("bmp/title.pal"), 16);
	palette_store(16, fopen("bmp/sp_castle.pal"), 16);

	vram_store(0x0000, fopen("bmp/sp_castle.ptn"), 0x2000);
	vram_store(0x2000, fopen("bmp/title.ptn"), 0x1000);
	vram_store(0x3000, fopen("bmp/font.ptn"), 0x800);
	pattern_fill(0x3800, 0, BG_HIGH, 32 * 24 * 2);

	print_init();
	store_pattern_name_buffer(10);
	print(message, 10);
	store_pattern_name_buffer(9);

	print("1P SCORE XXXX0 ", 8);
	pattern_name_buffer[17 << 1] = VRAM_NUMBER + score_ints[3];
	pattern_name_buffer[18 << 1] = VRAM_NUMBER + score_ints[2];
	pattern_name_buffer[19 << 1] = VRAM_NUMBER + score_ints[1];
	pattern_name_buffer[20 << 1] = VRAM_NUMBER + score_ints[0];
	store_pattern_name_buffer(11);

	if(players_count == 2){
		print("2P SCORE XXXX0 ", 8);
		pattern_name_buffer[17 << 1] = VRAM_NUMBER + score_ints[7];
		pattern_name_buffer[18 << 1] = VRAM_NUMBER + score_ints[6];
		pattern_name_buffer[19 << 1] = VRAM_NUMBER + score_ints[5];
		pattern_name_buffer[20 << 1] = VRAM_NUMBER + score_ints[4];
		store_pattern_name_buffer(13);
	}

	actors_clear();
	scroll_y = 0;
	print_init();
	display_on();
	psg_set_bgm(fopen("sound/over.sn7"), FALSE);
	
	for(c = 6; c != 0; c--){
		for(frame_count = 0; frame_count < 60; frame_count++){
			sprites_clear();
			vsync_wait();
			sprites_store();
			scroll_store();
			psg_play();
		}
	}
	psg_stop();
}
/**
 * @brief   Low level GDISP driver initialization.
 *
 * @notapi
 */
bool_t gdisp_lld_init(void) {
  // Initialize your display
  init_board();

  // Hardware reset.
  setpin_reset(TRUE);
  delay_ms(10);
  setpin_reset(FALSE);
  delay_ms(1);

  write_cmd(ST7565_LCD_BIAS_7);
  write_cmd(ST7565_ADC_NORMAL);
  write_cmd(ST7565_COM_SCAN_INC);
  set_display_start_line(0);

  set_contrast(32);
  write_cmd(ST7565_RESISTOR_RATIO | 0x3);

  // turn on voltage converter (VC=1, VR=0, VF=0)
  write_cmd(ST7565_POWER_CONTROL | 0x04);
  delay_ms(50);
  // turn on voltage regulator (VC=1, VR=1, VF=0)
  write_cmd(ST7565_POWER_CONTROL | 0x06);
  delay_ms(50);
  // turn on voltage follower (VC=1, VR=1, VF=1)
  write_cmd(ST7565_POWER_CONTROL | 0x07);
  delay_ms(50);

  display_on();
  write_cmd(ST7565_ALLON_NORMAL);
  invert_display(0);// Disable Inversion of display.

  write_cmd(ST7565_RMW);
  gdisp_lld_display();

  // Initialize the GDISP structure
  GDISP.Width = GDISP_SCREEN_WIDTH;
  GDISP.Height = GDISP_SCREEN_HEIGHT;
  GDISP.Orientation = GDISP_ROTATE_0;
  GDISP.Powermode = powerOn;
  GDISP.Contrast = 50;
#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
  GDISP.clipx0 = 0;
  GDISP.clipy0 = 0;
  GDISP.clipx1 = GDISP.Width;
  GDISP.clipy1 = GDISP.Height;
#endif
  return TRUE;
}
Пример #9
0
/* ----------------------------------------------------------------------------------- */
void basic_init_for_intro(){
	display_off();
	actors_clear();

	palette_store( 0, fopen("bmp/title.pal"), 16);
	palette_store(16, fopen("bmp/sp_castle.pal"), 16);
	vram_store(0x0000, fopen("bmp/sp_castle.ptn"), 0x2000);
	vram_store(0x2000, fopen("bmp/title.ptn"), 0x1800);
	vram_store(0x3800, fopen("map/intro.map"), (32 * 24 * 2));

	map_make_pointer(STAGE_COUNT, 0);
	frame_count = 0;
	print_init();
	display_on();
}
Пример #10
0
void sleep_mode(FunctionalState sleep)
{ 
  if(Settings.Sleep_time>0 && !Power.USB_active)
  {
		Power.Pump_deny=ENABLE;
		if(Power.Pump_active)Pump_now(DISABLE);
		
		set_msi();
    if(sleep)
    {
			RTC_ITConfig(RTC_IT_WUT, DISABLE);

			Power.led_sleep_time=0;
			GPIO_SetBits(GPIOC,GPIO_Pin_13);// Выключаем подсветку  				

      display_off(); // выключить дисплей
 			GPIO_ResetBits(GPIOA,GPIO_Pin_7);// Фиксируем режим 1.8 вольта, с низким потреблением ножки

			delay_ms(1000); // подождать установки напряжения
			DataUpdate.Need_batt_voltage_update=ENABLE; // разрешить работу АЦП
			adc_check_event(); // запустить преобразование
			delay_ms(100); // подождать установки напряжения

			PWR_FastWakeUpCmd(DISABLE);
			PWR_UltraLowPowerCmd(ENABLE); 
			PWR_PVDCmd(DISABLE);
			RTC_ITConfig(RTC_IT_WUT, ENABLE);
    }
    else
    {
			RTC_ITConfig(RTC_IT_WUT, DISABLE);
			GPIO_SetBits(GPIOA,GPIO_Pin_7);// Переключаем в режим 3 вольта
			delay_ms(400); // подождать установки напряжения
      display_on(); // включить дисплей
			DataUpdate.Need_batt_voltage_update=ENABLE; // разрешить работу АЦП
			DataUpdate.Need_display_update=ENABLE;
			adc_check_event(); // запустить преобразование
			RTC_ITConfig(RTC_IT_WUT, ENABLE);
			sound_deactivate();
    }
		Power.Pump_deny=DISABLE;
  } 
}
Пример #11
0
/**
 * @brief   Driver Control
 * @details Unsupported control codes are ignored.
 * @note    The value parameter should always be typecast to (void *).
 * @note    There are some predefined and some specific to the low level driver.
 * @note    GDISP_CONTROL_POWER         - Takes a gdisp_powermode_t
 *          GDISP_CONTROL_ORIENTATION   - Takes a gdisp_orientation_t
 *          GDISP_CONTROL_BACKLIGHT 	- Takes an int from 0 to 100. For a driver
 *                                        that only supports off/on anything other
 *                                        than zero is on.
 *          GDISP_CONTROL_CONTRAST      - Takes an int from 0 to 100.
 *          GDISP_CONTROL_LLD           - Low level driver control constants start at
 *                                        this value.
 *
 * @param[in] what		What to do.
 * @param[in] value 	The value to use (always cast to a void *).
 *
 * @notapi
 */
void gdisp_lld_control(unsigned what, void *value) {
  switch(what) {
    case GDISP_CONTROL_POWER:
      if (GDISP.Powermode == (gdisp_powermode_t)value)
        return;

      switch((gdisp_powermode_t)value) {
        case powerOff:
          display_off();
          break;
        case powerSleep:
          display_off();
          break;
        case powerDeepSleep:
          display_off();
          break;
        case powerOn:
          display_on();
          break;
        default:
          return;
      }
      GDISP.Powermode = (gdisp_powermode_t)value;
      return;

    case GDISP_CONTROL_BACKLIGHT:
      set_backlight((uint8_t)(size_t)value);
      return;

    case GDISP_CONTROL_CONTRAST:
      if ((unsigned)value > 100) value = (void*)100;
      if (GDISP.Contrast == (uint8_t)((float)((size_t)value) * 63.0/100.0))
        return;
      set_contrast((uint8_t)((float)((size_t)value) * 63.0/100.0) );
      GDISP.Contrast = (unsigned)value;
      return;

    case GDISP_CONTROL_LLD_FLUSH:
      gdisp_lld_display();
      return;
  }
}
Пример #12
0
int main(void)

{
	NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x3000);  

	set_msi();
	DBGMCU_Config(DBGMCU_SLEEP | DBGMCU_STANDBY | DBGMCU_STOP, DISABLE);
		
  set_bor();
	Power.sleep_now=DISABLE;
	
	DataUpdate.Need_erase_flash=ENABLE;
	
  Settings.Geiger_voltage=360; // Напряжение на датчике 360 вольт
  Settings.Pump_Energy=350;    // энергия накачки 350 мТл
	DataUpdate.current_flash_page=0;
	
	io_init(); // Инициализация потров МК

	eeprom_write_default_settings(); // Проверка, заполнен ли EEPROM
  eeprom_read_settings(); // Чтение настроек из EEPROM
  screen=1;
	Power.USB_active=DISABLE;
	Power.sleep_time=Settings.Sleep_time;
  Power.Display_active=ENABLE;
	
	ADCData.DAC_voltage_raw=0x610;
		
  dac_init();
	comp_init();
	comp_on();
	timer9_Config(); // Конфигурируем таймер накачки	
	timer10_Config();
	tim2_Config();
	sound_activate();
	delay_ms(100);
	sound_deactivate();
//--------------------------------------------------------------------
	RTC_Config();	   // Конфигурируем часы
//--------------------------------------------------------------------
// инициализация дисплея
//--------------------------------------------------------------------
	delay_ms(50); // подождать установки напряжения
  display_on(); 
  LcdInit(); 
  LcdClear(); 
//--------------------------------------------------------------------
  adc_init();
  delay_ms(100);
  adc_calibration();
	delay_ms(10);
//--------------------------------------------------------------------
  EXTI8_Config();
#ifdef version_401
  EXTI9_Config();
#endif
	EXTI3_Config();
  EXTI4_Config();
  EXTI6_Config();
		
	DataUpdate.Need_batt_voltage_update=ENABLE;
	
	if(!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_6))hidden_menu=ENABLE; // Открытие сервисных пунктов меню
	
	delay_ms(500); // подождать установки напряжения
		
  while(1) 
/////////////////////////////////
  {
		if(DataUpdate.Need_fon_update==ENABLE)	geiger_calc_fon();
    if(key>0)																keys_proccessing();
		if(DataUpdate.Need_batt_voltage_update)	adc_check_event();

		////////////////////////////////////////////////////

		
		if((Power.sleep_time>0)&(!Power.Display_active))sleep_mode(DISABLE); // Если дисплей еще выключен, а счетчик сна уже отсчитывает, поднимаем напряжение и включаем дисплей
    
		if(Power.Display_active)
    {
			if(Power.sleep_time==0 && !Alarm.Alarm_active) sleep_mode(ENABLE);  // Счетчик сна досчитал до нуля, а дисплей еще активен, то выключаем его и понижаем напряжение
			if(Power.led_sleep_time>0)
			{
				GPIO_ResetBits(GPIOC,GPIO_Pin_13);// Включаем подсветку 
			} else {
				GPIO_SetBits(GPIOC,GPIO_Pin_13);// Выключаем подсветку  				
			}			
			if(DataUpdate.Need_display_update==ENABLE)
			{
				DataUpdate.Need_display_update=DISABLE;
				LcdClear_massive();
				if (screen==1)main_screen();
				if (screen==2)menu_screen();
				if (screen==3)stat_screen();
			}
///////////////////////////////////////////////////////////////////////////////
		}
#ifdef version_401
		if((!Power.USB_active) && (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_9))){
			usb_activate(0x0); // Если питание USB начало подаваться включаем USB
		}
#endif

		if(!Power.USB_active)		// если USB не активен, можно уходить в сон
		{
			if(current_pulse_count<30)      // Если счетчик не зашкаливает, то можно уйти в сон
			{
				if(!Power.Pump_active && !Power.Sound_active)
				{
					PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);    // Переходим в сон
#ifdef debug
 					Wakeup.total_wakeup++;
					DataUpdate.Need_display_update=ENABLE;
#endif

				} else
				{
						PWR_EnterSleepMode(PWR_Regulator_ON, PWR_SLEEPEntry_WFI);
#ifdef debug
  					Wakeup.total_wakeup++;
						DataUpdate.Need_display_update=ENABLE;
#endif
				}
			}
		}else USB_work(); 		// если USB активен, попробовать передать данные
#ifdef debug
 					Wakeup.total_cycle++;
					DataUpdate.Need_display_update=ENABLE;
#endif

  }
/////////////////////////////////////////////////////////////////////////////// 
}
int main (void)
{
	char x, y, temp, q;
    ioinit(); //Setup IO pins and defaults
	//USART_Init( MYUBRR);
	set_baud(6);//115200
	rprintf_devopen(put_char); /* init rrprintf */
	
	//check for existing preset values==============================================================
	temp = EEPROM_read((unsigned int)BPS);
	
	if ((temp < 1) | (temp > 6))//BPS will only be 1-6
	{
		cli();//Disable Interrupts
		
		EEPROM_write((unsigned int) BPS, 6);
		EEPROM_write((unsigned int) BACKLIGHT, 100);
		EEPROM_write((unsigned int) SPLASH, 1);
		EEPROM_write((unsigned int) REV, 0);
		
		sei();//Enable Interrupts
		
		BL_dutycycle = 100;
		baud_rate = 6;
		splash_screen = 1;
		reverse = 0;
	}
	
	else
	{
		baud_rate = temp;
		BL_dutycycle = EEPROM_read((unsigned int)BACKLIGHT);
		splash_screen = EEPROM_read((unsigned int)SPLASH);
		reverse = EEPROM_read((unsigned int)REV);
	}
	
	
	//Reset the display
	PORTC &= ~(1 << RESET);
	delay_ms(50);
	PORTC |= (1 << RESET);
	//delay_ms(500);

	
	clear_screen();

	set_page(0);
	
	set_x(0);
	
	display_on();
	
	//set display start line to 0
	//set control lines
	PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));//down
	
	set_data(0xC0);
	//set_data(0xFF);
	delay();
	PORTC |= (1 << EN);//up
	delay();
	PORTC &= ~(1 << EN);//down
	delay();
	PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));//all high
	
	delay();
	
	x_offset = 0;

	set_page(0);
	
	DDRB |= (1<<BL_EN);//set PB2 as output
	
	set_backlight(BL_dutycycle);
	
	//Logo==========================================================
	if (splash_screen == 1)
	{
		y = 40;
		
		for (q = 0; q < 30; q++)
		{
			temp = logo[q];
			for (x = 56; x < 64; x++)
			{
				if (temp & 0x80) pixel(1,x,y);
				
				temp <<= 1;
			}
			
			q++;
			
			temp = logo[q];
			for (x = 64; x < 72; x++)
			{
				if (temp & 0x80) pixel(1,x,y);
				
				temp <<= 1;
			}
			y--;
	
		}	
	}
	
	pixel(0,0,0);//cheat
	
	RX_in = 0;
	
	delay_ms(1000);
	clear_screen();
	
	if (RX_in > 0)//revert to 115200
	{
		print_char(1,'1');
		print_char(1,'1');
		print_char(1,'5');
		print_char(1,'2');
		print_char(1,'0');
		print_char(1,'0');
		
		baud_rate = 6;
		set_baud(6);//115200
		
		cli();
		
		EEPROM_write((unsigned int) BPS, 6);
		
		sei();//Enable Interrupts
	}
	
	else (set_baud(baud_rate));
	
	delay_ms(1000);
	clear_screen();
	
	//main loop===================================================
	while(1)
	{
		if(RX_in != RX_read)
		{
			x = RX_array[RX_read];
			RX_read++;
			if(RX_read >= 416) RX_read = 0;
			
			//Backspace===================================================
			if(x == 8) del_char(0);
			
			//Special commands
			else if (x == 124)
			{	
				//make sure the next byte is there
				while(RX_in == RX_read);
				
				//0, clear screen======================================================
				if(RX_array[RX_read] == 0)//^@
				{
					clear_screen();
					RX_read++;
					if(RX_read >= 416) RX_read = 0;
				}
				
				//demo mode
				else if(RX_array[RX_read] == 4)//^d
				{
					RX_in = 0, RX_read = 0;
					demo();
					clear_screen();
					RX_in = 0;
				}
				
				
				//reverse mode
				else if(RX_array[RX_read] == 18)//^r
				{
					reverse ^= 1;
					clear_screen();
					RX_read++;
					if(RX_read >= 416) RX_read = 0;
					
					cli();
					EEPROM_write((unsigned int) REV, reverse);
					sei();
				}
				
				
				//toggle spasl screen
				else if(RX_array[RX_read] == 19)//^s
				{
					splash_screen ^= 1;
					//clear_screen();
					RX_read++;
					if(RX_read >= 416) RX_read = 0;
					
					cli();
					EEPROM_write((unsigned int) SPLASH, splash_screen);
					sei();
				}
				
				else
				{
					//set backlight (0 to 100)=========================================================
					if(RX_array[RX_read] == 2)//^b
					{
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
						while(RX_in == RX_read);//wait for byte
						BL_dutycycle = RX_array[RX_read];
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
						
						set_backlight(BL_dutycycle);
						
						cli();
						EEPROM_write((unsigned int) BACKLIGHT, BL_dutycycle);
						sei();
						
						

					}
					
					
					//change baud rate=========================================================
					if(RX_array[RX_read] == 7)//^g
					{
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
						while(RX_in == RX_read);//wait for byte
						//if (RX_array[RX_read] == '1') USART_Init( 1000000/2400-1);//4800
						//else if (RX_array[RX_read] == '2') USART_Init( 1000000/4800-1);//9600
						//else if (RX_array[RX_read] == '3') USART_Init( 1000000/9600-1);//19200
						//else if (RX_array[RX_read] == '4') USART_Init( 1000000/19200-1);//38400
						//else if (RX_array[RX_read] == '5') USART_Init( 1000000/28800-1);//57600
						//else if (RX_array[RX_read] == '6') USART_Init( 1000000/57600-1);//115200
						
						if ((RX_array[RX_read] > '0') * (RX_array[RX_read] < '7')) baud_rate = (RX_array[RX_read]) - 48;
						
						set_baud(baud_rate);
						
						cli();
						EEPROM_write((unsigned int) BPS, baud_rate);
						sei();
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
						
					}	
					
					
					//set x or y=========================================================
					if((RX_array[RX_read] == 24) | (RX_array[RX_read] == 25))//^x or ^y
					{
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
						while(RX_in == RX_read);//wait for byte
						if (RX_array[RX_read-1] == 24) x_offset = RX_array[RX_read];
						else if (RX_array[RX_read-1] == 25) y_offset = RX_array[RX_read];
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
						
						if (x_offset > 159) x_offset = 159;
						if (y_offset > 127) y_offset = 127;

					}

					//set pixel=========================================================
					if (RX_array[RX_read] == 16)//^p
					{
						//need 3 bytes
						for (y = 0; y < 3; y++)
						{
							RX_read++;
							if(RX_read >= 416) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						pixel(RX_array[RX_read], RX_array[RX_read-2], RX_array[RX_read-1]);
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;

					}

					
					//<ctrl>c, circle======================================================
					if(RX_array[RX_read] == 3)//^c
					{
						//need 4 bytes
						for (y = 0; y < 4; y++)
						{
							RX_read++;
							if(RX_read >= 416) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						circle(RX_array[RX_read], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1]);
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
					}
					
					
					//<ctrl>e, erase block======================================================
					if(RX_array[RX_read] == 5)//^e
					{
						//need 4 bytes
						for (y = 0; y < 4; y++)
						{
							RX_read++;
							if(RX_read >= 416) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						erase_block(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
					}
					
					
					//box======================================================
					if(RX_array[RX_read] == 15)//^o
					{
						//need 4 bytes
						for (y = 0; y < 4; y++)
						{
							RX_read++;
							if(RX_read >= 416) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						box(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
					}


					//line========================================================
					else if (RX_array[RX_read] == 12)//^l
					{
						//need 5 bytes
						for (y = 0; y < 5; y++)
						{
							RX_read++;
							if(RX_read >= 416) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						line(RX_array[RX_read], RX_array[RX_read-4], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read+-1]);
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
					}
					
					
				}
	
			}
			
			//print character to the screen===============================================
			else
			{
				del_char(1);
				print_char(1, x);
			}
		}
		
	}
	
	//demo();
	


    
}
Пример #14
0
static void display_off(volatile display_t *d)
{
    display_on(d, 0);
}
Пример #15
0
// Main loop of the program
int main(void)
{
    //
    // Set the clocking to run directly from the crystal. 8Mhz
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);
    delay(500);
    LED_init();
    delay(500);
    ADC_init(); //init the adc
    delay(500);
    timer0_init(); //init the first timer
    delay(500);
    timer1_init(); //second timer
    delay(500);
    key_init(); //keypad
    display_init();
    CPUcpsie(); //turn on cpu inttrupts

    //init all prices and indexes
    int upDownIndex = 0; 
    int currDollars = 0;
    int currCents = 0;
    int leftRightIndex = 0;
    display_on(1,1); 
    print_welcome(); //print initial welcome menu
 
     /*
    handles key inputs
    User can toggle through display menus (welcome menu, food menu,...) 
    using LEFT and RIGHT
    While on the food menu, user can toggle through food options using UP 
    and DOWN and select food items using SELECT.
    */
    while(1)
    {
      int currentKey = keymaster();
      if (!readKey) { //if we have not read the key since it has been updated
        switch (currentKey) //main control flow loop
        {
          case UP:
            if (upDownIndex) {
              upDownIndex--; //de-inc the vertical index
              print_menu(upDownIndex, currDollars, currCents);
            }
            break;
          case DOWN:
            if (upDownIndex < maxUpDownIndex) {
              upDownIndex++; //inc the vertical index
              print_menu(upDownIndex, currDollars, currCents);
            }
            break;
          case RIGHT:
            if (leftRightIndex < maxLeftRightIndex) {
              leftRightIndex++; //inc the left right index
              select_menu(&leftRightIndex, upDownIndex, currDollars, currCents);
            }
            break;
          case LEFT:
            if (leftRightIndex) {
              leftRightIndex--; //de-inc the left right index
              select_menu(&leftRightIndex, upDownIndex, currDollars, currCents);
            }
            break;
          case SELECT:
            currDollars += dollars[upDownIndex]; //update the total costs
            currCents += cents[upDownIndex];
            if (currCents >= 100) {
              currDollars += 1;
              currCents -= 100;
            }
            print_menu(upDownIndex, currDollars, currCents);
            break;
        }
      }
      readKey = 1; //tell timer 0 we have read the key
      //Reset the totals for the costs
      if (leftRightIndex == 0) {
        currDollars = 0;
        currCents = 0;
      }
    }

}
int main (void)
{
	char x, y;
	//char a = 0;
    ioinit(); //Setup IO pins and defaults
	USART_Init( MYUBRR);
	rprintf_devopen(put_char); /* init rrprintf */
	
	//set_data(0x55);

	//PORTC |= ((1 << RESET) | (1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2) | (1 << RS));//all high
	
	//while(1);
	
	/*
	while(1)
	{
		PORTC &= ~((1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2));//down
		delay_ms(500);
		//PORTC |= ((1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2));//all high
		PORTC |= ((1 << RESET) | (1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2) | (1 << RS));//all high
		delay_ms(500);
	}
	*/
	/*
	DDRC = 0b00000001;
	
	while(1)
	{
		PORTC |= 0b00000001;
		delay_1uS();
		PORTC &= 0b11111110;
		delay_1uS();
	
	}
	*/
	
	//Reset the display
	//PORTC = 0b11110111;
	PORTC &= ~(1 << RESET);
	delay_ms(50);
	PORTC |= (1 << RESET);
	delay_ms(500);
	
	clear_screen();
	
	set_page(0);
	set_x(0);
	
	display_on();
	
	//set display start line to 0
	//set control lines
	
	PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));//down
	set_port_out();
	//set_data(0xC0);
	set_data(0xC0);
	delay_us(4);
	PORTC |= (1 << EN);//up
	delay_us(4);
	PORTC &= ~(1 << EN);//down
	delay_us(4);
	PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));//all high
	
	set_port_in();
	delay_us(4);
	
	
	x_offset = 0;

	set_page(0);
	
	//Backlight on
	PORTB &= (~(1<<BL_EN));
	
	//demo();  
	//put_char('X');
	
	while(1)
	{
		if(RX_in != RX_read)
		{
			x = RX_array[RX_read];
			RX_read++;
			if(RX_read >= 256) RX_read = 0;
			
			
			
			//Backspace===================================================
			if(x == 8) del_char(0);
			
			//Special commands
			else if (x == 124)
			{	
				//make sure the next byte is there
				while(RX_in == RX_read);
				
				//0, clear screen======================================================
				if(RX_array[RX_read] == 0)
				{
					clear_screen();
					RX_read++;
					if(RX_read >= 256) RX_read = 0;
				}
				
				
				//Backlight on/off
				else if(RX_array[RX_read] == 2)
				{
					y = PINB;
					if (y & (1<<BL_EN)) PORTB &= (~(1<<BL_EN));
					else PORTB |= (1<<BL_EN);
					RX_read++;
				}
				
				//demo mode
				else if(RX_array[RX_read] == 4)
				{
					RX_in = 0, RX_read = 0;
					demo();
					clear_screen();
					RX_in = 0;
				}
				
				else
				{				
					//set x or y=========================================================
					if((RX_array[RX_read] == 24) | (RX_array[RX_read] == 25))
					{
						RX_read++;
						if(RX_read >= 256) RX_read = 0;
						while(RX_in == RX_read);//wait for byte
						if (RX_array[RX_read-1] == 24) x_offset = RX_array[RX_read];
						else if (RX_array[RX_read-1] == 25) y_offset = RX_array[RX_read];
						
						RX_read++;
						if(RX_read >= 256) RX_read = 0;
						
						if (x_offset > 127) x_offset = 127;
						if (y_offset > 63) y_offset = 63;

					}

					//set pixel=========================================================
					if (RX_array[RX_read] == 16)
					{
						//need 3 bytes
						for (y = 0; y < 3; y++)
						{
							RX_read++;
							if(RX_read >= 256) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						pixel(RX_array[RX_read], RX_array[RX_read-2], RX_array[RX_read-1]);
						
						RX_read++;
						if(RX_read >= 256) RX_read = 0;

					}

					//<ctrl>c, circle======================================================
					if(RX_array[RX_read] == 3)
					{
						//need 4 bytes
						for (y = 0; y < 4; y++)
						{
							RX_read++;
							if(RX_read >= 256) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						circle(RX_array[RX_read], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1]);
						
						RX_read++;
						if(RX_read >= 256) RX_read = 0;
					}
					
					
					//<ctrl>e, erase block======================================================
					if(RX_array[RX_read] == 5)
					{
						//need 4 bytes
						for (y = 0; y < 4; y++)
						{
							RX_read++;
							if(RX_read >= 256) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						erase_block(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
						
						RX_read++;
						if(RX_read >= 256) RX_read = 0;
					}
					
					
					//<ctrl>o, box, running out of meaningful letters======================================================
					if(RX_array[RX_read] == 15)
					{
						//need 4 bytes
						for (y = 0; y < 4; y++)
						{
							RX_read++;
							if(RX_read >= 256) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						box(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
						
						RX_read++;
						if(RX_read >= 256) RX_read = 0;
					}
					

					//<ctrl>L, line========================================================
					else if (RX_array[RX_read] == 12)
					{
						//need 5 bytes
						for (y = 0; y < 5; y++)
						{
							RX_read++;
							if(RX_read >= 256) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						line(RX_array[RX_read], RX_array[RX_read-4], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read+-1]);
						RX_read++;
						if(RX_read >= 256) RX_read = 0;
					}
					
					
				}
	
			}
			
			//print character to the screen===============================================
			else
			{
				
				del_char(1);
				//put_char('L');
				print_char(1, x);
				
			}
			
			//set_data(0xFF);
			//set_port_in();
			//display_on();
			//y = PINB;
			//PORTB = y;
		}
		
	}
	
}
Пример #17
0
Файл: io.c Проект: Fornax/RS485
void io_loop() {
	
	//Button decrement
	if ( BTN_DEC == 1u && old_btn_dec == 0u && cnt_dec == 0u ) {
		cnt_dec= 100;
		old_btn_dec= 1u;
		display_on(); //Show current address
	} else 	if ( BTN_DEC == 0u && old_btn_dec == 1u && cnt_dec == 0u ) {
		cnt_dec= 100;
		old_btn_dec= 0u;
		delay_unlock= 0u; //Reset unlocking time
		
		if (old_btn_inc == 0u) {
			if (!btn_ignore) {
				display_dec();
			}
			btn_ignore= 0u;
		} else {
			btn_ignore= 1u;
		}
	}
	//Button increment
	if ( BTN_INC == 1u && old_btn_inc == 0u && cnt_inc == 0u ) {
		cnt_inc= 100;
		old_btn_inc= 1u;
		display_on(); //Show current address
	} else if ( BTN_INC == 0u && old_btn_inc == 1u && cnt_inc == 0u ) {
		cnt_inc= 100;
		old_btn_inc= 0u;
		delay_unlock= 0u; //Reset unlocking time
		
		if (old_btn_dec == 0u) {
			if (!btn_ignore) {
				display_inc();
			}
			btn_ignore= 0u;
		} else {
			btn_ignore= 1u;
		}
	}
	
	//Input buttons
	if ( buttons_input == 0u && (INPUT1 == 0u && INPUT2 == 0u) && cnt_input == 0u ) {
		cnt_input= 100;
		buttons_input= 1u;
	} else if (buttons_input == 1u && (INPUT1 != 0u || INPUT2 != 0u) && cnt_input == 0u ) {
		cnt_input= 100;
		buttons_input= 0u;
		if (INPUT1&0x01) {inputs=9;}
		if (INPUT1&0x02) {inputs=8;}
		if (INPUT1&0x04) {inputs=7;}
		if (INPUT1&0x08) {inputs=6;}
		if (INPUT1&0x10) {inputs=5;}
		if (INPUT1&0x20) {inputs=4;}
		if (INPUT2&0x01) {inputs=3;}
		if (INPUT2&0x02) {inputs=2;}
		if (INPUT2&0x04) {inputs=1;}
	}
	//Input capture
	if ( CAPT1 == 1u && capt1 == 0u && cnt_capt == 0u ) {
		cnt_capt= 100;
		capt1= 1;
	} else if ( CAPT1 == 0u && capt1 == 1u && cnt_capt == 0u ) {
		cnt_capt= 100;
		capt1= 0;
		puls_counter++;
	}
	//both switches pressed
	if ( BTN_INC != 0u && BTN_DEC != 0u ) {
		if (cnt_dec == 0u && cnt_inc == 0u && delay_unlock == 0u) {
			delay_unlock= 2000;
		}
		
		//Unlock up/down counting.
		if (cnt_dec == 0u && cnt_inc == 0u && delay_unlock <= 200u) {
			display_unlock();
		}
	}
	
	//Display on
	if ( BTN_INC != 0u || BTN_DEC != 0u) {
		delay_off= 3000;
	}
	
	//Display off
	if ( delay_off == 0u ) {
		display_lock();
	}
}
Пример #18
0
Файл: 8bit.c Проект: note/ZigBee
int main(void){
	//ustawienie portow
	DDRD = 0xff;
	DDRC = 0x0f;
	PORTC = 0x30;
	DDRB = 0x00;
	PORTB = 0x02;
	
	display_on();
	display_clear();
	set_entry_mode();
	function_set();
	
	print("Ladies and");
	_delay_ms(1500);
	clear_line(0);
	
	print("Gentlemen");
	_delay_ms(1500);
	clear_line(0);
	
	print("We are floating");
	_delay_ms(1500);
	clear_line(0);
	
	print("in space");
	_delay_ms(1500);
	clear_line(0);
	
	short offset = 0;
	
	while(1){
	
		if(!(PINC & 0x20)){
			
			++offset;
			data_write('a'+offset);
			shift_cursor(SH_LEFT);
			
			_delay_ms(20); // przeczekaj drgania stykow
			
			uint8_t step = 10, counter = 0;
			while(!(PINC & 0x20)){ //dopoki wcisniety
				if(counter>100){
					step = 3;
					counter = 0;
					
					++offset;
					data_write('a'+offset);
					shift_cursor(SH_LEFT);
				}else
					++counter;
					
				_delay_ms(step);
			}
			_delay_ms(20); // przeczekaj drgania stykow
		}
		
		if(!(PINC & 0x10)){
			
			--offset;
			data_write('a'+offset);
			shift_cursor(SH_LEFT);
			
			_delay_ms(20); // przeczekaj drgania stykow
			
			uint8_t step = 10, counter = 0;
			while(!(PINC & 0x10)){ //dopoki wcisniety
				if(counter>100){
					step = 3;
					counter = 0;
					
					--offset;
					data_write('a'+offset);
					shift_cursor(SH_LEFT);
				}else
					++counter;
					
				_delay_ms(step);
			}
			_delay_ms(20); // przeczekaj drgania stykow
		}
		
		if(!(PINB & 0x2)){
			
			shift_cursor(SH_RIGHT);
			data_write('a');
			shift_cursor(SH_LEFT);
			offset = 0;
			
			_delay_ms(20); // przeczekaj drgania stykow
			while(!(PINB & 0x2)){} //dopoki wcisniety
			_delay_ms(20); // przeczekaj drgania stykow
		}
	}
}
Пример #19
0
int main (void)
{
        char x, y;
        //char a = 0;
    ioinit(); //Setup IO pins and defaults
        USART_Init( MYUBRR);
        rprintf_devopen(put_char); /* init rrprintf */
        
        //set_data(0x55);

        //PORTC |= ((1 << RESET) | (1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2) | (1 << RS));//all high
        
        //while(1);
        
        /*
        while(1)
        {
                PORTC &= ~((1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2));//down
                delay_ms(500);
                //PORTC |= ((1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2));//all high
                PORTC |= ((1 << RESET) | (1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2) | (1 << RS));//all high
                delay_ms(500);
        }
        */
        /*
        DDRC = 0b00000001;
        
        while(1)
        {
                PORTC |= 0b00000001;
                delay_1uS();
                PORTC &= 0b11111110;
                delay_1uS();
        
        }
        */
        
        //Reset the display
        //PORTC = 0b11110111;
        PORTC &= ~(1 << RESET);
        delay_ms(50);
        //PORTC = 0b11111111;
        PORTC |= (1 << RESET);
        delay_ms(500);
        
        clear_screen();
        
        set_page(0);
        set_x(0);
        
        display_on();
        
        //set display start line to 0
        //set control lines
        PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));//down
        
        set_data(0xC0);
        //set_data(0xFF);
        delay();
        PORTC |= (1 << EN);//up
        delay();
        PORTC &= ~(1 << EN);//down
        delay();
        PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));//all high
        
        delay();
        
        x_offset = 0;

        set_page(0);
        
        /*
        set_x(0);
        write_byte(0X55, 1);
        
        set_x(1);
        write_byte(0X55, 1);
        
        //set_x(0);
        x = read_byte(1,1);
        
        set_x(2);
        write_byte(x, 1);
        set_x(3);
        write_byte(x, 1);
        */
        

        //set_x(63);//???
        
        //x = read_byte(1);
        
        //set_x(3);
        
        //rite_byte(x, 1);
        
        //set_x(0);
        
        //write_byte(x, 1);
        
        //while(1);
        
        while(1)
        {
                line(0, 0, 63, 63);
                line(0, 10, 63, 52);
                line(0, 21, 63, 42);
                line(0, 32, 63, 32);
                line(0, 42, 63, 21);
                line(0, 52, 63, 10);
                line(0, 63, 63, 0);
        
                
                line(64, 0, 127, 63);
                line(64, 10, 127, 52);
                line(64, 21, 127, 42);
                line(64, 32, 127, 32);
                line(64, 42, 127, 21);
                line(64, 52, 127, 10);
                line(64, 63, 127, 0);
                
                //set_x(20);
                x_offset = 20;
                set_page(0);
                
                print_char('C');
                print_char('O');
                print_char('C');
                print_char('K');
                
                x_offset = 82;
                print_char('B');
                print_char('L');
                print_char('O');
                print_char('C');
                print_char('K');
                
                x_offset = 14;
                set_page(7);
                
                print_char('M');
                print_char('O');
                print_char('T');
                print_char('H');
                print_char('E');
                print_char('R');
                
                x_offset = 79;
                print_char('F');
                print_char('U');
                print_char('C');
                print_char('K');
                print_char('E');
                print_char('R');
                
                delay_ms(1000);
                clear_screen();
        }
        
        //line(0, 20, 127, 63);
        
        //line(20, 0, 127, 63);
        
        //line(0, 63, 127, 0);
        
        //pixel(127,63);
        //pixel(0,0);
        while(1);
        
        while(1)
        {
                for (y = 0; y < 64; y++)
                {
                        //set_x(0);
                        
                        //pixel(0,y);
                        //display_on();
                        //delay_ms(500);
                        
                        for(x = 0; x < 128; x++)
                        {
                                pixel(x,y);
                                //delay_ms(10);
                                display_on();
                        }
                
                }
                
                delay_ms(1000);
                clear_screen();
        
        }
        
        
        /*
        
        
        while(1);
        */
        
        /*
        for (a = 0; a < 64; a++)
        {
                set_x(a);
                write_byte(a,2);
                delay_ms(500);
        }
        */
        
        /*
        set_x(63);
        write_byte(0xFF,1);
        
        set_x(0);
        write_byte(0x55,1);
        
        while(1);
        */
        
        /*
        while(1)
        {
                for (a = 32; a < 128; a++)
                {
                        print_char(a);
                        
                        display_on();
                        delay_ms(50);
                }
        }        
        */

    
}