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

📄 smc1602.c

📁 用keil编写高速AD AD9225的工程文件
💻 C
字号:
#include"SMC1602.h"
#include<intrins.h>

void SendData(char value)
{
	char i;
	LcdClk=0;
	_nop_();
	for(i=0;i<8;i++){
	  LcdDat=(bit)(value&0x80);
	  LcdClk=0;
	  value<<=1;
	  LcdClk=1;
	  }
}
	    
void LcdRead()
{
	unsigned char i;
    for(i=0;i<255;i++)
	 _nop_();
}
void WriteLcd(unsigned char value,bit RS)
{
	LcdRS=RS;
	LcdEn=0;
	SendData(value);
	LcdEn=1;
}


void WriteCmd(unsigned char value,bit atrrib)
{	if(atrrib)
	  LcdRead();
	WriteLcd(value,0);
}

void WriteData(unsigned char value)
{
 	LcdRead();
   	WriteLcd(value,1);
}

void InitLcd(void)
{
	Delay400Ms();	
	WriteCmd(0x38,0);
	Delay5Ms();
	WriteCmd(0x38,0);
	Delay5Ms();
	WriteCmd(0x38,0);
	Delay5Ms();
	WriteCmd(0x38,1);
	WriteCmd(0x08,1);		// 先设置关屏 
	WriteCmd(0x01,1);		// 清屏 
	WriteCmd(0x06,1);		// 设置光标显示模式
	WriteCmd(0x0c,1);		// 开屏并显示光标 
}

void LocateXY(char x,char y)
{
	unsigned char temp;
	temp=x&0x0f;
	if(y&0x1)
	  temp|=0x40;
	temp|=0x80;
	WriteCmd(temp,1);
}

void PutChar(char x , char y , char value)
{
	LocateXY(x,y);
	WriteData(value);
}

void PutStr(char x,char y,char * str)
{
	unsigned char i,len=0;
	while (str[len] >31)
		len++;
	for (i=0;i<len;i++) 
	{
		PutChar(x++,y,str[i]);
		if ( x == 16 )
		{
			x = 0; y ^= 1;
		}
	}
}
/*显示0~99999999之间的整型*/
void PutLong(char x,char y,unsigned long F)
{
	unsigned char dat[8];
	char i;
	dat[7]=F/10000000;
	dat[6]=(F%10000000)/1000000;
	dat[5]=(F%1000000)/100000;
    dat[4]=(F%100000)/10000;
	dat[3]=(F%10000)/1000;
	dat[2]=(F%1000)/100;
	dat[1]=(F%100)/10;
	dat[0]=F%10;
	if(dat[7]){
	  for(i=0;i<8;i++)
	    PutChar(x+i,y,48+dat[7-i]);
	  }
	else if(dat[6]){
	  for(i=0;i<7;i++)
	    PutChar(x+i,y,48+dat[6-i]);
	  }
	else if(dat[5]){
	  for(i=0;i<6;i++)
	    PutChar(x+i,y,48+dat[5-i]);
	  }
    else if(dat[4]){
	  for(i=0;i<5;i++)
	    PutChar(x+i,y,48+dat[4-i]);
	  }
	else if(dat[3]){
	  for(i=0;i<4;i++)
	    PutChar(x+i,y,48+dat[3-i]);
	  }
	else if(dat[2]){
	  for(i=0;i<3;i++)
	    PutChar(x+i,y,48+dat[2-i]);
	  }
	else if(dat[1]){
	  for(i=0;i<2;i++)
	    PutChar(x+i,y,48+dat[1-i]);
	   }
	else
	   PutChar(x,y,48+dat[0]);
	  	
}
/*显示0.001~99999之间的浮点型*/
void PutFloat(char x,char y, float F)
{
	 unsigned long temp,temp1,temp2;
	 unsigned char d[8],NumI,NumF;
	 temp=(long)(F*1000);
	 temp1=(long)F;
	 temp2=temp%1000;
	 d[7]=temp/10000000;
	 d[6]=(temp%10000000)/1000000;
	 d[5]=(temp%1000000)/100000;
	 d[4]=(temp%100000)/10000;
	 d[3]=(temp%10000)/1000;
	 d[2]=(temp%1000)/100;
	 d[1]=(temp%100)/10;
	 d[0]=temp%10;
	 if(d[7]) NumI=5;
	 else if(d[6]) NumI=4;
	 else if(d[5]) NumI=3;
	 else if(d[4]) NumI=2;
	 else if(d[3]) NumI=1;
	 else NumI=1;
	 if(d[0]) NumF=3;
	 else if(d[1]) NumF=2;
	 else if(d[2]) NumF=1;
	 else NumF=0;
     switch(NumF){
	     case 3: PutLong(x,y,temp1);
		 	     PutChar(x+NumI,y,46); 
				 PutChar(x+1+NumI,y,48+d[2]);
				 PutChar(x+2+NumI,y,48+d[1]);
				 PutChar(x+3+NumI,y,48+d[0]);
				 break;
		 case 2: PutLong(x,y,temp1);
		         PutChar(x+NumI,y,46);
		         PutChar(x+1+NumI,y,48+d[2]);
				 PutChar(x+2+NumI,y,48+d[1]);
				 break;
		 case 1: PutLong(x,y,temp1);
		         PutChar(x+NumI,y,46); 
				 PutChar(x+1+NumI,y,48+d[2]);
				 break;
		 case 0: PutLong(x,y,temp1);
		         break;
		 default:PutLong(x,y,temp1);
		         PutChar(x+NumI,y,46); 
				 PutChar(x+1+NumI,y,48+d[2]);
		 }

	 	
}

void Delay5Ms(void)
{
	unsigned int i =5552;
	while(i--);
}

void Delay400Ms(void)
{
	unsigned char i = 80;
	while(i--)
		Delay5Ms();
}

void Delay(unsigned char dly)
{
   char j;
   for(j=dly;j>0;j--)
	 Delay5Ms();	
}	

⌨️ 快捷键说明

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