使用的是ALIENTEK LCD2.8寸屏。看图,在红 {MOD}的上出现了很多蓝 {MOD}背景小点,人太笨,c一点不会,看了几遍原子哥的视频,都是懵懵懂懂,后来我就直接模仿直接写了,现在出现了一个问题,我想做一个圆形的指针钟,画外形的时候我我画了5个圆心一样,半径逐次加1的圆,但是在圆上面出现了很多蓝 {MOD}背景的点。 问题:
①、我认为的问题是我这样画圆并不是每一个点都画到了,所以出现了这种情况,不过我不确定我说的对不对我在想可不可以修改画圆函数,让线变粗,如果可以,能否提示下,多谢了。
②、有没有好的办法画钟的刻度?我像我这样画也可以慢慢调可以画好,但是就是太慢了,有没有快的方法画刻度。如果可以,是否能告知,多谢了。
代码:
画圆函数:
void LCD_Draw_Circle(u16 x0,u16 y0,u8 r)
{
int a,b;
int di;
a=0;b=r;
di=3-(r<<1);
while(a<=b)
{
LCD_DrawPoint(x0+a,y0-b); //5
LCD_DrawPoint(x0+b,y0-a); //0
LCD_DrawPoint(x0+b,y0+a); //4
LCD_DrawPoint(x0+a,y0+b); //6
LCD_DrawPoint(x0-a,y0+b); //1
LCD_DrawPoint(x0-b,y0+a);
LCD_DrawPoint(x0-a,y0-b); //2
LCD_DrawPoint(x0-b,y0-a); //7
a++;//使用Bresenham算法画圆
if(di<0)di +=4*a+6;
else
{
di+=10+4*(a-b);
b--;
}
}
}
main函数:
#include "stm32f10x.h"
#include "led.h"
#include "delay.h"
#include "lcd.h"
#include "usart.h"
void init();
int main(void)
{
u8 lcd_id[12];
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
uart_init(115200);
LED_Init();
LCD_Init(); //
POINT_COLOR=RED;
sprintf((char*)lcd_id,"LCD ID:%04X",lcddev.id);
init();
while(1)
{
GPIO_SetBits(GPIOB,GPIO_Pin_5);
GPIO_SetBits(GPIOE,GPIO_Pin_5);
delay_ms(500);
GPIO_ResetBits(GPIOB,GPIO_Pin_5);
GPIO_ResetBits(GPIOE,GPIO_Pin_5);
delay_ms(500);
}
}
void init()
{
LCD_Clear(BLUE);
POINT_COLOR=RED;
LCD_Draw_Circle(120,80,75);
LCD_Draw_Circle(120,80,76);
LCD_Draw_Circle(120,80,77);
LCD_Draw_Circle(120,80,78);
LCD_Draw_Circle(120,80,79);
LCD_Draw_Circle(120,80,2);
LCD_DrawLine(119,80,119,38);
LCD_DrawLine(120,80,120,38);
LCD_DrawLine(121,80,121,38);
LCD_DrawLine(120,79,155,79);
LCD_DrawLine(120,80,155,80);
LCD_DrawLine(120,81,155,81);
LCD_DrawLine(119,1,119,15);
LCD_DrawLine(120,1,120,15);
LCD_DrawLine(121,1,121,15);
LCD_ShowNum(114,18,12,2,16);
LCD_DrawLine(119,155,119,145);
LCD_DrawLine(120,155,120,145);
LCD_DrawLine(121,155,121,145);
LCD_ShowNum(117,128,6,1,16);
LCD_DrawLine(42,79,55,79);
LCD_DrawLine(42,80,55,80);
LCD_DrawLine(42,81,55,81);
LCD_ShowNum(58,72,9,1,16);
LCD_DrawLine(198,79,185,79);
LCD_DrawLine(198,80,185,80);
LCD_DrawLine(198,81,185,81);
LCD_ShowNum(175,72,3,1,16);
LCD_DrawLine(150,12,145,20);
LCD_DrawLine(151,13,146,21);
LCD_DrawLine(152,14,147,22);
}
一周热门 更多>