0.png (51.17 KB, 下載次數(shù): 129)
下載附件
2017-4-20 01:40 上傳
全部源碼下載:
彩屏?xí)r鐘.zip
(79.04 KB, 下載次數(shù): 27)
2017-4-19 10:53 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
單片機源程序:
- #include<reg52.h>
- #include"NBCTFT.h"
- #include"math.h"
- unsigned int Device_code;
- extern uchar Mark;
- uint *p1,*p2;
- uint dd;
- uint count;
- uint S[10],H[10],H1[60],S1[60],H2[60],S2[60];
- uint j=0,m=0;
- void timer0(void)
- {
- TH1=0xFC;
- TL1=0x17;
- TMOD=0x10;
- ET1=1;
- EA=1;
- TR1=1;
- }
- void HZ_init(uint dat1,uint dat2,uchar *p)// 16*16漢字 從低位到高位
- {
- unsigned int i,j;
- unsigned int temp;
- unsigned int x,y;//
- x=dat1;
- y=dat2;
- for(i=0;i<32;i++)
- {
- temp=*(p++);//
- if((i%2==0)&&(i!=0))//
- {
- y++;//
- }
- for(j=0;j<8;j++)//
- {
- if(temp&0x01==1)//
- {
- Put_pixel(x,y,0xFFFF);//
- }
- else
- {
- Put_pixel(x,y,0xFFFF);//
- }
- temp>>=1;//
- if(x==(dat1+16))//
- {
- x=dat1;
- }
- if(y==(dat2+16))
- {
- y=dat2;
- }
- }
- }
- }
- void DispCharAt(uint x,uint y,uchar *S)//8*16字符 從低位到高位
- {
- uint temp,i,j,dat;
- dat=x;
- for(i=0;i<16;i++)
- {
- y++;
- temp=*S++;
- for(j=0;j<8;j++)
- {
- if(temp&(1<<0))
- {
- Put_pixel(x++,y,0xFFFF);
- }
- else
- {
- Put_pixel(x++,y,0xFFFF);
- }
- }
- x=dat;
- }
- }
- void Fill_Rect(uint x1,uint y1,uint x2,uint y2,uint color)//填充一個矩形
- {
- uint DX,DY,i,j,temp,dat;
- DX=x2-x1;
- DY=y2-y1;
- if(DX<0)
- {
- dat=x1;
- x2=x1;
- x1=x2;
- }
- temp=x1;
- if(DY<0)
- {
- dat=y1;
- y2=y1;
- y1=dat;
- }
- DX=abs(DX);
- DY=abs(DY);
- for(i=0;i<DY;i++)
- {
- y1++;
- for(j=0;j<DX;j++)
- {
- Put_pixel(x1++,y1,color);
- }
- x1=temp;
- }
- }
- void Draw_Line(uint x1,uint y1,uint x2,uint y2,uint color)
- {
- unsigned int i,Flag,temp,x,y;
- int DX,DY;
- int s1,s2,e;
- DX=x2-x1;
- DY=y2-y1;
- x=x1;
- y=y1;
- if(x2<x1)
- {
- s1=-1;
- }
- else
- {
- s1=1;
- }
- if(y2<y1)
- {
- s2=-1;
- }
- else
- {
- s2=1;
- }
- if(DX<0)
- {
- DX=-DX;
- }
- if(DY<0)
- {
- DY=-DY;
- }
- if(DX<DY)
- {
- temp=x1;
- x1=x2;
- x2=temp;
-
- temp=y1;
- y1=y2;
- y2=temp;
-
- temp=DX;
- DX=DY;
- DY=temp;
- Flag=0;
- }
- else
- {
- Flag=1;
- }
- e=2*DY-DX;
- for(i=0;i<DX;i++)
- {
- *p1=x;
- *p2=y;
- p1++;
- P2++;
- Put_pixel(x,y,color);
- if(e>=0)
- {
- if(Flag==1)
- {
- y+=s2;
- }
- else
- {
- x+=s1;
- }
- e=e-2*DX;
- }
- if(Flag==1)
- {
- x+=s1;
- }
- else
- {
- y+=s2;
- }
- e=e+2*DY;
- }
-
- }
- void Point(uint x0,uint y0,int x,int y,uint color)
- {
- Put_pixel(x0+x,y0+y,color);
- Put_pixel(x0-x,y0+y,color);
- Put_pixel(x0+x,y0-y,color);
- Put_pixel(x0-x,y0-y,color);
- Put_pixel(x0+y,y0+x,color);
- Put_pixel(x0-y,y0+x,color);
- Put_pixel(x0+y,y0-x,color);
- Put_pixel(x0-y,y0-x,color);
- }
- void Draw_Circle(uint x0,uint y0,uint r)
- {
- int x,y;
- float d;
- x=0;
- y=r;
- d=(5.0/4.0)-r;
- while(x<=y)
- {
- Point(x0,y0,x,y,0xF81F);
- if(d<0)
- {
- d+=x*2.0+3.0;
- }
- else
- {
- d+=2.0*(x-y)+5.0;
- y--;
- }
- x++;
-
- }
- }
- void Draw_Section(uint x0,uint y0,uint r)
- {
- int x,y,j=0,i=0;
- float d;
- x=0;
- y=r;
- d=(5.0/4.0)-r;
- while(x<=y)
- {
- if(x%8==0)
- {
- S[j++]=y;
- H[i++]=x;
- Point(x0,y0,x,y,0xFFFF);
- }
- if(d<0)
- {
- d+=x*2.0+3.0;
- }
- else
- {
- d+=2.0*(x-y)+5.0;
- y--;
- }
- x++;
-
- }
- }
- void main(void)//新的分針會被秒針給描掉
- {
- uint i;
- timer0();
- Device_code=0x9328;
- TFT_Initial();
- CLR_Screen(0x0000);
- Draw_Circle(120,160,110);
- Point(120,160,80,46,0xF81F);
- Put_pixel(120,65,0xF81F);
- Put_pixel(215,160,0xF81F);
- Put_pixel(120,255,0xF81F);
- Put_pixel(25,160,0xF81F);
- Draw_Section(120,160,80);
- for(i=0;i<8;i++)//第一象限前部分
- {
- H1[j]=120+H[i];
- S1[j]=160-S[i];
- H2[j]=120+H[i]/2;
- S2[j]=160-S[i]/2;
- j++;
- }
- for(i=7;i>0;i--)//第一象限后部分
- {
- H1[j]=120+S[i];
- S1[j]=160-H[i];
- H2[j]=120+S[i]/2;
- S2[j]=160-H[i]/2;
- j++;
- }
- for(i=0;i<8;i++)//第二項限前部分
- {
- H1[j]=120+S[i];
- S1[j]=160+H[i];
- H2[j]=120+S[i]/2;
- S2[j]=160+H[i]/2;
- j++;
- }
- for(i=7;i>0;i--)//第二項限后部分
- {
- H1[j]=120+H[i];
- S1[j]=160+S[i];
- H2[j]=120+H[i]/2;
- S2[j]=160+S[i]/2;
- j++;
- }
- for(i=0;i<8;i++)//第三項限前部分
- {
- H1[j]=120-H[i];
- S1[j]=160+S[i];
- H2[j]=120-H[i]/2;
- S2[j]=160+S[i]/2;
- j++;
- }
- for(i=7;i>0;i--)//第三項限后部分
- {
- H1[j]=120-S[i];
- S1[j]=160+H[i];
- H2[j]=120-S[i]/2;
- S2[j]=160+H[i]/2;
- j++;
- }
- for(i=0;i<8;i++)//第四項限前部分
- {
- H1[j]=120-S[i];
- S1[j]=160-H[i];
- H2[j]=120-S[i]/2;
- S2[j]=160-H[i]/2;
- j++;
- }
- for(i=7;i>0;i--)//第四項限后部分
- {
- H1[j]=120-H[i];
- S1[j]=160-S[i];
- H2[j]=120-H[i]/2;
- S2[j]=160-S[i]/2;
- j++;
- }
- j=0;
- while(1)
- {
-
-
- if(m>=1)
- {
- Draw_Line(120,160,H1[59],S1[59],0x0000);
- Draw_Line(120,160,H2[m-1],S2[m-1],0x0000);
- }
- if(j>=1)
- {
- Draw_Line(120,160,H1[j-1],S1[j-1],0x0000);
- }
- Draw_Line(120,160,H1[j],S1[j],0xFFFF);
- Draw_Line(120,160,H2[m],S2[m],0xFFFF);
- }
- }
- void time(void) interrupt 3
- {
- TH1=0xFC;
- TL1=0x17;
- count++;
- if(count==1000)
- {
- j++;
- count=0;
- }
- if(j==60)
- {
- j=0;
- m++;
- }
- if(m==60)
- {
- m=0;
- }
- }
復(fù)制代碼
|