📄 lcd6963.c
字号:
bit_pos = left & 0x07; /* get starting bit offset into byte */
byte_offset = left >> 3; /* get byte offset into y direction */
x_bits = (right - left) + 1; /* get length in the x 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 */
while(x_bits) /* while there are still bits to write */
{
if((remaining_bits == 8) && (x_bits > 7))
{
/* here if we are byte aligned and have at least 1 byte to write */
/* do the entire byte at once instead of bit by bit */
while(x_bits > 7) /* while there are at least 8 more bits to do */
{
l_display_array[row][byte_offset] = 0xFF;
byte_offset++;
x_bits -= 8;
}
}
else
{
/* we are not byte aligned or an entire byte does not need written */
/* do each individual bit */
l_display_array[row][byte_offset] |= mask;
if(l_mask_array[0] & 0x80)
{
mask >>= 1;
}
else
{
mask <<= 1;
}
x_bits--;
remaining_bits--;
if(remaining_bits == 0)
{
/* might have bust gotton byte aligned */
/* so reset for beginning of a byte */
remaining_bits = 8;
byte_offset++;
mask = l_mask_array[0];
}
}
}
}
/*
**
** Draws a vertical line into display memory starting at the top
** going to the bottom in the given column. No runtime error checking
** is performed. It is assumed that top is less than bottom and that
** the column is in range.
**
*/
void lcd_vert_line(unsigned char top, unsigned char bottom,
unsigned char column)
{
unsigned char bit_pos;
unsigned char byte_offset;
unsigned char mask;
unsigned char row;
bit_pos = column & 0x07; /* get the bit offset into a byte */
byte_offset = column >> 3; /* get the byte offset into x array */
mask = l_mask_array[bit_pos]; /* get the mask for this bit */
for(row = top; row <= bottom; row++)
{
l_display_array[row][byte_offset] |= mask;
}
}
/*
**
** Clears a line into the display memory starting at left going to
** right, on the given row. No runtime error checking is performed.
** It is assumed that left is less than right.
**
*/
void lcd_clr_horz_line(unsigned char left, unsigned char right,
unsigned char row)
{
unsigned char bit_pos;
unsigned char byte_offset;
unsigned char x_bits;
unsigned char remaining_bits;
unsigned char mask;
bit_pos = left & 0x07; /* get starting bit offset into byte */
byte_offset = left >> 3; /* get byte offset into x direction */
x_bits = (right - left) + 1; /* get length in the x 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 */
while(x_bits) /* while there are still bits to write */
{
if((remaining_bits == 8) && (x_bits > 7))
{
/* here if we are byte aligned and have at least 1 byte to write */
/* do the entire byte at once instead of bit by bit */
while(x_bits > 7) /* while there are at least 8 more bits to do */
{
l_display_array[row][byte_offset] = 0x00;
byte_offset++;
x_bits -= 8;
}
}
else
{
/* we are not byte aligned or an entire byte does not need written */
/* do each individual bit */
l_display_array[row][byte_offset] &= ~mask;
if(l_mask_array[0] & 0x80)
{
mask >>= 1;
}
else
{
mask <<= 1;
}
x_bits--;
remaining_bits--;
if(remaining_bits == 0)
{
/* might have bust gotton byte aligned */
/* so reset for beginning of a byte */
remaining_bits = 8;
byte_offset++;
mask = l_mask_array[0];
}
}
}
}
/*
**
** Clears a vertical line into display memory starting at the top
** going to the bottom in the given column. No runtime error checking
** is performed. It is assumed that top is less than bottom and that
** the column is in range.
**
*/
void lcd_clr_vert_line(unsigned char top, unsigned char bottom,
unsigned char column)
{
unsigned char bit_pos;
unsigned char byte_offset;
unsigned char mask;
unsigned char row;
bit_pos = column & 0x07; /* get the bit offset into a byte */
byte_offset = column >> 3; /* get the byte offset into x array */
mask = l_mask_array[bit_pos]; /* get the mask for this bit */
for(row = top; row <= bottom; row++)
{
l_display_array[row][byte_offset] &= ~mask;
}
}
/*
**
** Draws a box in display memory starting at the left/top and going
** to the right/bottom. No runtime error checking is performed.
** It is assumed that left is less than right and that top is less
** than bottom.
**
*/
void lcd_box(unsigned char left, unsigned char top,
unsigned char right, unsigned char bottom)
{
/* to draw a box requires two vertical lines */
lcd_vert_line(top,bottom,left);
lcd_vert_line(top,bottom,right);
/* and two horizonal lines */
lcd_horz_line(left,right,top);
lcd_horz_line(left,right,bottom);
}
/*
**
** Clears a box in display memory starting at the Top left and going
** to the bottom right. No runtime error checking is performed and
** it is assumed that Left is less than Right and that Top is less
** than Bottom.
**
*/
void lcd_clr_box(unsigned char left, unsigned char top,
unsigned char right, unsigned char bottom)
{
/* to undraw the box undraw the two vertical lines */
lcd_clr_vert_line(top,bottom,left);
lcd_clr_vert_line(top,bottom,right);
/* and the two horizonal lines that comprise it */
lcd_clr_horz_line(left,right,top);
lcd_clr_horz_line(left,right,bottom);
}
/*
**
** Writes a glyph to the display at location x,y
**
** Arguments are:
** column - x corrdinate of the left part of glyph
** row - y coordinate of the top part of glyph
** width - size in pixels of the width of the glyph
** height - size in pixels of the height of the glyph
** glyph - an unsigned char pointer to the glyph pixels
** to write assumed to be of length "width"
**
*/
void lcd_glyph(unsigned char left, unsigned char top,
unsigned char width, unsigned char height,
unsigned char *glyph, unsigned char store_width)
{
unsigned char bit_pos;
unsigned char byte_offset;
unsigned char x_bits;
unsigned char remaining_bits;
unsigned char mask;
unsigned char char_mask;
unsigned char y;
unsigned char *glyph_scan;
unsigned char glyph_offset;
bit_pos = left & 0x07; /* get the bit offset into a byte */
glyph_offset = 0; /* start at top of the glyph rasters */
for (y = top; y < (top + height); y++)
{
byte_offset = left >> 3; /* get the byte offset into x direction */
x_bits = width; /* 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 + glyph_offset; /* point to start of glyph raster */
char_mask = 0x80; /* initial character glyph mask */
/* boundary checking here to account for the possibility of */
/* write past the right of the screen. */
while((x_bits) && (byte_offset < X_BYTES)) /* while there are bits still to write */
{
/* check if the character pixel is set or not */
if(*glyph_scan & char_mask)
{
l_display_array[y][byte_offset] |= mask; /* set image pixel */
}
else
{
l_display_array[y][byte_offset] &= ~mask; /* clear the image pixel */
}
if(l_mask_array[0] & 0x80)
{
mask >>= 1;
}
else
{
mask <<= 1;
}
x_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];
}
/* shift over to next glyph bit */
char_mask >>= 1;
if(char_mask == 0) /* reset for next byte in raster */
{
char_mask = 0x80;
glyph_scan++;
}
}
/* bump the offset to next raster */
glyph_offset += store_width;
}
}
/*
**
** 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 and non 0x20->0x7e characters are ignored.
**
** Arguments are:
** left coordinate of left start of string.
** top coordinate of top of string.
** font font number to use for display
** str text string to display
**
*/
void lcd_text(unsigned char left, unsigned char top, unsigned char font, char *str)
{
unsigned char x = left;
unsigned char glyph;
unsigned char width;
unsigned char height;
unsigned char store_width;
unsigned char *glyph_ptr;
while(*str != 0x00)
{
glyph = (unsigned char)*str;
/* check to make sure the symbol is a legal one */
/* if not then just replace it with the default character */
if((glyph < fonts[font].glyph_beg) || (glyph > fonts[font].glyph_end))
{
glyph = fonts[font].glyph_def;
}
/* make zero based index into the font data arrays */
glyph -= fonts[font].glyph_beg;
width = fonts[font].fixed_width; /* check if it is a fixed width */
if(width == 0)
{
width=fonts[font].width_table[glyph]; /* get the variable width instead */
}
height = fonts[font].glyph_height;
store_width = fonts[font].store_width;
glyph_ptr = fonts[font].glyph_table + (((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 */
}
//
//lcd_update(SCRN_TOP,SCRN_BOTTOM);
}
/*
**
** Updates area of the display. Writes data from display
** RAM to the lcd display controller.
**
** Arguments Used:
** top top line of area to update.
** bottom bottom line of area to update.
**
*/
void lcd_update(unsigned char top, unsigned char bottom)
{
unsigned char x;
unsigned char y;
unsigned char dat;
unsigned char *colptr;
for(y = top; y <= bottom; y++)
{
/* set addr ptr to start of line */
lcd_cmd_2(0x24,y*30); /* scan the display up top to bottom */
lcd_cmd(0xB0); /* send the auto write command */
colptr = &l_display_array[y][0]; /* point to row of data in buffer */
for (x=0; x < X_BYTES; x++)
{
do
{
dat=lcd_in_sta();
}
while((dat & 0x08) != 0x08); /* wait till STA3=1 */
lcd_out_dat(*colptr++);
}
do /* poll loop for ready for auto reset command */
{
dat=lcd_in_sta();
}
while((dat & 0x08) != 0x08); /* wait till STA2=1 */
lcd_out_ctl(0xB2); /* send the auto reset command */
}
}
void lcd_part_update(unsigned char top, unsigned char bottom,unsigned char left, unsigned char right)
{
unsigned char x;
unsigned char y;
unsigned char dat;
unsigned char *colptr;
for(y = top; y <= bottom; y++)
{
/* set addr ptr to start of line */
lcd_cmd_2(0x24,y*30+left); /* scan the display up top to bottom */
lcd_cmd(0xB0); /* send the auto write command */
colptr = &l_display_array[y][left]; /* point to row of data in buffer */
for (x=left; x < right; x++)
{
do
{
dat=lcd_in_sta();
}
while((dat & 0x08) != 0x08); /* wait till STA3=1 */
lcd_out_dat(*colptr++);
}
do /* poll loop for ready for auto reset command */
{
dat=lcd_in_sta();
}
while((dat & 0x08) != 0x08); /* wait till STA2=1 */
lcd_out_ctl(0xB2); /* send the auto reset command */
}
}
void lcd_byte_update(unsigned char top, unsigned char bottom,unsigned char left)
{
unsigned char x;
unsigned char y;
unsigned char dat;
unsigned char colptr;
for(y = top; y <= bottom; y++)
{
/* set addr ptr to start of line */
lcd_cmd_2(0x24,y*30+left); /* scan the display up top to bottom */
lcd_cmd(0xB0); /* send the auto write command */
colptr = l_display_array[y][left]; /* point to row of data in buffer */
for (x=0; x < 8; x++)
{
do
{
dat=lcd_in_sta();
}
while((dat & 0x08) != 0x08); /* wait till STA3=1 */
lcd_cmd_1(0xc0,colptr);
}
do /* poll loop for ready for auto reset command */
{
dat=lcd_in_sta();
}
while((dat & 0x08) != 0x08); /* wait till STA2=1 */
lcd_out_ctl(0xB2); /* send the auto reset command */
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -