代码很简单啊,网上有demo程序你们下载做模板,将lcd驱动修改成自己的就行,以下是我的代码。
#define pai 3.14159256
const GUI_POINT SecondArrowPoint[]=//秒指针
{
0,-2,
90,-2,
92,-4,
100,0,
92,4,
90,2,
0,2,
};
const GUI_POINT MiniteArrowPoint[]=//分指针
{
0,-4,
70,-4,
72,-6,
80,0,
72,6,
70,4,
0,4,
};
const GUI_POINT HourArrowPoint[]=//时指针
{
0,-6,
50,-6,
52,-8,
60,0,
52,8,
50,6,
0,6,
};
const GUI_COLOR ColorArray[]=//12种颜色填充各个圆弧
{
GUI_BLUE,
GUI_GREEN,
GUI_RED,
GUI_CYAN,
GUI_MAGENTA,
GUI_YELLOW,
GUI_LIGHTBLUE,
GUI_LIGHTGREEN,
GUI_LIGHTRED,
GUI_LIGHTCYAN,
GUI_DARKBLUE,
GUI_DARKMAGENTA
};
GUI_POINT aRotatePoint[7];//存放旋转后的指针坐标
struct
{
u8 Hour;
u8 Minite;
u8 Second;
}time;
void DispTime()
{
//将时指针旋转
GUI_RotatePolygon(aRotatePoint,HourArrowPoint,7,
(90-time.Hour*30-30*time.Minite/60)*pai/180);
//显示时时钟
GUI_FillPolygon(aRotatePoint,7,160,120);
GUI_RotatePolygon(aRotatePoint,MiniteArrowPoint,7,(90-time.Minite*6)*pai/180);
GUI_FillPolygon(aRotatePoint,7,160,120);
GUI_RotatePolygon(aRotatePoint,SecondArrowPoint,7,(90-time.Second*6)*pai/180);
GUI_FillPolygon(aRotatePoint,7,160,120);
}
int main(void)
{
char i;
u32 ii;
CPU_IntDis();
BSP_Init();
GUI_Init();
GUI_SetBkColor(GUI_GRAY);
GUI_SetPenSize(10);
GUI_SetColor(GUI_DARKGREEN);
GUI_Clear(); //清屏
GUI_FillEllipse(160,120,150,110);//画黑绿色椭圆
for(i=0;i<12;i++) //画12道圆弧
{
GUI_SetColor(ColorArray[i]);
GUI_DrawArc(160,120,105,105,30*i,30*(i+1));
}
time.Hour = 10; //改当前时间
time.Minite = 36;
time.Second = 0;
while(1)
{
GUI_SetColor(GUI_BLACK); //换成黑色
GUI_FillCircle(160,120,10); //画中间原点
DispTime(); //画指针
for(ii=0;ii<11990000;ii++); //大约1秒
GUI_SetColor(GUI_DARKGREEN); //换成绿黑色
DispTime(); //画绿黑色指针,因为跟底色一样,故有擦除功能
time.Second++;
if(time.Second>59)
{
time.Second=0;
time.Minite++;
if(time.Minite>59)
{
time.Minite=0;
time.Hour++;
if(time.Hour>11)
time.Hour=0;
}
}
}
} |