请教一个LCD划线的程序!这个程序实在看不明白! 要求要简化它,不要每个点来判断一次,要按照步长来判断! 就是说要划虚线!谢谢那位大侠能帮我分析分析~ //划线 void DrawLine(unsigned int intStarX_Addr,unsigned int intStarY_Addr,unsigned int intEndX_Addr,unsigned int intEndY_Addr) { unsigned char ReadData; unsigned int ErrDataX=0; //X方向公差 unsigned int ErrDataY=0; //Y方向公差 unsigned int PointNum=0; unsigned long Temp; unsigned int D_X; //X坐标差 unsigned int D_Y; //Y坐标差 unsigned int MaxErrData; //X坐标差和Y坐标差中的最大值 unsigned int OffsetX; //X方向修改值 unsigned int OffsetY; //Y方向修改值 unsigned int PX=intStarX_Addr; //X点坐标 unsigned int PY=intStarY_Addr; //Y点坐标 unsigned int EX=intEndX_Addr; unsigned int EY=intEndY_Addr; // EX=intEndX_Addr; // EY=intEndY_Addr; D_X=ABS(PX,EX); //D_X=|intEndX_Addr-intStarX_Addr| D_Y=ABS(PY,EY); //D_Y=|intEndY_Addr-intStarY_Addr| MaxErrData=Max(D_X,D_Y); //MaxErrData=max(D_X,D_Y) if((PX==EX)&&(PY==EY)) { ReadData=ReadSram_one_Data(PX,PY); ReadData=BitTurnOver(ReadData,0); if(bCPL==false) ReadData=ReadData|0x01; WriteSram_one_Data(PX,PY,ReadData); } else {
if(EX>PX) OffsetX=1; //intEndX_Addr>intStarX_Addr else if(EX<PX) OffsetX=0xffff; //intEndX_Addr<intStarX_Addr else OffsetX=0; //intEndX_Addr=intStarX_Addr if(EY>PY) OffsetY=1; //intEndY_Addr>intStarY_Addr else if(EY<PY) OffsetY=0xffff; //intEndY_Addr<intStarY_Addr else OffsetY=0; //intEndY_Addr=intStarY_Addr do { if(PointNum%Step==0) { ReadData=ReadSram_one_Data(PX,PY); ReadData=BitTurnOver(ReadData,0); if(bCPL==false) ReadData=ReadData|0x01; WriteSram_one_Data(PX,PY,ReadData); } Temp=(unsigned long)ErrDataX+D_X; if(Temp>=0x10000) { ErrDataX=ErrDataX+D_X; ErrDataX=ErrDataX-MaxErrData; PX=PX+OffsetX; } else { ErrDataX=ErrDataX+D_X; if(ErrDataX>=MaxErrData) { ErrDataX=ErrDataX-MaxErrData; PX=PX+OffsetX; } } Temp=(unsigned long)ErrDataY+D_Y; if(Temp>=0x10000) { ErrDataY=ErrDataY+D_Y; ErrDataY=ErrDataY-MaxErrData; PY=PY+OffsetY; } else { ErrDataY=ErrDataY+D_Y; if(ErrDataY>=MaxErrData) { ErrDataY=ErrDataY-MaxErrData; PY=PY+OffsetY; } } PointNum++; }while(PointNum!=MaxErrData); ReadData=ReadSram_one_Data(PX,PY); ReadData=BitTurnOver(ReadData,0); if(bCPL==false) ReadData=ReadData|0x01; WriteSram_one_Data(EX,EY,ReadData); } } |