Пример #1
0
void lcd_cmd_shift(void){
  lcd_write_command(0x01);
  lcd_write_command(0x0c);
  lcd_write_command(0x01);
  lcd_write_command(0x07);  
  os_dly_wait(1);       //  38us=>минимальная задержка 1ms=>1ms
}
Пример #2
0
/** Initialize the display */
void lcd_init()
{
	// configure pins as output
	as_output(LCD_E);
	as_output(LCD_RW);
	as_output(LCD_RS);
	_lcd_mode = 1;  // force data pins to output
	_lcd_mode_w();

	// Magic sequence to invoke Cthulhu (or enter 4-bit mode)
	_delay_ms(16);
	_lcd_write_nibble(0b0011);
	_lcd_clk();
	_delay_ms(5);
	_lcd_clk();
	_delay_ms(5);
	_lcd_clk();
	_delay_ms(5);
	_lcd_write_nibble(0b0010);
	_lcd_clk();
	_delay_us(100);

	// Configure the display
	lcd_write_command(LCD_IFACE_4BIT_2LINE);
	lcd_write_command(LCD_DISABLE);
	lcd_write_command(LCD_CLEAR);
	lcd_write_command(LCD_MODE_INC);

	// mark as enabled
	lcd_enable();
}
/*
 * lcd_16207_init is called at boot time to initialise the LCD driver
 */
void alt_lcd_16207_init(alt_LCD_16207_dev * dev)
{
  unsigned int base = dev->base;

  /* Mark the device as functional */
  dev->broken = 0;

  ALT_SEM_CREATE (&dev->write_lock, 1);

  /* TODO: check that usleep can be called in an initialisation routine */

  /* The initialisation sequence below is copied from the datasheet for
   * the 16207 LCD display.  The first commands need to be timed because
   * the BUSY bit in the status register doesn't work until the display
   * has been reset three times.
   */

  /* Wait for 15 ms then reset */
  usleep(15000);
  IOWR_ALTERA_AVALON_LCD_16207_COMMAND(base, LCD_CMD_FUNCTION_SET | LCD_CMD_8BIT);

  /* Wait for another 4.1ms and reset again */
  usleep(4100);
  IOWR_ALTERA_AVALON_LCD_16207_COMMAND(base, LCD_CMD_FUNCTION_SET | LCD_CMD_8BIT);

  /* Wait a further 1 ms and reset a third time */
  usleep(1000);
  IOWR_ALTERA_AVALON_LCD_16207_COMMAND(base, LCD_CMD_FUNCTION_SET | LCD_CMD_8BIT);

  /* Setup interface parameters: 8 bit bus, 2 rows, 5x7 font */
  lcd_write_command(dev, LCD_CMD_FUNCTION_SET | LCD_CMD_8BIT | LCD_CMD_TWO_LINE);

  /* Turn display off */
  lcd_write_command(dev, LCD_CMD_ONOFF);

  /* Clear display */
  lcd_clear_screen(dev);

  /* Set mode: increment after writing, don't shift display */
  lcd_write_command(dev, LCD_CMD_MODES | LCD_CMD_MODE_INC);

  /* Turn display on */
  lcd_write_command(dev, LCD_CMD_ONOFF | LCD_CMD_ENABLE_DISP);

  dev->esccount = -1;
  memset(dev->escape, 0, sizeof(dev->escape));

  dev->scrollpos = 0;
  dev->scrollmax = 0;
  dev->active = 0;

  dev->period = alt_ticks_per_second() / 10; /* Call every 100ms */

  alt_alarm_start(&dev->alarm, dev->period, &alt_lcd_16207_timeout, dev);

  /* make the device available to the system */
  alt_dev_reg(&dev->dev);
}
Пример #4
0
void lcd_set_cursor(uint8_t line, uint8_t column)
{
	line &= 7;
	column &= 127;
	if(column > 95) column -= 96;
	lcd_state.current_line = line;
	lcd_state.current_column = column;
	lcd_write_command(0xB0 | line);
	lcd_write_command(0x10 | (column >> 4));
	lcd_write_command(column & 0x0F);
}
Пример #5
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);
	}
}
Пример #6
0
void lcd_cmd_display(bool display, bool cursor, bool blink){
  char cmd = 0x08;
  lcd_write_command(0x00);
  if(display)
    cmd |= 0x04;
  if(cursor)
    cmd |= 0x02;
  if(blink)
    cmd |= 0x01;
  lcd_write_command(cmd);
  os_dly_wait(1);       //  38us=>минимальная задержка 1ms=>1ms
}
Пример #7
0
/**
 * Plots a pixel at the specified coordinates.
 * @param x The x coordinante of the pixel.
 * @param y The y coordinante of the pixel.
 * @param state PIXEL_ON to set the pixel, otherwise pixel will be cleared.
 */
void lcd_graphics_plot_pixel(unsigned short x, unsigned short y, unsigned char state) {
	unsigned char pos;
	
	lcd_graphics_move(x, y);
	/* Since lcd_graphics_move() moves the cursor to a particular
	 * byte, not bit, we need the relative distance to the specified 
	 * bit we are going to set/clear. */
	pos = x%8;

	if (state == PIXEL_ON) 
		lcd_write_command(LCD_CMD_SET_BIT, pos);
	else 
		lcd_write_command(LCD_CMD_CLEAR_BIT, pos);
}
/* turn the display upside down (call lcd_update() afterwards) */
void lcd_set_flip(bool yesno)
{
    if (yesno) 
    {
        lcd_write_command(LCD_CNTL_COLUMN_ADDRESS_DIR | 1);
        lcd_write_command(LCD_CNTL_COMMON_OUTPUT_STATUS | 0);
        lcd_write_command_ex(LCD_CNTL_DUTY_SET, 0x20, 0);
    }
    else
    {
        lcd_write_command(LCD_CNTL_COLUMN_ADDRESS_DIR | 0);
        lcd_write_command(LCD_CNTL_COMMON_OUTPUT_STATUS | 1);
        lcd_write_command_ex(LCD_CNTL_DUTY_SET, 0x20, 1);
    }
}
Пример #9
0
void lcd_powerdown(void) {
    // switch display off
    lcd_write_command(LCD_CMD_DISPLAY_OFF);

    // all pixels on
    lcd_write_command(LCD_CMD_MODE_ALLBLACK);

    // wait
    wdt_reset();
    delay_ms(100);
    wdt_reset();
    delay_ms(100);
    wdt_reset();
    delay_ms(100);
}
Пример #10
0
void lcd_update_rect(int x, int y, int width, int height)
{
    int ymax;

    /* The Y coordinates have to work on even 8 pixel rows */
    ymax = (y + height-1) >> 2;
    y >>= 2;

    if(x + width > LCD_WIDTH)
        width = LCD_WIDTH - x;
    if (width <= 0)
        return; /* nothing left to do, 0 is harmful to lcd_write_data() */
    if(ymax >= LCD_FBHEIGHT)
        ymax = LCD_FBHEIGHT-1;

    /* Copy specified rectange bitmap to hardware */
    for (; y <= ymax; y++)
    {
        lcd_write_command_ex(LCD_CNTL_PAGE, y, -1);
        lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1);

        lcd_write_command(LCD_CNTL_DATA_WRITE);
        lcd_write_data (&lcd_framebuffer[y][x], width);
    }
}
Пример #11
0
Файл: 1602.c Проект: timqi/watch
/****光标定位******/
void disp_xy(uchar x, uchar y)
{
	uchar tmp;
	tmp = x & 0x0f;
	y  &= 0x1;
	if(x > 15)  tmp |= 0x40;  //在第二行显示
	if(y == 1)	tmp |= 0x40;
	tmp |= 0x80;			   //D7位置1,表示状态繁忙
	lcd_write_command(tmp,0);
}
Пример #12
0
/**
 * Moves the LCD cursor to the specified coordinates. 
 * @param x The new x coordinante of the cursor.
 * @param y The new y coordinante of the cursor.
 */
