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

📄 lcd1.c

📁 示波器
💻 C
字号:
#include"lcd1.h"
#include "config.h"
#include "math.h"
#include "adc.h"

unsigned char      data[64][16]={0};
unsigned char buf[3];

/*****************************延时子程序**************************/
void delay( unsigned int t )
{
  while( t-- );      
}

/*****************************初始化子程序******************************/
void Serial_int(void)
{	
	PINSEL0 = PINSEL0&(~0x0F);
	IO0DIR  = 0x0f;
	IO0SET  = IO0SET|CS;
	IO0CLR  = IO0CLR|SID;
    IO0CLR  = IO0CLR|CLK; 
    IO0CLR	= IO0CLR|PSB;
    Writelcd( 0x30,0 );//功能设置,一次送8位数据,基本指令集
    delay( 50 );
	Writelcd( 0x30,0 );//功能设置,一次送8位数据,基本指令集
    delay( 40 );
    Writelcd( 0x0c,0 );//0000,1100  整体显示,游标off,游标位置off
    delay( 50 );
    Writelcd( 0x01,0 );//0000,0001 清DDRAM
    delay( 8000 );
    Writelcd( 0x02,0 );//0000,0010 DDRAM地址归位
	delay( 50 );

    delay( 50 );
    Writelcd( 0x80,0 );//1000,0000 设定DDRAM 7位地址000,0000到地址计数器AC//   	 
    delay( 150 );
	Writelcd( 0x06,0 );	
}

/*****************************写液晶子程序******************************/
/************************************************************************
说明:word:要写的内容 dat:1为数据 0为指令
*************************************************************************/
void Writelcd(int word,int dat)
{
	int lcddat[3];
	int i,j,k;
	lcddat[0] = ( 0xf8+(dat<<1) );//第一个字节
	lcddat[1] = ( word&0xf0 ) ;     //第二个字节 内容的高四位+0000
	lcddat[2] = ( (word<<4)&0xf0 ) ;//第三个字节 内容的第四位+0000
	IO0CLR    = IO0CLR|CS;
	IO0SET    = IO0SET|CS;
	IO0CLR    = IO0CLR|CLK;
	for(i=0;i<3;i++)
	{
		j = lcddat[i];
		for(k=0;k<8;k++)
		{
			if( (j<<k)&0x80 )IO0SET = IO0SET|SID;		
	        else 			 IO0CLR = IO0CLR|SID;			
			/**时钟下降沿写入数据**/
			IO0SET  = IO0SET|CLK;
			IO0CLR  = IO0CLR|CLK; 
		}
	}	
}




/***************画图专用清屏函数*****************/

void wt_clr()
{
	unsigned char i,j;
	for(i=0;i<64;i++)
	{
		for(j=0;j<16;j++)
		{
			data[i][j] = 0x00;
		}
	}
}
/***2^x的值*********************/
unsigned char smart(uint8 x)
{
	uint8 i,da=1;
	for(i=0;i<x;i++)
	{
		da=da*2;	
	}	
	return da;
}

/******************************************************************
*********取得坐标和数据;
******************************************************************/
void get_data(unsigned char x,unsigned char y)
{
	unsigned char dot,f;
	f = 7-x%8;
	dot = smart(f);
	buf[0] =y;
	buf[1] =x/8;
	buf[2] = dot;		//数据
	data[buf[0]][buf[1]] |= buf[2];
}
/****************************************************************
*****画圆函数
*****接口参数:xi,yi圆心坐标
*************:R半径
******************************************************************/
void circle(unsigned char xi,unsigned char yi,unsigned char r)
{
	float pi = 2*3.14159265,i;
	for(i=0;i<pi;i+=pi/50.0)
	{
		get_data(r*cos(i)+xi,r*sin(i)+yi);
		
	}
}
/****************************************************************
*****画椭圆函数
*****接口参数:xi,yi圆心坐标
*************:r1,r2半径
******************************************************************/
void ellipse(unsigned char xi,unsigned char yi,unsigned char r1,unsigned char r2)
{
	float pi = 2*3.14159265,i;
	for(i=0;i<pi;i+=pi/50.0)
	{
		get_data(r1*cos(i)+xi,r2*sin(i)+yi);
		//data[buf[0]][buf[1]] |= buf[2];
	}
}

/**************************************************************
***正弦曲线
************************************************************/
void sin_line()
{
	float pi = 14*3.14159265,i,n=0;
	for(i=0;i<pi;i+=pi/150.0)
	{
		get_data(n++,32+20*sin(i));
		//data[buf[0]][buf[1]] |= buf[2];
	}
}

/*************************************************************
****AD转化取点
*************************************************************/
void ad_plot()
{
	unsigned char   t;
	unsigned short  result;
	while(( result = GetAdc()) >= 0x1f);
	for(t=0;t<128;t++)
	{
		result =  GetAdc();
		get_data(t,result);
	//	data[buf[0]][buf[1]] |= buf[2];
	//	delay(3000);
	}
}
/*******************************************************************
画图函数
*****************************************************************/
void wrtu()
{
	char i,i1;

	IO0CLR = IO0CLR|CS;
	IO0SET = IO0SET|CS;
	IO0CLR = IO0CLR|CLK;
	
		Writelcd( 0x01,0 ); 
		delay(5000);
	    Writelcd( 0x32,0 );
	    delay(5000);
		Writelcd( 0x36,0 );
		delay(5000);

	for(i1=0;i1<32;i1++)
		   {
		 		Writelcd( 0x80+i1,0 );
				Writelcd( 0x80,0 );
				for(i=0;i<16;i++)
					{	
					
					Writelcd( data[i1][i],1 );

					} 
		}
		 for(i1=0;i1<32;i1++)
		   {
		 		Writelcd( 0x80+i1,0 );
				Writelcd( 0x88,0 );
				for(i=0;i<16;i++)
					{	
					
					Writelcd( data[i1+32][i],1 );
						
					}
			} 
}

⌨️ 快捷键说明

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