⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 font.c

📁 AVR控制12864液晶画圆弧,在AVR单片机的控制下完成圆弧的绘制。
💻 C
📖 第 1 页 / 共 5 页
字号:
//*****************************************************************
//本头文件实现了用于字符显示的宏以及显示函数和显示的数据
//                   ---北京交通大学电气学院 杨罡 2008.8
//*****************************************************************

#include "font.h"

void lcd_glyph(uint8_t left, uint8_t top, uint8_t width, uint8_t height,
               uint8_t *glyph_ptr, uint8_t store_width)
 { uint8_t bit_pos;
   uint8_t byte_offset;
   uint8_t y_bits;
   uint8_t remaining_bits;
   uint8_t mask;
   uint8_t char_mask;
   uint8_t x;
   uint8_t *glyph_scan;
   uint8_t glyph_offset;

   bit_pos = top & 0x07;		/* get the bit offset into a byte */
   glyph_offset = 0;			/* start at left side of the glyph rasters */
   char_mask = 0x80;			/* initial character glyph mask */

   for (x = left; x < (left + width); x++)
    { 
	   
	  byte_offset = top >> 3;        	/* get the byte offset into y direction */
      y_bits = height;		/* get length in y direction to write */
      remaining_bits = 8 - bit_pos;	/* number of bits left in byte */
      mask = l_mask_array[bit_pos];	/* get mask for this bit */
      glyph_scan = glyph_ptr + glyph_offset;	 /* point to base of the glyph */
      /* boundary checking here to account for the possibility of  */
      /* write past the bottom of the screen.                        */
	  while((y_bits) && (byte_offset < LCD_Y_BYTES)) /* while there are bits still to write */
       { /* check if the character pixel is set or not */
         //if(*glyph_scan & char_mask)
         if(pgm_read_byte(glyph_scan) & char_mask)
            l_display_array[byte_offset][x] |= mask;	/* set image pixel */
         else
            l_display_array[byte_offset][x] &= ~mask;	/* clear the image pixel */    
         if(l_mask_array[0] & 0x80)
            mask >>= 1;
         else
            mask <<= 1;
			
         y_bits--;
         remaining_bits--;
         if(remaining_bits == 0)
          { /* just crossed over a byte boundry, reset byte counts */
            remaining_bits = 8;
            byte_offset++;
            mask = l_mask_array[0];
          }
		 
          /* bump the glyph scan to next raster */
          glyph_scan += store_width;
		  
       }
     
      /* shift over to next glyph bit */
      char_mask >>= 1;
      if(char_mask == 0)				/* reset for next byte in raster */
       { char_mask = 0x80;
         glyph_offset++;
       }
	 
   }
 }


/*
 Prints the given string at location x,y in the specified font.
 Prints each character given via calls to lcd_glyph. The entry string
 is null terminated. (adapted function from the MJK-code)
 Arguments are:
	left       coordinate of left start of string.
	top        coordinate of top of string.
	font       font number to use for display (see fonts.h)
	str        text string to display (null-terminated)
*/ 
 void lcd_text(uint8_t left, uint8_t top, uint8_t font,   char *str)
 { uint8_t x = left;
   uint8_t glyph;
   uint8_t width;
   uint8_t height, defaultheight;
   uint8_t store_width;
   uint8_t *glyph_ptr;
   uint8_t *width_table_ptr;
   uint8_t *glyph_table_ptr;
   uint8_t glyph_beg, glyph_end;
   uint8_t fixedwidth;
   uint8_t inprogmem=0;//mine
  
   defaultheight = (fonts[font].glyph_height);//pgm_read_byte ( &(fonts[font].glyph_height) );
   store_width =   (fonts[font].store_width);//pgm_read_byte ( &(fonts[font].store_width) );
   width_table_ptr = (uint8_t*)(fonts[font].width_table);//(uint8_t*) pgm_read_word( &(fonts[font].width_table) );
   glyph_table_ptr = (uint8_t*)(fonts[font].glyph_table);//(uint8_t*)pgm_read_word( &(fonts[font].glyph_table) );
   glyph_beg  = (fonts[font].glyph_beg);//pgm_read_byte( &(fonts[font].glyph_beg) );
   glyph_end  = (fonts[font].glyph_end);//pgm_read_byte( &(fonts[font].glyph_end) );
   fixedwidth = (fonts[font].fixed_width);//pgm_read_byte( &(fonts[font].fixed_width) );

   if (inprogmem) 
      glyph = pgm_read_byte(str);
    
   else 
      glyph = (uint8_t)*str;
	
   while(glyph != 0x00) // while(*str != 0x00)
    { /* check to make sure the symbol is a legal one */
      /* if not then just replace it with the default character */
      if((glyph < glyph_beg) || (glyph > glyph_end))
         glyph = (fonts[font].glyph_def);//pgm_read_byte( &(fonts[font].glyph_def) ) ;

      /* make zero based index into the font data arrays */
      glyph -= glyph_beg;
      if(fixedwidth == 0)
         // width=fonts[font].width_table[glyph];	/* get the variable width instead */
         width=pgm_read_byte(width_table_ptr+glyph);
      else 
         width = fixedwidth;
		
      height = defaultheight;
      //glyph_ptr = fonts[font].glyph_table + ((unsigned int)glyph * (unsigned int)store_width * (unsigned int)height);
      glyph_ptr = glyph_table_ptr + ((unsigned int)glyph * (unsigned int)store_width * (unsigned int)height) ;

      /* range check / limit things here */
      if(x > SCRN_RIGHT)
         x = SCRN_RIGHT;
       
      if((x + width) > SCRN_RIGHT+1)
         width = SCRN_RIGHT - x + 1;
       
      if(top > SCRN_BOTTOM)
         top = SCRN_BOTTOM;
       
      if((top + height) > SCRN_BOTTOM+1)
         height = SCRN_BOTTOM - top + 1;
       
      lcd_glyph(x,top,width,height,glyph_ptr,store_width);  /* plug symbol into buffer */

      x += width;		/* move right for next character */
      str++;			/* point to next character in string */
      if (inprogmem) 
         glyph = pgm_read_byte(str);
      else 
         glyph = (uint8_t)*str;
       
    }
 }
void lcd_text_p(uint8_t left, uint8_t top, uint8_t font,  const char *str)
 { uint8_t x = left;
   uint8_t glyph;
   uint8_t width;
   uint8_t height, defaultheight;
   uint8_t store_width;
   uint8_t *glyph_ptr;
   uint8_t *width_table_ptr;
   uint8_t *glyph_table_ptr;
   uint8_t glyph_beg, glyph_end;
   uint8_t fixedwidth;
   uint8_t inprogmem=1;//mine
   
   defaultheight = (fonts[font].glyph_height);//pgm_read_byte ( &(fonts[font].glyph_height) );
   store_width =   (fonts[font].store_width);//pgm_read_byte ( &(fonts[font].store_width) );
   width_table_ptr = (uint8_t*)(fonts[font].width_table);//(uint8_t*) pgm_read_word( &(fonts[font].width_table) );
   glyph_table_ptr = (uint8_t*)(fonts[font].glyph_table);//(uint8_t*)pgm_read_word( &(fonts[font].glyph_table) );
   glyph_beg  = (fonts[font].glyph_beg);//pgm_read_byte( &(fonts[font].glyph_beg) );
   glyph_end  = (fonts[font].glyph_end);//pgm_read_byte( &(fonts[font].glyph_end) );
   fixedwidth = (fonts[font].fixed_width);//pgm_read_byte( &(fonts[font].fixed_width) );

   if (inprogmem) 
      glyph = pgm_read_byte(str);
    
   else 
      glyph = (uint8_t)*str;
	
   while(glyph != 0x00) // while(*str != 0x00)
    { /* check to make sure the symbol is a legal one */
      /* if not then just replace it with the default character */
      if((glyph < glyph_beg) || (glyph > glyph_end))
         glyph = (fonts[font].glyph_def);//pgm_read_byte( &(fonts[font].glyph_def) ) ;

      /* make zero based index into the font data arrays */
      glyph -= glyph_beg;
      if(fixedwidth == 0)
         // width=fonts[font].width_table[glyph];	/* get the variable width instead */
         width=pgm_read_byte(width_table_ptr+glyph);
      else 
         width = fixedwidth;
		
      height = defaultheight;
      //glyph_ptr = fonts[font].glyph_table + ((unsigned int)glyph * (unsigned int)store_width * (unsigned int)height);
      glyph_ptr = glyph_table_ptr + ((unsigned int)glyph * (unsigned int)store_width * (unsigned int)height) ;

      /* range check / limit things here */
      if(x > SCRN_RIGHT)
         x = SCRN_RIGHT;
       
      if((x + width) > SCRN_RIGHT+1)
         width = SCRN_RIGHT - x + 1;
       
      if(top > SCRN_BOTTOM)
         top = SCRN_BOTTOM;
       
      if((top + height) > SCRN_BOTTOM+1)
         height = SCRN_BOTTOM - top + 1;
       
      lcd_glyph(x,top,width,height,glyph_ptr,store_width);  /* plug symbol into buffer */

      x += width;		/* move right for next character */
      str++;			/* point to next character in string */
      if (inprogmem) 
         glyph = pgm_read_byte(str);
      else 
         glyph = (uint8_t)*str;
       
    }
 }
 
 