void lcd_graphics_move(unsigned short x, unsigned short y) {
	unsigned short pos;

	/* Calculate the raw address in terms of bytes on the screen */
	pos = ((y*LCD_WIDTH)+x)/8;

	/* Move the cursor to the new address */
	lcd_write_command(LCD_CMD_CURSOR_LA, pos&0xFF);
	lcd_write_command(LCD_CMD_CURSOR_HA, pos>>8);
}
Пример #13
0
/**
 * Initializes the LCD in graphics mode.
 * Uses a character pitch of 8 (8 bits are plotted whenever a byte is drawn)
 */ 
void lcd_graphics_init(void) {
	unsigned char commandData;

	/* Set the data direction registers apprioriately */
	LCD_DATA_DDR = 0xFF;
	LCD_CTRL_DDR |= (1<<LCD_CTRL_RS)|(1<<LCD_CTRL_RW)|(1<<LCD_CTRL_E)|(1<<LCD_CTRL_CS)|(1<<LCD_CTRL_RST);

	/* Assert all control lines to low */
	lcd_rw_low();
	lcd_enable_low();
	
	/* Reset the LCD controllers */
  	lcd_rst_low(); 
        _delay_ms(100); /* Delay for 100 ms */
        lcd_rst_high();
        _delay_ms(100); /* Delay for 100 ms */
  
        /* Assert all registor control line to low */
  	lcd_rs_low();

	/* Send mode configuration command with
	 * Toggle Display On, Master, Mode Graphics bits set */
	commandData = LCD_MODE_ON_OFF | LCD_MODE_MASTER_SLAVE | LCD_MODE_MODE;
	lcd_write_command(LCD_CMD_MODE, commandData);

	/* Send the set character pitch command with horizontal
 	 * character pitch of 8 (so 8 pixels are painted when we draw) */	
	commandData = LCD_CHAR_PITCH_HP_8;
	lcd_write_command(LCD_CMD_CHAR_PITCH, commandData);
	
	/* Send the number of characters command with the total
	 * number of graphics bytes that can be painted horizontally 
	 * (width/8) */
	commandData = (LCD_WIDTH/8)-1;
	lcd_write_command(LCD_CMD_NUM_CHARS, commandData);

	/* Set the time division */
	commandData = 128-1;
	lcd_write_command(LCD_CMD_TIME_DIVISION, commandData);
	
	/* Set the display low/high start address to 0x00 (left corner) */
	commandData = 0x00;
	lcd_write_command(LCD_CMD_DISPLAY_START_LA, commandData);
	lcd_write_command(LCD_CMD_DISPLAY_START_HA, commandData);

	/* Reset the cursor to home 0x00 (left corner) */
	commandData = 0x00;
	lcd_write_command(LCD_CMD_CURSOR_LA, commandData);
	lcd_write_command(LCD_CMD_CURSOR_HA, commandData);
}
Пример #14
0
/* Performance function that works with an external buffer
   note that by and bheight are in 8-pixel units! */
void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
                   int bheight, int stride)
{
    const unsigned char *src, *src_end;
    unsigned char *dst_u, *dst_l;
    static unsigned char upper[LCD_WIDTH] IBSS_ATTR;
    static unsigned char lower[LCD_WIDTH] IBSS_ATTR;
    unsigned int byte;

    by *= 2;

    while (bheight--)
    {
        src = data;
        src_end = data + width;
        dst_u = upper;
        dst_l = lower;
        do
        {
            byte = *src++;
            *dst_u++ = lcd_dibits[byte & 0x0F];
            byte >>= 4;
            *dst_l++ = lcd_dibits[byte & 0x0F];
        }
        while (src < src_end);

        lcd_write_command_ex(LCD_CNTL_PAGE, by++, -1);
        lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1);
        lcd_write_command(LCD_CNTL_DATA_WRITE);
        lcd_write_data(upper, width);

        lcd_write_command_ex(LCD_CNTL_PAGE, by++, -1);
        lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1);
        lcd_write_command(LCD_CNTL_DATA_WRITE);
        lcd_write_data(lower, width);

        data += stride;
    }
}
Пример #15
0
void lcd_update(void)
{

    /* Setup initial PAGE and COLUMN address
     * the addressing circuit will take care of the rest
     */
    lcd_write_command_ex(LCD_CNTL_PAGE, 0, -1);
    lcd_write_command_ex(LCD_CNTL_COLUMN, 0, -1);
    lcd_write_command(LCD_CNTL_DATA_WRITE);

    /* Copy display bitmap to hardware */
    lcd_write_data (&lcd_framebuffer[0][0], LCD_WIDTH*LCD_FBHEIGHT);
}
Пример #16
0
/* Performance function that works with an external buffer
   note that by and bheight are in 4-pixel units! */
