When drawing a straight line, due to the granularity of the display on the LCD, the problem of the pace of the x and y axes is distinguished. The problem of pace involves the problem of slope. Therefore, even if the line drawing algorithm is completed, it is necessary to pay attention to the direction of the x and y axes relative to the LCD. Now a relatively rough line drawing algorithm is implemented.
void lcd_line(u16 x1,u16 y1,u16 x2,u16 y2,u16 Color)
{
u16 temp,x,y;
Set_direction(0);
if((x1 == x2) && (y1 == y2))
{
//Draw the origin
LCD_open_windows(x1,y1,1,1);
}
else if(abs(y1-y2)>abs(x1-x2))
{
//Move along the y axis, determine the size and swap
if(y1 > y2)
{
x1 ^= x2 ^= x1 ^= x2;
y1 ^= y2 ^= y1 ^= y2;
}
for( y = y1 ; y <= y2 ; y ++ )
{
x = x1 + (y - y1) * (x2 - x1) / (y2 - y1);
LCD_ColorPoint(x ,y ,Color);
}
}
else
{
if(x1 > x2)
{
x1 ^= x2 ^= x1 ^= x2;
y1 ^= y2 ^= y1 ^= y2;
}
for( x = x1 ; x <= x2 ; x ++ )
{
y = y1 + (x - x1) * (y2 - y1) / (x2 - x1);
LCD_ColorPoint(x ,y ,Color);
}
}
}
The main thing is to pay attention to the slope problem and understand the properties of LCD. The slope is greater than 1. You must know that only by moving along the y-axis can the x-axis be dense without an obvious breakpoint.
2. Write in ascii.
To write ASCII, you can first make a font, take the corresponding font, such as 8 * 16. Since the principle of writing ASCII on LCD is mainly to dot, you can write a simple program for A.
unsigned char code_A[]=
{
/*------------------------------------------------ ----------------------------------
; If the data is garbled, please check the font format settings and pay attention to selecting the correct modulus direction and byte order.
; Source file / text: A
; Width × height (pixels): 8×16
; Font format/size: monochrome dot matrix LCD font, horizontal mode, byte positive order/16 bytes
; Data conversion date: 2015/2/10 15:00:31
-------------------------------------------------- ----------------------------*/
//0x08,0x10,0x01, //Number of pixels in width, number of pixels in height, number of bytes in width, parameter settings are optional
0x00,0x00,0x00,0x08,0x08,0x0C,0x14,0x14,0x12,0x1E,0x22,0x21,0x21,0x73,0x00,0x00,
};
//8 * 16 ascii characters
void lcd_ascii(u16 x,u16 y,const u8 *str,u16 Color)
{
u8 i , j;
u8 temp;
for (i = 0;i < 16; i++)
{
temp = str[i];
for(j = 0 ; j < 8 ; j ++)
{
if((temp >> (7 - j) ) & 0x01 == 0x01)
{
LCD_ColorPoint(x + (j) ,y + i,Color);
}
}
}
}
The main principle is to get the value of each bit to be displayed, and if it is 1, just write the corresponding value.
unsigned char code_A_24x48[]=
{
/*------------------------------------------------ ----------------------------------
; If the data is garbled, please check the font format settings and pay attention to selecting the correct modulus direction and byte order.
; Source file / text: A
; Width × height (pixels): 24×48
; Font format/size: monochrome dot matrix LCD font, horizontal mode, byte sequence/144 bytes
; Data conversion date: 2015/2/10 15:09:19
-------------------------------------------------- ----------------------------*/
//0x18,0x30,0x03, //Number of pixels in width, number of pixels in height, number of bytes in width, parameter settings are optional
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x38,0x00,0x00,0x3C,0x00,0x00,0x7C,
0x00,0x00,0x7C,0x00,0x00,0x7C,0x00,0x00,0x6C,0x00,0x00,0xCE,0x00,0x00,0xCE,0x00,
0x00,0xCE,0x00,0x00,0xC6,0x00,0x01,0x87,0x00,0x01,0x87,0x00,0x01,0x87,0x00,0x01,
0x83,0x00,0x03,0x03,0x80,0x03,0x03,0x80,0x03,0x03,0x80,0x03,0x03,0x80,0x06,0x01,
0xC0,0x07,0xFF,0xC0,0x06,0x01,0xC0,0x06,0x01,0xC0,0x0C,0x01,0xE0,0x0C,0x00,0xE0,
0x0C,0x00,0xE0,0x0C,0x00,0xE0,0x18,0x00,0xF0,0x18,0x00,0x70,0x18,0x00,0x70,0x18,
0x00,0x70,0x38,0x00,0x78,0xFE,0x01,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
void lcd_ascii_24x48(u16 x,u16 y,const u8 *str,u16 Color)
{
u8 i,j,k;
u8 buffer[3];
for (i = 0;i < 48; i++)
{
for(j = 0; j < 3 ; j ++)
{
buffer[j] = str[i * 3 + j];
}
for( j = 0; j < 3 ; j ++)
{
for (k = 0 ; k < 8 ; k++)
{
if( ( buffer[j] >> (7 - k)) & 0x01 == 0x01)
{
LCD_ColorPoint(x + 8 * (j) + k,y + i,Color);
}
}
}
}
}
3. Write Chinese characters
unsigned char yuan[]=
{
/*------------------------------------------------ ----------------------------------
; If the data is garbled, please check the font format settings and pay attention to selecting the correct modulus direction and byte order.
; Source file / text: Yuan
; Width × height (pixels): 48 × 48
; Font format/size: monochrome dot matrix LCD font, horizontal mode, byte positive sequence/288 bytes
; Data conversion date: 2015/2/10 13:17:47
-------------------------------------------------- ----------------------------*/
//0x30,0x30,0x06, //Number of pixels in width, number of pixels in height, number of bytes in width, parameter settings are optional
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,
0x00,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,
0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0xC0,0x0C,0x00,0x00,0x00,0x00,0xC0,0x1E,0x00,
0x00,0x1F,0xFF,0xFF,0xFF,0x00,0x00,0x08,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0xC0,
0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x40,0x00,0x00,
0x00,0xC0,0x00,0xE0,0x07,0xFF,0xFF,0xFF,0xFF,0xF0,0x03,0xFF,0xFF,0xFF,0xFF,0xF8,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x10,0x00,0x00,0x06,0x00,0x00,
0x3C,0x00,0x00,0x07,0xFF,0xFF,0xFC,0x00,0x00,0x07,0x00,0x00,0x38,0x00,0x00,0x07,
0x00,0x00,0x38,0x00,0x00,0x07,0x00,0x00,0x38,0x00,0x00,0x07,0x00,0x00,0x38,0x00,
0x00,0x07,0x00,0x00,0x38,0x00,0x00,0x07,0x00,0x00,0x38,0x00,0x00,0x07,0xFF,0xFF,
0xF8,0x00,0x00,0x07,0xFF,0xFF,0xF8,0x00,0x00,0x07,0x0F,0x10,0x31,0x80,0x00,0x04,
0x1E,0x18,0x03,0xC0,0x00,0x00,0x3C,0x08,0x07,0xE0,0x00,0x00,0x78,0x0C,0x0F,0x00,
0x00,0x00,0xF8,0x06,0x1C,0x00,0x00,0x01,0xF8,0x07,0x70,0x00,0x00,0x07,0xB8,0x03,
0xC0,0x00,0x00,0x0E,0x38,0x01,0xC0,0x00,0x00,0x1C,0x38,0x00,0xE0,0x00,0x00,0x70,
0x38,0x00,0x70,0x00,0x01,0xC0,0x38,0x10,0x7C,0x00,0x03,0x00,0x38,0xE0,0x3F,0x00,
0x0C,0x00,0x3B,0xC0,0x0F,0xE0,0x10,0x00,0x3F,0x00,0x07,0xFC,0x00,0x00,0x7E,0x00,
0x03,0xF0,0x00,0x00,0x38,0x00,0x00,0xE0,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
//lcd displays 48 * 48 characters
void lcd_show_48x48(u16 x,u16 y,const u8 *str,u16 Color)
{
u8 i,j,k;
u8 buffer[6];
for (i = 0;i < 48; i++)
{
for(j = 0; j < 6 ; j ++)
{
buffer[j] = str[i * 6 + j];
}
for( j = 0; j < 6 ; j ++)
{
for (k = 0 ; k < 8 ; k++)
{
if( ( buffer[j] >> 7 - k) & 0x01 == 0x01)
{
LCD_ColorPoint(x + 8 * (j) + k,y + i,Color);
}
}
}
}
}
Previous article:stm32 control DS1302
Next article:IAP learning of stm32
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- EEWORLD University ---- Wildfire FPGA Video Tutorial
- 【Node.js for Embedded Systems】Electronic version
- Very detailed introductory article FPGA_SOPC_starter
- Start a new ultra-wideband experience and discuss solutions to support chip interoperability
- 【Contactless facial recognition access control system】+ 3-Arduino Bluetooth BLE library
- 24V to 16V circuit problem
- The problem of the propagation speed of electric pulses in wires
- About 15.4stack coordinator mode modification
- Newbie Help
- What is 802.11ay?