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

📄 main.c

📁 CM12864驱动程序 ARM控制LCD显示数字还有屏幕保护功能
💻 C
字号:

#include <stdlib.h> 
#include <stdio.h> 
//#include "reg52.h"
#include "config.h"
#include "ks0108.h"
#include "string.h"
#include "math.h"
int x,y,qqw;
uint8 LCDExist;

///***************************************************************/
///* 函数功能: 延时
///* 入口参数:D_time:延迟的时间
///* 出口参数:无
///***************************************************************/

void Delay(uint8 D_time)
{
   uint8 i,j;
   for(j=0;j<D_time;j++)
	 for(i=0;i<124;i++);

}
void Delaym(uint32 D_time)
{
   uint32 i,j;
   for(j=0;j<D_time;j++)
	 for(i=0;i<0xfff;i++);

}
///***********************LCD12864驱动程序部分********************************/
///***************************************************************/
///* 函数功能: 延时判忙
///* 入口参数: 无
///* 出口参数: 无
///***************************************************************/
uint8  LCD12864_Delay(void)
{
	uint8 LCD_status=0x90,i;

	IOSET=LCD_RW; //读状态
	IOCLR=LCD_DI;
	
	if(LCDExist)
	{
		while(LCD_status&0x90)//判忙以及复位情况
		{
			if(i<1000)
			{
				IODIR &=~(LCDPORT);
				for (i=0;i<2 ;i++ );
				IOSET=LCD_EN ;
				Delay(1);
				LCD_status =(IO0PIN&LCDPORT)>>8;
				IODIR |=LCDPORT;
				IOCLR=LCD_EN;
				i++;
			}
			else
			{
				LCDExist = FALSE;
				return FALSE;
			}
			
		}
	}
	
	return TRUE;

}

////***************************************************************/
///* 函数功能: 向LCD12864中写入数据或命令
///* 入口参数: D_type:0->写入的是命令,1->写入的是数据
///* 			 D_code:要写入的数据
///* 出口参数: 无
///***************************************************************/
void LCD12864_Write_code(uint32 type,uint8 D_code)
{
	LCD12864_Delay();
	
	IOCLR=LCD_RW;
	if(type)
		IOSET=LCD_DI;
	else
		IOCLR=LCD_DI;
	
	IO0PIN=(IO0PIN&(~(LCDPORT)))|(D_code<<8);
	
	IOSET=LCD_EN;
	Delay(1);
	IOCLR=LCD_EN;
}

///***************************************************************/
///* 函数功能: 设置12864显示的初始地址
//** 入口参数: L_X:竖直方向(0<=L_X<=7)  L_Y:水平方向(0<=L_Y<=127)
///* 出口参数: 无
///***************************************************************/
void LCD_Set_XY(uint8 L_X,uint8 L_Y)
{

	L_Y &= 0x3f; // 0=<L_Y<=63   数据保护
	L_Y |= 0x40; //01xx xxxx
	LCD12864_Write_code(0,L_Y);//写横向地址
	
	L_X &= 0x07; //0<=L_X<=7  数据保护
    L_X |= 0xb8; //1011 1xxx
    LCD12864_Write_code(0,L_X); //写纵向地址
    
}


///****************************************************************
//** 函数功能: 在屏幕上显示汉字
//** 入口参数: bmp:所要画的图
//**           start_x,start_y:图的起始地址
//**			 postiton:左右半屏选择 1->右半屏 0->左半屏
//** 出口参数: 无
//****************************************************************/
void LCD12864_Darw_bmp_HZ(uint32 position,uint8 *bmp,uint8 start_x,uint8 start_y)
{
	uint8 a;
	
	if(!position)
	{
		IOSET=CS1;
		IOCLR=CS2;
	}
	else
	{
		IOCLR=CS1;
		IOSET=CS2;
	}

	LCD_Set_XY(start_x++, start_y);//设置显示地址
	for(a=0 ;a<16 ;a++)
		LCD12864_Write_code(1, bmp[a]);
	LCD_Set_XY(start_x, start_y);
	for(a=16 ;a<32 ;a++)
		LCD12864_Write_code(1, bmp[a]);

}

///****************************************************************
//** 函数功能: 在屏幕上显示英文
//** 入口参数: bmp:所要画的图 position:左右半屏选择 0->左半屏 1->右半屏
//**           start_x,start_y:图的起始地址
//** 出口参数: 无
//****************************************************************/
void LCD12864_Darw_bmp_ENG(uint32 position,uint8 *bmp,uint8 Start_x,uint8 Start_y)
{
	uint8 a;
	
	if(!position)
	{
		IOSET=CS1;
		IOCLR=CS2;
	}
	else
	{
		IOCLR=CS1;
		IOSET=CS2;
	}

	LCD_Set_XY(Start_x++, Start_y);//设置显示地址
	for(a=0 ;a<8 ;a++)
		LCD12864_Write_code(1, bmp[a]);
	LCD_Set_XY(Start_x, Start_y);
		for(a=8 ;a<16 ;a++)
		LCD12864_Write_code(1, bmp[a]);

}