const struct FONT_DEF fonts[FONT_COUNT]  = 
 { //
#ifdef EN_FIVE_DOT
   {1,  7, five_dot_glyph_table, 0, five_dot_width_table,' ','~','.'},
#endif

#ifdef EN_SIX_DOT
   {2,  8, six_dot_glyph_table, 0, six_dot_width_table,' ','~','.'},
#endif

#ifdef EN_SEVEN_DOT
   //{2,  8, seven_dot_glyph_table, 0, seven_dot_width_table,' ','~','.'},
	{2,  8, seven_dot_glyph_table, 0, seven_dot_width_table,' ',DEG_CHAR,'.'},
#endif

#ifdef EN_NINE_DOT
   {1, 12, nine_dot_glyph_table, 8, NULL,' ','~','.'},
#endif

#ifdef EN_TEN_DOT
   {2, 12, ten_dot_glyph_table, 9, NULL,' ','~','.'},
#endif

#ifdef EN_FIFTEEN_DOT
   {3, 18, fifteen_dot_glyph_table, 0, fifteen_dot_width_table,' ','~','.'},
#endif

#ifdef EN_EIGHTEEN_DOT
   // {3, 18, eighteen_dot_glyph_table, 0, eighteen_dot_width_table,' ','9','.'},
	{3, 18, eighteen_dot_glyph_table, 0, eighteen_dot_width_table,' ',':','.'},
#endif
 };
 
 //*****************************************************************************
 #ifdef EN_FIVE_DOT
const unsigned char five_dot_glyph_table[]  = 
 { /* ' ' charwidth: 2 */
   0x00,    /*  [  ]  */
   0x00,    /*  [  ]  */
   0x00,    /*  [  ]  */
   0x00,    /*  [  ]  */
   0x00,    /*  [  ]  */
   0x00,    /*  [  ]  */
   0x00,    /*  [  ]  */
	
   /* '!' charwidth: 2 */
   0x00,    /*  [  ]  */
   0x80,    /*  [* ]  */
   0x80,    /*  [* ]  */
   0x80,    /*  [* ]  */
   0x00,    /*  [  ]  */
   0x80,    /*  [* ]  */
   0x00,    /*  [  ]  */
	
   /* '"' charwidth: 4 */
   0x00,    /*  [    ]  */
   0xA0,    /*  [* * ]  */
   0xA0,    /*  [* * ]  */
   0x00,    /*  [    ]  */
   0x00,    /*  [    ]  */
   0x00,    /*  [    ]  */
   0x00,    /*  [    ]  */
	
   /* '#' charwidth: 8 */
   0x00,    /*  [        ]  */
   0x14,    /*  [   * *  ]  */
   0x7E,    /*  [ ****** ]  */
   0x28,    /*  [  * *   ]  */
   0xFC,    /*  [******  ]  */
   0x50,    /*  [ * *    ]  */
   0x00,    /*  [        ]  */
	
   /* '$' charwidth: 4 */
   0x40,    /*  [ *  ]  */
   0x60,    /*  [ ** ]  */
   0x80,    /*  [*   ]  */
   0x40,    /*  [ *  ]  */
   0x20,    /*  [  * ]  */
   0xC0,    /*  [**  ]  */
   0x40,    /*  [ *  ]  */
	
   /* '%' charwidth: 8 */
   0x00,    /*  [        ]  */
   0x64,    /*  [ **  *  ]  */
   0xA8,    /*  [* * *   ]  */
   0xD6,    /*  [** * ** ]  */
   0x2A,    /*  [  * * * ]  */
   0x4C,    /*  [ *  **  ]  */
   0x00,    /*  [        ]  */
	
   /* '&' charwidth: 6 */
   0x00,    /*  [      ]  */
   0x60,    /*  [ **   ]  */
   0x90,    /*  [*  *  ]  */
   0x40,    /*  [ *    ]  */
   0x98,    /*  [*  ** ]  */
   0x60,    /*  [ **   ]  */
   0x00,    /*  [      ]  */
	
   /* ''' charwidth: 2 */
   0x00,    /*  [  ]  */
   0x80,    /*  [* ]  */
   0x80,    /*  [* ]  */
   0x00,    /*  [  ]  */
   0x00,    /*  [  ]  */
   0x00,    /*  [  ]  */
   0x00,    /*  [  ]  */
	
   /* '(' charwidth: 3 */
   0x40,    /*  [ * ]  */
   0x80,    /*  [*  ]  */
   0x80,    /*  [*  ]  */
   0x80,    /*  [*  ]  */
   0x80,    /*  [*  ]  */
   0x80,    /*  [*  ]  */
   0x40,    /*  [ * ]  */
	
   /* ')' charwidth: 3 */
   0x80,    /*  [*  ]  */
   0x40,    /*  [ * ]  */
   0x40,    /*  [ * ]  */
   0x40,    /*  [ * ]  */
   0x40,    /*  [ * ]  */
   0x40,    /*  [ * ]  */
   0x80,    /*  [*  ]  */
	
   /* '*' charwidth: 6 */
   0x00,    /*  [      ]  */
   0x50,    /*  [ * *  ]  */
   0x20,    /*  [  *   ]  */
   0xF8,    /*  [***** ]  */
   0x20,    /*  [  *   ]  */
   0x50,    /*  [ * *  ]  */
   0x00,    /*  [      ]  */
	
   /* '+' charwidth: 6 */
   0x00,    /*  [      ]  */
   0x20,    /*  [  *   ]  */
   0x20,    /*  [  *   ]  */
   0xF8,    /*  [***** ]  */
   0x20,    /*  [  *   ]  */
   0x20,    /*  [  *   ]  */
   0x00,    /*  [      ]  */
	
   /* ',' charwidth: 3 */
   0x00,    /*  [   ]  */
   0x00,    /*  [   ]  */
   0x00,    /*  [   ]  */
   0x00,    /*  [   ]  */
   0x40,    /*  [ * ]  */
   0x40,    /*  [ * ]  */
   0x80,    /*  [*  ]  */
	
   /* '-' charwidth: 4 */
   0x00,    /*  [    ]  */
   0x00,    /*  [    ]  */
   0x00,    /*  [    ]  */
   0xE0,    /*  [*** ]  */
   0x00,    /*  [    ]  */
   0x00,    /*  [    ]  */
   0x00,    /*  [    ]  */
		
   /* '.' charwidth: 2 */
   0x00, 	/*  [  ]  */
   0x00, 	/*  [  ]  */
   0x00, 	/*  [  ]  */
   0x00, 	/*  [  ]  */
   0x00, 	/*  [  ]  */
   0x80, 	/*  [* ]  */
   0x00, 	/*  [  ]  */
   
   /* '/' charwidth: 4 */
   0x20, 	/*  [  * ]  */
   0x20, 	/*  [  * ]  */
   0x40, 	/*  [ *  ]  */
   0x40, 	/*  [ *  ]  */
   0x80, 	/*  [*   ]  */
   0x80, 	/*  [*   ]  */
   0x00, 	/*  [    ]  */
   
   /* '0' charwidth: 5 */
   0x00, 	/*  [     ]  */
   0x60, 	/*  [ **  ]  */
   0x90, 	/*  [*  * ]  */
   0x90, 	/*  [*  * ]  */
   0x90, 	/*  [*  * ]  */
   0x60, 	/*  [ **  ]  */
   0x00, 	/*  [     ]  */
   
   /* '1' charwidth: 3 */
   0x00, 	/*  [   ]  */
   0x40, 	/*  [ * ]  */
   0xC0, 	/*  [** ]  */
   0x40, 	/*  [ * ]  */
   0x40, 	/*  [ * ]  */
   0x40, 	/*  [ * ]  */
   0x00, 	/*  [   ]  */
   
   /* '2' charwidth: 5 */
   0x00, 	/*  [     ]  */
   0x60, 	/*  [ **  ]  */
   0x90, 	/*  [*  * ]  */
   0x20, 	/*  [  *  ]  */
   0x40, 	/*  [ *   ]  */
   0xF0, 	/*  [**** ]  */
   0x00, 	/*  [     ]  */
   
   /* '3' charwidth: 5 */
   0x00, 	/*  [     ]  */
   0x60, 	/*  [ **  ]  */
   0x90, 	/*  [*  * ]  */
   0x20, 	/*  [  *  ]  */
   0x90, 	/*  [*  * ]  */
   0x60, 	/*  [ **  ]  */
   0x00,    /*  [     ]  */
   
   /* '4' charwidth: 5 */
   0x00, 	/*  [     ]  */
   0x20, 	/*  [  *  ]  */
   0x60, 	/*  [ **  ]  */
   0xA0, 	/*  [* *  ]  */
   0xF0, 	/*  [**** ]  */
   0x20, 	/*  [  *  ]  */
   0x00, 	/*  [     ]  */
   
   /* '5' charwidth: 4 */
   0x00, 	/*  [    ]  */
   0xE0, 	/*  [*** ]  */
   0x80, 	/*  [*   ]  */
   0xE0, 	/*  [*** ]  */
   0x20, 	/*  [  * ]  */
   0xC0, 	/*  [**  ]  */
   0x00, 	/*  [    ]  */
   
   /* '6' charwidth: 5 */
   0x00, 	/*  [     ]  */
   0x20, 	/*  [  *  ]  */
   0x40, 	/*  [ *   ]  */
   0xE0, 	/*  [***  ]  */
   0x90, 	/*  [*  * ]  */
   0x60, 	/*  [ **  ]  */
   0x00, 	/*  [     ]  */
   
   /* '7' charwidth: 4 */
   0x00, 	/*  [    ]  */
   0xE0, 	/*  [*** ]  */
   0x20, 	/*  [  * ]  */
   0x40, 	/*  [ *  ]  */
   0x40, 	/*  [ *  ]  */
   0x40, 	/*  [ *  ]  */
   0x00, 	/*  [    ]  */
   
   /* '8' charwidth: 5 */
   0x00, 	/*  [     ]  */
   0x60, 	/*  [ **  ]  */
   0x90, 	/*  [*  * ]  */
   0x60, 	/*  [ **  ]  */
   0x90, 	/*  [*  * ]  */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -