单片机控制诺基亚2600彩屏(六)
0赞
Step 6Drawing Rectangles


Rectangles are incredibly useful. You can draw one big rectangle to clear the screen, use them for menu elements, indicators, check boxes, frames, text backgrounds, and much more. Thankfully they are easy to draw on the Nokia LCD's. All you need to do is define a region the size of the rectangle and fill it in with a solid color. The following AVR C code (using the functions described in the last section) will do this.
void color_lcd_draw_rectangle(int color, unsigned char xs, unsigned char ys, unsigned char xe, unsigned char ye)
{
color_lcd_send_cmd(PASET);
color_lcd_send_data(ys);
color_lcd_send_data(ye);
color_lcd_send_cmd(CASET);
color_lcd_send_data(xs);
color_lcd_send_data(xe);
color_lcd_send_cmd(RAMWR);
unsigned int half_rect_area = (((unsigned int)(xe-xs+1)*(ye-ys+1))/2);
for(unsigned int i = 0; i < half_rect_area; i++)
{
color_lcd_send_data(color>>4);
color_lcd_send_data(((color&0x0F)<<4)|(color>>8));
color_lcd_send_data(color);
}
}
It starts out by defining the region using CASET and PASET, initiates a RAM write, and then fills the region with a solid color. Since the three send_data lines actually fill 2 pixels instead of 1, the for loop only has to count to half the rectangle area.