///****************************************************************
//** 函数功能: 在屏幕上显示数字
//** 入口参数: bmp:所要画的图 position:左右半屏选择 0->左半屏 1->右半屏
//**           start_x,start_y:图的起始地址
//** 出口参数: 无
//****************************************************************/
void LCD12864_Darw_bmp_NUM(uint32 position, uint8 c, uint8 Start_x, uint8 Start_y)
{
	uint8 a;
	
	if(!position)
	{
		IOSET=CS1;
		IOCLR=CS2;
	}
	else
	{
		IOCLR=CS1;
		IOSET=CS2;
	}

	LCD_Set_XY(Start_x++, Start_y);//设置显示地址
	for(a=0 ;a<8 ;a++)
		LCD12864_Write_code(1, BMP_NUM[c][a]);
	LCD_Set_XY(Start_x, Start_y);
	for(a=8 ;a<16 ;a++)
		LCD12864_Write_code(1, BMP_NUM[c][a]);

}

///****************************************************************
///** 函数功能: 清屏
//** 入口参数: 无
//** 出口参数: 无
//****************************************************************/
void LCD12864_Clr(void)
{
	uint8 i,j;
	IOSET=CS1;
	IOSET=CS2;
	
	Delay(1);
	for (i=0;i<8;i++ )
	{
		LCD_Set_XY(i, 0);
		for(j=0 ;j<64 ;j++)
			LCD12864_Write_code(1, 0x00);
			
	}
	
}
////***************************************************************/
///* 函数功能: LCD12864初始化
///* 入口参数: 无
///* 出口参数: 无
///***************************************************************/
void LCD12864_Init(void)
{
 	LCD12864_Write_code(0,LCD12864_ON); //开显示
}
//////////////////////////////////////////////////////
///2008.4.29
///zhang
//格式化函数
////////////////////////////////////////////////////////
void printQ(uint8 g[])
{int8 u=0;
 int i;

  for(i=0;i<17;i++)
   {u=g[i];
    if(u=='\0')
      {
       y=y+2;
       x=0;
       break;
      }
    if(i<8)
     {if(u==' ')
       x=x+8;
      else
       {
        LCD12864_Darw_bmp_NUM(0,(u-0x30),y,x);
        x=x+8;
       }
     }
    else
     {if(u==' ')
       x=x+8;
      else
       { 
        LCD12864_Darw_bmp_NUM(1,(u-0x30),y,x);
        x=x+8;
       }
     }  
     
  }
}
///////////////////////////////////////////
//2008.4.29
//zhang
//test
//////////////////////////////////////////
void ppo(uint8 q, uint8 Start_x, uint8 Start_y)
{  uint8 a;
   if(Start_y<57)
   {IOSET=CS1;
    IOCLR=CS2;}
   if(Start_y>61)
    {IOSET=CS2;
     IOCLR=CS1;} 
   LCD_Set_XY(Start_x++, Start_y);//设置显示地址
   for(a=0 ;a<9 ;a++)
		LCD12864_Write_code(1, bmp[q][a]);
   LCD_Set_XY(Start_x, Start_y);
   for(a=8 ;a<18 ;a++)
		LCD12864_Write_code(1, bmp[q][a]);
}
///////////////////////////////////////////////
//2008.4.29
//zhang
//屏幕保护//输入参数qqw=1;时执行
///////////////////////////////////////////////
void pingbao(void)
{int a,b,i,j;
 a=2;
 b=0;
 i=0;
 LCD12864_Clr();
 while(qqw)
  {
     {
     if(i==1)
       a=a-1;
     else
       a=a+1;
   if(a==6)
    i=1;
   if(a==0)
    i=0;
     }
     {
     if(j==1)
      b=b-8;
     else
      b=b+8;
   if(b==120)
    j=1;
   if(b==0)
    j=0;
     }
   LCD12864_Clr();    
   ppo(0,a,b);
  Delaym(400);////////一定要延时。
  }
}
///****************************************END************************************/

int main()
{    
  uint8 u[19]=" ";
  uint8 t[19]="MIN ";
  uint8 r[19]="SEC ";
  uint8 w[19]="3333333";
  x=0;
  y=0;
  qqw=1;
 
  PINSEL0=0;
  PINSEL1=0;
  IODIR=~0;
  
   IOSET=CS1;
   IOSET=CS2;
   LCD12864_Init();
   IOCLR=CS1;
   IOCLR=CS2;
   
  LCD12864_Clr();
  
  printQ(u);
  printQ(t);
  printQ(r);
  printQ(w);
  
 ppo(0,0,0);
 ppo(1,0,9);
  
  while(1)
   {
    pingbao();
   }
return 1;}

⌨️ 快捷键说明

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