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

📄 main.cpp

📁 嵌入式计算机及接口技术
💻 CPP
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzou ZLG-MCU Development Co.,LTD.
**                                      graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:			main.c
** Last modified Date:  2004-09-16
** Last Version:		1.0
** Descriptions:		The main() function example template
**
**------------------------------------------------------------------------------------------------------
** Created by:			Chenmingji
** Created date:		2004-09-16
** Version:				1.0
** Descriptions:		The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:			Chenxibing
** Modified date:		2005-01-18
** Version:
** Descriptions:		定时器0匹配实验,查询标志位。
**
********************************************************************************************************/
#include "config.h"
#include <cstdlib>
#include "t6963c.h"
//#include "tab.h"
#include "Pin_LPC2138.h"
#include "PinGroup_LPC2138.h"


uint8 wang[32] ={
//-- 王 --
 0x00,0x08,0x7F,0xFC,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x08,0x3F,0xFC,
 0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x04,0xFF,0xFE,0x00,0x00,0x00,0x00,};

uint8 feng[32]= 
{0x20,0x80,0x20,0xFC,0x20,0x88,0xA9,0x88,0xAA,0x50,0xAC,0x20,0xA8,0xDC,0xAB,0x48,
 0xA8,0x40,0xAB,0xFC,0xB8,0x40,0xEB,0xFC,0x80,0x40,0x07,0xFE,0x00,0x40,0x00,0x40,};

uint8 dian[32] = 
{
0x02,0x00,0x02,0x00,0x02,0x10,0x7F,
0xF8,0x42,0x10,0x42,0x10,0x7F,0xF0,
0x42,0x10,0x42,0x10,0x7F,0xF0,0x42,
0x10,0x02,0x00,0x02,0x04,0x02,0x04,
0x01,0xFC,0x00,0x00,
};

Pin_LPC2138 		PIN_CD,PIN_RD,PIN_WR,PIN_TEST;
PinGroup_LPC2138	PIN_LCDGROUP;




void Pin_Ini()
{
	PIN_CD.SetPinTag("P025");
	PIN_CD.Function = 0;
	PIN_CD.Dirction = PinDirOut;
	PIN_CD.Ini();
	PIN_CD.Set();
	
	PIN_RD.SetPinTag("P026");
	PIN_RD.Function = 0;
	PIN_RD.Dirction = PinDirOut;
	PIN_RD.Ini();
	PIN_RD.Set();
	
	PIN_WR.SetPinTag("P027");
	PIN_WR.Function = 0;
	PIN_WR.Dirction = PinDirOut;
	PIN_WR.Ini();
	PIN_WR.Set();
	
	PIN_TEST.SetPinTag("P010");
	PIN_TEST.Function = 0;
	PIN_TEST.Dirction = PinDirOut;
	PIN_TEST.Ini();
	PIN_TEST.Set();
}

void PinGroup_Ini()
{
	PIN_LCDGROUP.SetStartPinTag("P016");
	PIN_LCDGROUP.PinNumber = 8;
	PIN_LCDGROUP.Ini();
}


//读状态函数
unsigned char ReadState()
{
	uint8 a;
	
	PIN_CD.Set();  //设置命令属性
	PIN_RD.Clear();

	a=PIN_LCDGROUP.GetValue();
	PIN_RD.Set();
	
	return a;
}

//bit0指令写状态位,bit1数据读/写状态位,为1时候空闲
void ReadEnable()
{
	uint8 temp;
    while(((temp=ReadState())&0x03)!=0x03);	
}

//bit2数据自动读状态位,为1时候空闲
void Aut_Read()
{
	uint8 temp;
    while(((temp=ReadState())&0x04)!=0x04);
}

//bit3数据自动写状态位,为1时候空闲
void Aut_Write()
{
	uint8 temp;
    while(((temp=ReadState())&0x08)!=0x08);
}

//写命令函数
void WriteCommand (uint8 command)
{


ReadEnable();

PIN_RD.Set();
PIN_WR.Set();
PIN_CD.Set();//命令属性




PIN_LCDGROUP.SetValue(command);

PIN_WR.Clear();
PIN_WR.Set();

}

//写数据函数
void WriteData (uint8 data)
{

	ReadEnable();
	
	PIN_RD.Set();
	
	PIN_WR.Set();
	PIN_CD.Clear(); //数据属性
	
	PIN_LCDGROUP.SetValue(data);

	PIN_WR.Clear();
	PIN_WR.Set();
	
}

/*写命令、写数据命令*********************
数据1、数据2、命令、参数个数*************
*****************************************/
void wr_data(uint8 data1,uint8 data2,uint8 cmd,uint8 num)
{
	uint8 temp;
	temp=num;
	
	if(temp==2)
		{
		WriteData(data1);
		}
	if(temp==2||temp==1)
	 	{
	 	WriteData(data2);
		}
		
	WriteCommand(cmd);
}

//设置数据显示在屏幕上的坐标(以字节为单位)
//x表示显示的行(0~127),y表示显示的列(0~19)
void Set_xy(unsigned char x,unsigned char y)
{
	unsigned int a;
	a=x*20+y;
	wr_data(a&0xff,a>>8,ADR_POS,0x02);
}


//设置数据存储起始地址
void Set_Addr(unsigned char Addr1,unsigned char Addr2)
{
	wr_data(Addr1,Addr2,ADR_POS,0x02);
}


//设置汉字显示在屏幕上的坐标(以16X16汉字为单位)
//x表示显示的行(0~7),y表示显示的列(0~9)
void SetHanZi_xy(unsigned char x,unsigned char y)
{
	unsigned int a;
	a=x*320+y*2;
	wr_data(a&0xff,a>>8,ADR_POS,0x02);
}

//汉字显示函数
void DisHanZi(uint8 x,uint8 y,uint8 *Hzcode)
{
	uint8 i;
	Set_xy(x*16,y*2);
	for(i = 0;i<16;i++)
	{
		WriteCommand(AUT_WR);
		WriteData(Hzcode[2*i]);
		WriteData(Hzcode[2*i+1]);
		WriteCommand(AUT_WO);
		
		Set_xy(x*16+i+1,y*2);
	}
	

}


//液晶初始化函数
//(文本区首地址D1,文本区首地址D2, 文本区宽度,  
//图形区首地址D1, 图形区首地址D2, 图形区宽度,   
//光标形状,  显示方式,  显示开关)
/*void LCD_Init(	unsigned char Txt1,			unsigned char Txt2,		unsigned char Txt_Wide,
              	unsigned char Map1,			unsigned char Map2,		unsigned char Map_Wide,
              	unsigned char Guang_Biao,	unsigned char Disp_Mode,unsigned char Kai_Guan)
{
	Write_Data2(Txt1,Txt2,TXT_STP);
	Write_Data2(Txt_Wide,0,TXT_WID);
	Write_Data2(Map1,Map2,GRH_STP);
	Write_Data2(Map_Wide,0,GRH_WID);
	Write_Com(CUR_SHP|Guang_Biao);
	Write_Com(Disp_Mode);
	Write_Com(DIS_SW|Kai_Guan);
}
*/

void lcd_init()
	{

	wr_data(0x00,0x00,0x40,0x02);	//设置文本显示首地址
	wr_data(0x14,0x00,0x41,0x02);	//设置文本显示宽度
	wr_data(0x00,0x00,0x42,0x02);	//设置图形显示首地址
	wr_data(0x14,0x00,0x43,0x02);	//设置图形显示宽度
	wr_data(0x00,0x00,0xa0,0x00);	//光标形状设置
	wr_data(0x00,0x00,0x81,0x00);	//显示方式设置,“或”
	wr_data(0x00,0x00,0x98,0x00);	//显示开关设置
	}



//清屏程序
void Clear_LCD()
{
	unsigned int a;
	Set_xy(0,0);
	WriteCommand(AUT_WR);
	for(a=0;a<2560;a++)
	WriteData(0x00);
	WriteCommand(AUT_WO);
}

/*自定义字符写入CGROM函数
void Write_CGORM()
{
	unsigned int a;
	Set_CGRAM();
	Set_Addr(0,0x0c);
	for(a=0;a<992;a++)//960
	Write_8_Data(Tab[a],INC_WR);
}
*/
//设置点显示在屏幕上的坐标(以位为单位)
//x表示显示的行(0~127),y表示显示的列(0~159),n=1表示打个点,n=0清除一个点
void Point(unsigned char x,unsigned char y,uint8 n)
{
	unsigned char point;
	unsigned int temp;
	temp=x*20+y/8;
	point=0xf7-y%8;
	if(n)point|=0xf8;
	else point&=0xf7;
	wr_data(temp&0xff,temp>>8,0x24,0x02);	//设置写地址
	wr_data(0x00,0x00,point,0x00);
}


//画线子程序,x1/y1/x2/y2,分别表示起点和终点的坐标、draw=1表示画直线为0表示清除直线
void Line(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,uint8 n)
{
	unsigned char x, y, HalfCount, i; 
	int Feel = 0,DeltaX, DeltaY; 
	char Flag; 
    DeltaX = x2 - x1; 
    DeltaY = y2 - y1; 
    if (abs(DeltaY) < abs(DeltaX))    //abs()为取绝对值函数 
    { 
        if (DeltaX < 0) 
  		{ 
      		i = x1; x1 = x2; x2 = i; 
      		i = y1; y1 = y2; y2 = i; 
   			DeltaX = x2 - x1; 
            DeltaY = y2 - y1; 
  		} 
  		if (DeltaY < 0) Flag = -1; 
  		else Flag = 1; 
  		DeltaY = abs(DeltaY); 
  		HalfCount = DeltaX >> 1; 
  		x = x1; y = y1; 
  		for (i = 0; i <= DeltaX; i++) 
  		{ 
      		Point(x, y, n); //打点 
   			x++; 
      		Feel += DeltaY; 
      		if (Feel > HalfCount) 
   			{ 
             	Feel -= DeltaX; 
    			y += Flag; 
      		} 
  		} 
    } 
    else 
    { 
  		if (DeltaY < 0) 
  		{ 
      		i = x1; x1 = x2; x2 = i; 
      		i = y1; y1 = y2; y2 = i; 
      		DeltaX = x2 - x1; 
      		DeltaY = y2 - y1; 
  		} 
  		if (DeltaX < 0) Flag = -1; 
  		else Flag = 1; 
  		DeltaX = abs(DeltaX); 
  		HalfCount = DeltaY >> 1; 
  		x = x1; y = y1; 
  		for (i = 0; i <=DeltaY; i++) 
  		{ 
      		Point(x, y, n); //打点 
      		y++; 
      		Feel += DeltaX; 
      		if (Feel > HalfCount) 
      		{ 
          		Feel -= DeltaY; 
       			x += Flag; 
      		} 
  		} 
	} 
}



//画圆子程序,其中(x0,y0)表示圆心,R表示半径
//圆方程为(x-x0)^2+(y-y0)^2=R^2
//先打第一象限内的1/4段圆弧(顺时针和反时针各打一次),再依据对称原理打出其他3段圆弧
void Circle(unsigned char x0,unsigned char y0,unsigned char R,uint8 n)
{
	unsigned char i,j=0;
	Point(x0,y0,n);
	for(i=0;i<=R;i++)
   	{
   		while(1)
      	{
      		if(R*R-i*i<=j*j) break;
      		j++;
      	}
		//第一象限打点
      	Point(x0-j,y0+i,n);
	  	Point(x0-i,y0+j,n);
		//第二象限打点
      	Point(x0+j,y0+i,n);
	  	Point(x0+i,y0+j,n);
		//第三象限打点
      	Point(x0+j,y0-i,n);
      	Point(x0+i,y0-j,n);
		//第四象限打点
      	Point(x0-j,y0-i,n);
	  	Point(x0-i,y0-j,n);
	  	j=0;
   	}
}

/*
*********************************************************************************************************
** 函数名称 :main()
** 函数功能 :用P0.7控制BEEP,让BEEP鸣叫。
** 调试说明 :需将跳线JP5和LED短接。
*********************************************************************************************************
*/
int main (void)
{
	char i,j;
    Pin_Ini();
	PinGroup_Ini();
	
//	ReadEnable();
	
lcd_init();
//DelayNS(100);
//PIN_TEST.Set();
//	Line(0,0,127,159,1);
//	PIN_TEST.Clear();
//	wr_data(0x00,0x00,0x98,0x00);	//显示开关设置
	
//	Circle(1,1,1,1);
//	PIN_TEST.Clear();
//	Circle(1,158,1,1);
//	Circle(126,1,1,1);
//	Circle(126,158,1,1);


 //	for(i = 0;i<150;i++)
// 	Circle(63,79,3+6*i,1);
	Point(2,2,0x01); 	
  
//	DisHanZi(1,1,dian);
//	DelayNS(1000000);
	
	PIN_TEST.Clear();
//	Clear_LCD();

	while(1);
	
	return 0;
}
/*********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

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