void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
                         int x, int by, int width, int bheight, int stride)
{
    stride <<= 2; /* 4 pixels per block */
    while (bheight--)
    {
        lcd_write_command_ex(LCD_CNTL_PAGE, by++, -1);
        lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1);
        lcd_write_command(LCD_CNTL_DATA_WRITE);
        lcd_grey_data(values, phases, width);
        values += stride;
        phases += stride;
    }
}
static void lcd_clear_screen(alt_LCD_16207_dev * dev)
{
  int y;

  lcd_write_command(dev, LCD_CMD_CLEAR);

  dev->x = 0;
  dev->y = 0;
  dev->address = 0;

  for (y = 0 ; y < ALT_LCD_HEIGHT ; y++)
  {
    memset(dev->line[y].data, ' ', sizeof(dev->line[0].data));
    memset(dev->line[y].visible, ' ', sizeof(dev->line[0].visible));
    dev->line[y].width = 0;
  }
}
Пример #18
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;
}
Пример #19
0
Файл: 1602.c Проект: timqi/watch
/****液晶初始化程序*******/
void lcd_reset()
{		  //按照手册相关步骤初始化

unsigned int i;
	lcd_write_command(0x38,0);
//	delay_Ms(10);  
	for (i=0;i<1000;i++);
	lcd_write_command(0x38,0);
//	delay_Ms(10);
	for (i=0;i<1000;i++);
	lcd_write_command(0x38,0);
//	delay_Ms(10);
	for (i=0;i<1000;i++);

	lcd_write_command(0x38,1);
	lcd_write_command(0x08,1);
	lcd_write_command(0x01,1);
	lcd_write_command(0x06,1);
	lcd_write_command(0x0c,1);
}
Пример #20
0
void lcd_init_device(void)
{
    and_l(~0x00000800, &GPIO_FUNCTION); /* CS3 line */

    /* LCD Reset GPO34 */
    or_l(0x00000004, &GPIO1_ENABLE);    /* set as output */
    or_l(0x00000004, &GPIO1_FUNCTION);  /* switch to secondary function - GPIO */

    and_l(~0x00000004, &GPIO1_OUT);     /* RESET low */
    sleep(1);                           /* delay at least 1000 ns */
    or_l(0x00000004, &GPIO1_OUT);       /* RESET high */
    sleep(1);

    lcd_write_command(LCD_CNTL_ON_OFF | 1); /* LCD ON */
    lcd_write_command(LCD_CNTL_OFF_MODE | 1); /* OFF -> VCC on drivers */
    lcd_write_command(LCD_CNTL_REVERSE | 0); /* Reverse OFF */
    lcd_write_command(LCD_CNTL_ALL_LIGHTING | 0); /* Normal */
    lcd_write_command(LCD_CNTL_COMMON_OUTPUT_STATUS | 1); /* Reverse dir */
    lcd_write_command_ex(LCD_CNTL_DISPLAY_START_LINE, 0, -1);
    lcd_write_command(LCD_CNTL_COLUMN_ADDRESS_DIR | 0);   /* Normal */
    lcd_write_command_ex(LCD_CNTL_DISPLAY_MODE, 0, -1); /* Greyscale mode */
    lcd_write_command_ex(LCD_CNTL_GRAY_SCALE_PATTERN, 0x53, -1);
    lcd_write_command_ex(LCD_CNTL_DUTY_SET, 0x20, 1);
    lcd_write_command_ex(LCD_CNTL_ELECTRONIC_VOLUME, 24, -1); /* 0x18 */

    lcd_write_command(LCD_CNTL_OSC_ON_OFF | 1); /* Oscillator ON */
    lcd_write_command(LCD_CNTL_POWER_SAVE | 0);
    lcd_write_command_ex(LCD_CNTL_VOLTAGE_SELECT, 3, -1);
    lcd_write_command_ex(LCD_CNTL_POWER_CONTROL, 0x17, -1);
    lcd_write_command_ex(LCD_CNTL_OSC_FREQUENCY, 3, -1);
    lcd_write_command(LCD_CNTL_NLINE_ON_OFF | 1); /* N-line ON */
    lcd_write_command_ex(LCD_CNTL_LINE_INVERT_DRIVE, 0x10, -1);
    lcd_write_command_ex(LCD_CNTL_TEMP_GRADIENT_SELECT, 0, -1);

    lcd_update();
}
Пример #21
0
void lcd_send_data(const uint8_t *buf) {
    uint32_t x, y;

    // set start to 0,0
    lcd_write_command(LCD_CMD_SET_STARTLINE + 0);
    lcd_write_command(LCD_CMD_SET_PAGESTART + 2);

    // set col address of ram to 0
    lcd_write_command(LCD_CMD_SET_COL_LO + 0);
    lcd_write_command(LCD_CMD_SET_COL_HI + 0);

    for (y = 0; y < 8; y++) {
        // start on col 0
        lcd_write_command(LCD_CMD_SET_COL_LO + 0);
        lcd_write_command(LCD_CMD_SET_COL_HI + 0);
        // page start
        lcd_write_command(LCD_CMD_SET_PAGESTART + y);

        LCD_CS_LO();
        LCD_RS_HI();
        LCD_RW_LO();

        // send 4 dummy bytes(132-128)
        for (x = 4; x > 0; --x) {
            LCD_DATA_SET(0x00);
            LCD_RD_HI();
            LCD_RD_LO();
        }

        for (x = 128; x > 0; --x) {
            LCD_DATA_SET(*buf++);
            // execute write
            LCD_RD_HI();
            LCD_RD_LO();
        }
    }

    LCD_RD_HI();

    // deselect device
    LCD_CS_HI();
    LCD_RW_HI();
}
static void lcd_repaint_screen(alt_LCD_16207_dev * dev)
{
  int y, x;

  /* scrollpos controls how much the lines have scrolled round.  The speed
   * each line scrolls at is controlled by its speed variable - while
   * scrolline lines will wrap at the position set by width
   */

  int scrollpos = dev->scrollpos;

  for (y = 0 ; y < ALT_LCD_HEIGHT ; y++)
  {
    int width  = dev->line[y].width;
    int offset = (scrollpos * dev->line[y].speed) >> 8;
    if (offset >= width)
      offset = 0;

    for (x = 0 ; x < ALT_LCD_WIDTH ; x++)
    {
      char c = dev->line[y].data[(x + offset) % width];

      /* Writing data takes 40us, so don't do it unless required */
      if (dev->line[y].visible[x] != c)
      {
        unsigned char address = x + colstart[y];

        if (address != dev->address)
        {
          lcd_write_command(dev, LCD_CMD_WRITE_DATA | address);
          dev->address = address;
        }

        lcd_write_data(dev, c);
        dev->line[y].visible[x] = c;
      }
    }
  }
}
Пример #23
0
void lcd_periodic (void) 
{
	int x;
	unsigned char tuchar;
	
	if (timeout_lcd) {
		timeout_lcd--;
		return;
	}
	
	if (!state_lcd)
		return;
			
	if (buffer_lcd_counter > 0) {
		x = buffer_lcd[index_lcd];
		index_lcd++;
		if (index_lcd >= buffer_lcd_counter) {
			buffer_lcd_counter = 0;
			index_lcd = 0;
			state_lcd = 0;
		}
			
		if (x >= 256) {
			// é dado
			lcd_write_data ((char)(x & 0x00FF));
			timeout_lcd = TIMEOUT_LCD_DATA;
		}
		else {
			// é comando
			tuchar = (unsigned char)(x & 0x00FF);
			lcd_write_command (tuchar);
			timeout_lcd = TIMEOUT_LCD_CMD;
		}
	}
	else {
		state_lcd = 0;
	}
}
Пример #24
0
/** Set address in CGRAM */
void lcd_set_addr_cgram(const uint8_t acg)
{
	lcd_write_command(0b01000000 | ((acg) & 0b00111111));
}
Пример #25
0
/** Go home */
void lcd_home()
{
	lcd_write_command(LCD_HOME);
}
Пример #26
0
/** Clear the screen */
void lcd_clear()
{
	lcd_write_command(LCD_CLEAR);
}
Пример #27
0
/** Set address in DDRAM */
void lcd_set_addr(const uint8_t add)
{
	lcd_write_command(0b10000000 | ((add) & 0b01111111));
}
int main(void)
{
  
  //LCD_begin();

  UINT16 i=0,temporary1,temporary2,song_num=0,song_position=0,k,key,key2,key3,key4,sw[17],sw0,sw1,clupsec_num,data_sector;
  
  
  UINT16 back[2]={0},num_lyric,num_music,num_lyrics,time_base,j_base,base,fat_addr,cluster_num;

  UINT32 j;
  unsigned int cl[3000];
  BYTE Buffer[512]={0};
  
  while(SD_card_init())  // wait for the card to be inserted
    usleep(500000);
  LCD_begin();
  
  struct music0 music[30];
  struct lyric0 lyric[30];
  struct lyrics0 lyrics;
  
  char title[2][18]={" Press KEY1 to   ",
                      " select a song   "}; 
  char text[2][16]={"songs",
                    "lyrics"};
  char wait[16]="loading";
  
  file_list(music,lyric,&num_music,&num_lyric,&clupsec_num, &data_sector,&fat_addr); // search and update the database from the SD card
  sw1=IORD(SW_BASE,0);
  back[0]=sw1&0x20000;
  
  while(1)
  { 
    
    IOWR(SEG7_BASE,0,0);
    sw0=IORD(SW_BASE,0);
    sw0=sw0&0x07; 
    sw[0]=sw0&0x01;
    sw[1]=sw0&0x02;   
    sw[2]=sw0&0x04; 
    

    if(!sw0)
    {
      LCD_Init();   
      LCD_Show_Text(title[0]);
      lcd_write_command(LCD_BASE,0xC0);
      LCD_Show_Text(title[1]);
      while(1)
      {
        key=IORD(KEY_BASE,0);      // wait till key2 is pressed
        key2=~key&0x02;
        if(key2)
          break;
      }
      LCD_Init();
      lcd_write_command(LCD_BASE,0x80);
      usleep(100);  
      lcd_write_data(LCD_BASE,(char)(num_music/10+0x30));   // display the number of wav files
      usleep(100);  
      lcd_write_data(LCD_BASE,(char)(num_music%10+0x30));
      usleep(100);
      for(i=0;i<5;i++)
      {
        lcd_write_data(LCD_BASE,text[0][i]);
        usleep(100);
      }
      lcd_write_command(LCD_BASE,0xc0);
      usleep(100);  
      lcd_write_data(LCD_BASE,(char)(num_lyric/10+0x30));  // display the number of lysic files
      usleep(100);  
      lcd_write_data(LCD_BASE,(char)(num_lyric%10+0x30));
      usleep(100);
      for(i=0;i<6;i++)
      {
        lcd_write_data(LCD_BASE,text[1][i]);
         usleep(100);
      }
     usleep(1000000);
     
     while(1)
     {
        show_name(music[song_num].m_name);
        key=IORD(KEY_BASE,0);
        key=~key&0x0e; 
        if(key)
        {   
           key2=key&0x02;
           key3=key&0x04;
           key4=key&0x08;
           if(key2)
             break;
           else if(key3)
           {  
             song_num=(song_num+1)%num_music;           // next song
           }
           else if(key4)
           {
             song_num=(song_num+num_music-1)%num_music;  // previous song
           }
           else
           ;
        }
         time(0,song_num+1,num_music);    
     }
    }
    
    else if(sw[0])       {
      song_num=(song_num+1)%num_music;      // continuous 
      time(0,song_num+1,num_music); 
    }
    else if(sw[1])          {
      song_num+=0;
      time(0,song_num+1,num_music);        // repeat the song
    }
    else if(sw[2])
    {
      song_num=(num_lyrics+temporary1+temporary2+music[song_num].m_name[0])%num_music;  // random play
      time(0,song_num+1,num_music);   
    }    
    LCD_Init();    
    LCD_Show_Text(wait);
    num_lyrics=read_lyrics(music[song_num].m_name,lyric,&lyrics,num_lyric,&clupsec_num, &data_sector); //lyrics
    cl[0]=music[song_num].cluster;
    find_cluster(song_num,fat_addr,cl);
    for(i=0;cl[i]>1;i++);
    cluster_num=i;  
    
    show_name(music[song_num].m_name);   // show the name of the song
    for(song_position=0;song_position<cluster_num;song_position++)
    {  
      base=(cl[song_position]-2)*clupsec_num+data_sector;
      j_base=song_position*clupsec_num-base;
      sw1=IORD(SW_BASE,0);
      sw[4]=sw1&0x10;
      sw[5]=sw1&0x20; 
      sw[6]=sw1&0x40;
      
      back[1]=sw1&0x20000;
      if(back[1]!=back[0])
      {
        back[0]=back[1];
        break;
      } 
      if(sw[4])
      {
         song_position=(song_position+4)%cluster_num;
         time(song_position*clupsec_num,song_num+1,num_music);    // fast forward
         usleep(20000);
         continue;        
      }
      else if(sw[6])
      {
         song_position=(song_position+cluster_num-4)%cluster_num;
         time(song_position*clupsec_num,song_num+1,num_music);   // pause
         usleep(20000);
         continue;
      }    
      else if(sw[5])
      {
         song_position=(song_position+cluster_num-1)%cluster_num;  // reverse
         usleep(20000);
         continue;
      }   
      
      for(j=base;j<base+clupsec_num;j++) //j is the section in the cluster
      {      
        SD_read_lba(Buffer,j,1);    // read function from SD card controller.c
        i=0;
        while(i<512)
        {
          if(!IORD(AUDIO_BASE,0))
          {
            temporary1=((Buffer[i+1]<<8)|Buffer[i]);   // read from SD card
           
            IOWR(AUDIO_BASE,0,temporary1);
            
            i+=2;            
          }
        }

        if(j%32==0)
        {
            unsigned int x=0;
            unsigned int y=0xffff;
            unsigned int z = temporary1;
            do
            {
                x++;
                z=z<<1;
            }while((z & 0x8000)==0);
            y=y>>x;
            IOWR(LEDR_BASE,0,y);
            IOWR(LEDG_BASE,0,z);
        }
/********************************************************************/

        time(j+j_base,song_num+1,num_music); //display time

        for(k=0;k<num_lyrics;k++)            //display lyric
        {       
          time_base=j_base-lyrics.time[k]-2;       
          if(j+j_base==lyrics.time[k])   
          {    
            lcd_write_command(LCD_BASE,0x80);
            break;
          }
          else if(j+j_base==lyrics.time[k]+36)
          {
            lcd_write_command(LCD_BASE,0xc0);
            break;          
          }
          
          else if(j%2==0&&(j+j_base>=lyrics.time[k]+2)&&(j+j_base<=lyrics.time[k]+34))
          {
              lcd_write_data(LCD_BASE,lyrics.text[k][(j+time_base)/2]);
              break;             
          }          
          else if(j%2==0&&(j+j_base>=lyrics.time[k]+38)&&(j+j_base<lyrics.time[k]+70))
          {
              lcd_write_data(LCD_BASE,lyrics.text[k][(j+time_base)/2-2]);
              break;            
          }          
        }             
    }   
   }
  }
Пример #29
0
/**
 * Draws a byte to the LCD at the current LCD's cursor location.
 * @param data The byte to draw. The pixels are drawn MSB to LSB.
 */
void lcd_graphics_draw_byte(unsigned char data) {
	lcd_write_command(LCD_CMD_WRITE_DATA, data);
}
Пример #30
0
/** Display display (preserving cursor) */
void lcd_disable()
{
	lcd_write_command(LCD_DISABLE);
	_lcd_enabled = false;
}