⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1335c51.c

📁 这是一个成熟的用于驱动步进马达的程序,我们用于调试螺钉的.
💻 C
📖 第 1 页 / 共 3 页
字号:
}

//8*16点阵数字显示,res为0表示不反色显示,要显示正负号,res为1表示第一位反色显示,如此类推
void NumDisp_816(uchar x0, uchar y0,uchar res, int dat)
{
    uint temp;
	if(res==0)
	{
	    if(dat<0)
	    {
	        PutSdotInGraph(x0, y0, "-");
	        dat-=1;
	        dat=~dat;
	    }
	    else
	    {
	        PutSdotInGraph(x0, y0, "+");
	    }
		x0++;
	}
	if(res==1)
	{
		Disp816(x0,y0,dat/1000,1);
	}
	else
	{
   		Disp816(x0,y0,dat/1000,0);
	}
    temp=dat%1000;
	if(res==2)
	{
    	Disp816(x0+1,y0,temp/100,1);
	}
	else
	{
		Disp816(x0+1,y0,temp/100,0);
	}
    temp%=100;
	if(res==3)
	{
    	Disp816(x0+2,y0,temp/10,1);
	}
	else
	{
		Disp816(x0+2,y0,temp/10,0);
	}
	if(res==4)
	{
    	Disp816(x0+3,y0,temp%10,1);
	}
	else
	{
		Disp816(x0+3,y0,temp%10,0);
	}
}

//显示8*16点阵数字,res指定是否需要反色显示(非0为反色显示)
void Disp816(uchar x0,uchar y0,uchar num,uchar res)
{
	switch(num)
	{
		case 0: 
			{
				if(!res)
					PutSdotInGraph(x0,y0,"0");
				else
					PutSdotInGraph_V(x0,y0,"0");
				break;
			}
		case 1: 
			{
				if(!res)
					PutSdotInGraph(x0,y0,"1");
				else
					PutSdotInGraph_V(x0,y0,"1");
				break;
			}
		case 2: 
			{
				if(!res)
					PutSdotInGraph(x0,y0,"2");
				else
					PutSdotInGraph_V(x0,y0,"2");
				break;
			}
		case 3: 
			{
				if(!res)
					PutSdotInGraph(x0,y0,"3");
				else
					PutSdotInGraph_V(x0,y0,"3");
				break;
			}
		case 4: 
			{
				if(!res)
					PutSdotInGraph(x0,y0,"4");
				else
					PutSdotInGraph_V(x0,y0,"4");
				break;
			}
		case 5: 
			{
				if(!res)
					PutSdotInGraph(x0,y0,"5");
				else
					PutSdotInGraph_V(x0,y0,"5");
				break;
			}
		case 6: 
			{
				if(!res)
					PutSdotInGraph(x0,y0,"6");
				else
					PutSdotInGraph_V(x0,y0,"6");
				break;
			}
		case 7: 
			{
				if(!res)
					PutSdotInGraph(x0,y0,"7");
				else
					PutSdotInGraph_V(x0,y0,"7");
				break;
			}
		case 8: 
			{
				if(!res)
					PutSdotInGraph(x0,y0,"8");
				else
					PutSdotInGraph_V(x0,y0,"8");
				break;
			}
		case 9: 
			{
				if(!res)
					PutSdotInGraph(x0,y0,"9");
				else
					PutSdotInGraph_V(x0,y0,"9");
				break;
			}
	}
}
/********************************************/
/*画线。任意方向的斜线,直线数学方程	aX+bY=1	*/
/********************************************/
// 参数类型有待修改
void Linexy(uint x0,uchar y0,uint xt,uchar yt,uchar att)
{
	uint t;
	int	xerr=0,yerr=0,delta_x,delta_y,distance;
	int	incx,incy;
	uint row,col;
	delta_x	= xt-x0;							//计算坐标增量
	delta_y	= yt-y0;
	col	= x0;
	row	= y0;
	if(delta_x>0) 
		{
			incx=1;						//设置单步方向
		}
	else 
    {
    	if( delta_x==0	) 
    		{
    			incx=0;				//垂直线
    		}
		else 
			{
				incx=-1;
				delta_x=-delta_x;
			}
	}
	if(delta_y>0) 
		{
			incy=1;
		}
	else
    {
    	if( delta_y==0	) 
    		{
    			incy=0;				//水平线
    		}
		else 
			{
				incy=-1;
				delta_y=-delta_y;
			}
	}
	if(	delta_x	> delta_y )	
		{
			distance=delta_x;	//选取基本增量坐标轴
		}
	else 
		{
			distance=delta_y;
		}

	for( t=0;t <= distance+1; t++ )
	{											//画线输出
		Point((uint)col,row,att);				//画点
		xerr +=	delta_x	;
		yerr +=	delta_y	;
		
		if(	xerr > distance	)
		{
			xerr-=distance;
			col+=incx;
		}
		if(	yerr > distance	)
		{
			yerr-=distance;
			row+=incy;
		}
	}
}

#if 0

/********************************************/
/*画矩形	*/
/********************************************/
void Rectangle(uint x0, uchar y0, uint xt, uchar yt, uchar att)
{
    Linexy(x0, y0, x0, yt,att);
    Linexy(x0, yt, xt, yt,att);
    Linexy(xt, yt, xt, y0,att);
    Linexy(xt, y0, x0, y0,att);
}

#endif


// 写指令代码子程序
void WriteCommand( uchar CommandByte ) 
{
	LCD_CS_LOW;    //选通
    LCD_A0=1;    //1为写命令或读数据
    LCD_WR=0;  
    LCD_RD=1;    //确定读信号不起作用
    LCM_DATA=CommandByte;  //向1335中写入指令代码     
    LCD_WR=1;
    LCD_CS_UP;
	LCM_DATA=0xff; 
	//LcmCmdPort = CommandByte;
}

//---------------------------
// 写参数及显示数据子程序
void WriteData( uchar dataW ) 
{
	LCD_CS_LOW;    //选通
    LCD_A0=0;    //0为写数据、参数和读忙标志        
    LCD_RD=1;    //确定读信号不起作用
    LCM_DATA=dataW;  //向1335中写入指令代码    
    LCD_WR=0;   
    LCD_WR=1;
    LCD_CS_UP;
	LCM_DATA=0xff;
	//LcmWdataPort = dataW;
}

//---------------------------
// 读参数及显示数据子程序
uchar ReadDataLcm( void ) 
{
	uchar Lcmdat;
    LCM_DATA=0xff;
    LCD_CS_LOW;    //选通
    LCD_A0=1;    //0为写数据、参数和读忙标志        
    LCD_RD=0;    //  
    LCD_WR=1;
    Lcmdat=LCM_DATA;
    LCD_RD=1;
    LCD_CS_UP;
	LCM_DATA=0xff;    
  	return Lcmdat;
}

/*=====================================
 初始化子程序
======================================*/
void LcmInition( void ) 
{

	uchar i;
	delay_xms(500);			// 足够的延时确保Lcm已经准备好	
	WriteCommand( SystemSet );			// 系统参数设置
	for (i=0;i<8;i++) {				
		WriteData( ParaSysTable8[i] );	//
	}

	WriteCommand( Scroll ); 			//设定显示区域起始地址
	for (i=0;i<10;i++) {
		WriteData( ParaScrTableA[i] );
	}

	WriteCommand( HdotScr );		// 写入点位移指令代码
	WriteData( 0 );					// 写入P1参数
	WriteCommand( Ovlay );			// 显示合成方式设置
	WriteData( 0x08 );					// 0000 0100 显示一区文本,二区图形属性,二重"或"合成
	WriteCommand( DispOn );			// 写入指令代码
	WriteData( 0x54 );				// 显示 1~4 区开显示,光标关显示
	LcmClear();
//	BuildCgram(0,15);               //
}

#if 0
/*============================================
 建立 cgram,将显示字符送入cgram中

  入口参数约定:Base.... 起始
=============================================*/
void BuildCgram( uchar Base, uchar EndlCode ) 
{

uchar iCgram,ii,ij;

	WriteCommand( CgramAdr );		// CGRAMADR 代码
	WriteData( 0 );					// 设置SAG=07000H
	WriteData( 0x70 );				// 汉字模在cgram中的编码0x70~0x73

	WriteCommand( CsrW );			// CSRW 代码,光标指针设置
	WriteData( 0 );					// 设置CSR=07400H(字符代码=80H)
	WriteData( 0x74 );				// 汉字模在cgram中的编码0x70~0x73
	WriteCommand( CsrDirR );		// CSRDIR 代码
	WriteCommand( mWrite );			// 代码0x42,数据写入指令
	for (ii=0;ii<EndlCode;ii++)
	{
		for (ij=0;ij<2;ij++)
		{
			for (iCgram=0;iCgram<32;iCgram+=2) 
				WriteData( Cdotlib[(Base+ii)*32+ij+iCgram] );	// 将制定的数据块写入 cgram
		}
		
	}
}



	

/*============================================================================
 汉字写入子程序(文本方式)
 在文本方式下显示汉字,	首先要建立汉字Cgram, 要定义汉字代码.
 在文本方式下写汉字需要写入4 个代码以组成一个汉字 
 每8字节组成一个点阵Ascii小区,4个小区组合成一个汉字所以需要4个代码
 ============================================================================*/
void PutCdotInAlpha( uchar Ox, uchar Oy, uchar Cnumber ) 
{

uint tempPtr;
uchar tempCount;
		
	tempPtr = (uint)Oy * paraP9 + Ox;
	WriteCommand( CsrDirD );					// CSRDIR 代码(下移)

	for(tempCount=0;tempCount<2;tempCount++)
	 {
		
		WriteCommand( CsrW );					// CSRW 代码,光标指针设置
		WriteData( (uchar)(tempPtr &0xff) );	// 设置光标地址CSR
		WriteData( tempPtr /256 + BasePart1 );
		WriteCommand( mWrite );					// 代码0x42,数据写入指令

		WriteData( Cnumber++ );					// 写入汉字代码

		WriteData( Cnumber++ );					// 写入汉字代码
		tempPtr++;								// 修正光标地址
	}
}

#endif

/*====================================================
;  绘点子程序,携入参数attr决定写或擦点
 ====================================================*/
void Point(uint Px, uchar Py, uchar attr ) 
{

	uint tempPtr;
	uchar tempD,tempP;
		
	tempPtr = (uint)Py * paraP9 + (Px / 8);			// 计算地址
	WriteCommand( CsrDirD );						// CSRDIR 代码(光标自动下移)
	WriteCommand( CsrW );							// 设置光标地址
	WriteData( (uchar)(tempPtr & 0xff) );
	WriteData( (uchar)(tempPtr /256 +BasePart2) );
	WriteCommand( mRead );							// 读显示ram指令
	tempD = ReadDataLcm();							// 读取当前显示数据
	//tempP = 1<<(uchar)(7-Px & 0x0007);
    tempP = Px - ((Px / 8) * 8);
	tempP = (0x80 >> tempP);

// 根据预定属性决定写点或擦除
	if( attr )
		{
			tempD |= tempP;	// 画点
		}
	else 
		{
			tempD &= ~tempP;				// 消点
		}

	WriteCommand( CsrW );						// 重新设置光标地址
	WriteData( (uchar)(tempPtr & 0xff) );
	WriteData( (uchar)(tempPtr /256+BasePart2) );
	WriteCommand( mWrite );						// 代码0x42,数据写入指令
	WriteData( tempD );							// 写入合成数据

}

/*======================== 清显示 32K RAM区(清屏)子程序 ======================*/

void LcmClear( void ) 
{

	uint i1=32768;

	WriteCommand( CsrDirR ); 			// 光标移动方向定义:自动右移
	WriteCommand( CsrW );				// 光标Locate,定位
	WriteData( 0 );						// 写入参数CSRL设置参数光标指针低8位
	WriteData( 0 );						// 写入参数CSRH设置参数光标指针高8位
	WriteCommand( mWrite );				// 数据写入指令,代码0x42
	while(i1--)	
	{

		WriteData( 0x0 );	// 写入数据0
	}
}

#if 0
/*======================== 清显示 图形 RAM区(清屏)子程序 ======================*/
void LcmClear_G( void ) 
{

	uint i1=0x3400;

	WriteCommand( CsrDirR ); 			// 光标移动方向定义:自动右移
	WriteCommand( CsrW );				// 光标Locate,定位
	WriteData( 0xff );						// 写入参数CSRL设置参数光标指针低8位
	WriteData( 0x3f );						// 写入参数CSRH设置参数光标指针高8位
	WriteCommand( mWrite );				// 数据写入指令,代码0x42
	while(i1--)	
	{

		WriteData( 0x0 );	// 写入数据0
	}
}



/*============================================================================
 光标位定位,用于在1区图形方式下。
 输入参数约定:	x...水平方向字节单位坐标,即可以以半个汉字宽度设定水平坐标。
 				y...垂直方向以行线定位的坐标,可以定位到点单位。
				左上角约定坐标为( 0, 0 )

 ============================================================================*/
void Locatexy(uchar x,uchar y, uchar attribs) 
{
	uint temp;
	temp = (uint)y*paraP9+x;
	if(attribs)temp += BasePart2*256;	// 如果需要就指向第二区,加上第二区首地址
	WriteCommand( CsrW );				// 光标Locate,定位
	WriteData( (uchar)(temp & 0xff) );	// 写入参数CSRL设置参数光标指针低8位
	WriteData( (uchar)(temp /256 ) );	// 写入参数CSRH设置参数光标指针高8位
}

#endif





#if 0

/************************************************/
/*画圆。数学方程(X-Ox)^2+(Y-Oy)^2=Rx^2		*/
/************************************************/

void circle(uint Ox,uchar Oy,uchar Rx,uchar attr)
{
	uint xx,rr,xt,yt,rs,col,row;
	yt=Rx;
	rr=Rx*Rx+1;			//补偿 1 修正方形
	rs=(yt+(yt>>1))>>1;		//(*0.75)分开1/8圆弧来画
	for (xt=0;xt<=rs;xt++)
	{
		xx=xt*xt;
		while ((yt*yt)>(rr-xx))yt--;
		col=Ox+xt;		//第一象限
		row=Oy-yt;
		Point(col,row,attr);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -