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

📄 main.c

📁 MB90092字符叠加芯片相关代码。ADS1.2下面的工程文件
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************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:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include "config.h"
#include "mb90092.h"
#include "asic.h"
//#include "sctruct.h"

#define VREST   0x10000000
#define VCS     0x20000000
#define VSCK    0x40000000
#define VSI     0x80000000

char disp_in_use=0;
uint16 _X,_Y;
int8 kkk;

/**********************************************************/

/************************
DelayNS()     软件延时程序

************************/
void DelayNS(uint16 dly)
{ uint16 i;
  for(;dly>0;dly--)
   for(i=0;i<100;i++);
}

/************************/
/************************************************************
	向MB90092发送命令数据函数,输入为MB90092的命令码,输出无*
	发送过程为低位在前,数据在上升沿被锁存					*
*************************************************************/
void command(uint16 com) 
{
 
  char i,j;
  char *p;
  uint8 dat;
  IO2CLR = VCS;              /*使MB90092片选有效*/  
  DelayNS(10);//for(j=0;j<10;j++){;;}/*延时*/
 // p=(char *)&com;
//	dat=*p;
    dat=(uint8)(com>>8);
	for(i=0;i<8;i++)
	{
	
		IO2CLR = VSCK;
		DelayNS(1);//for(j=0;j<10;j++){;;}/*延时*/
  
  		if((dat&0x01)==0)
	
		 {IO2CLR=VSI;
	      DelayNS(1);}
	    else
	     {
		 IO2SET=VSI;
		 DelayNS(1);
		 }
  		dat>>=1;
  		DelayNS(1);//for(j=0;j<10;j++){;;}/*延时*/
  		IO2SET=VSCK;
  		
		DelayNS(1);//for(j=0;j<1;j++){;;}/*延时*/
 	}

      dat=(uint8)com;
 
	for(i=0;i<8;i++)
	{

		IO2CLR=VSCK;
		DelayNS(1);//for(j=0;j<10;j++){;;}/*延时*/

  		if((dat&0x01)==0)

			{IO2CLR=VSI;
			 DelayNS(1);
            }
  		else
            {
		 	IO2SET=VSI;
		 	DelayNS(1);
		 	}
  		dat>>=1;
  		DelayNS(1);//for(j=0;j<10;j++){;;}/*延时*/

  		IO2SET=VSCK;
  		
		DelayNS(1);//for(j=0;j<1;j++){;;}
 	}
	
	IO2SET=VCS;/*使MB90092片选无效*/
	DelayNS(10);//for(j=0;j<10;j++){;;}/*延时*/



}
/*****************************************
	MB90092上电复位,上电后MB90092处于复位状态,
	SPI口必须要在CS脚给出4次有效后,才可使用
******************************************/
void MB90092_REST(void) 
{
	//uint8 SFRPAGE_BAK;
	uint16 i,j;
	DelayNS(100);
	IO2CLR=VREST;
	DelayNS(100);
	
	IO2SET=VREST;
	DelayNS(100);
	
	IO2CLR=VCS;
	DelayNS(100);
	
	IO2SET=VCS;
	DelayNS(100);
	
	IO2CLR=VCS;
	DelayNS(100);
	
	IO2SET=VCS;
	DelayNS(100);
	
	IO2CLR=VCS;
	DelayNS(100);
	
	IO2SET=VCS;
	DelayNS(100);
	//3
	IO2CLR=VCS;
	DelayNS(100);
	
	IO2SET=VCS;
	DelayNS(100);
	
		IO2CLR=VCS;
	DelayNS(100);
	
	IO2SET=VCS;
	DelayNS(100);
	
  //4
	DelayNS(1000);
	DelayNS(1000);
	DelayNS(1000);
	
	
}

/*************************************
	汉字内码到显示命令码转换
	输入为汉字内码,输出为显示命令数据结构
**************************************/
main_char GbToAddress(uint16 gb) 
{
	uint16 zone;/*区码*/
	uint16 site;/*位码*/
	uint16 addr;/*字模地址*/
	main_char t;
	site=gb>>8;
	zone=gb&0x00ff;
	addr=(zone-0xa1)*94+(site-0xa1);/*计算字模地址*/
	t.char_addr2=addr&0x007f;/*取低7位*/
	t.char_addr2|=((addr<<1)&0x0700);
	t.char_addr1=0;
	if((addr&0x1000)!=0)t.char_addr1|=MC;
	if((addr&0x0800)!=0)t.char_addr1|=MB;
	if((addr&0x0400)!=0)t.char_addr1|=MA;/*完成main charater 2命令*/
	return t;
} 

/**************************************
	主屏显示字符定位,输入X,Y坐标,输出:成功1,失败0
***************************************/
int8 gotoxy(uint16 x,uint16 y) 
{
	uint16 com;
	if((x>0x000f)|(y>0x001f))return 0;
	_X=x;_Y=y;
	com=VRAM_ADDR_SET;
	com|=((_X<<6)&0x0300);
	com|=((_X<<5)&0x0060);
	com|=_Y;
	command(com);
	return 1;
}
/**************************************
	清屏命令
***************************************/
void cls(void) 
{
	gotoxy(0,0);
	_X=0;_Y=0;
	command(VRAM_WRITE_CONTROL|FIL);
	command(MAIN_SCREEN_CHAR_CONTROL1/*|MC|MB|MA*/);
	command(MAIN_SCREEN_CHAR_CONTROL2/*|M9|M8|M7|M6|M5|M4|M3|M2|M1|M0*/);
	command(VRAM_WRITE_CONTROL);
}
/**************************************
	扩展方式 在X行,Y列显示1个汉字
	输入:汉字内码,字符颜色,字符背景颜色
	输出:-1失败,0成功显示,到最后,1成功显示。
***************************************/
int8 putcharex(uint16 x,uint16 y,uint16 gb,uint16 CharColor,uint16 BackColor) 
{
	if(!gotoxy(x,y))return -1;
	command(GbToAddress(gb).char_addr1|CharColor|BackColor|MAIN_SCREEN_CHAR_CONTROL1);
	command(GbToAddress(gb).char_addr2|MAIN_SCREEN_CHAR_CONTROL2);
	return 1;
}

/**************************************
	清一个窗口
***************************************/
int8 cls_windows(char top,char left,char bottom,char right)//reentrant
{
	uint16 i,j;
	//if(disp_in_use)return -1;
	disp_in_use=1;
	for(i=top;i<=bottom;i++)
		for(j=left;j<=right;j++)
			putcharex(i,j,*(int16 *)" ",C_YELLOW,B_GREEN);/*在初始位置显示箭头*/
	disp_in_use=0;		
	return 0;
}

/***************************************
	扩展方式输出一串字符
	输入X,Y坐标
****************************************/
int8 sprintex(uint16 m_x,uint16 m_y,char*m_s,int16 CharColor,int16 BackColor) //reentrant
{
	int16 cnt;
	int16 flag;
	int16 cnt2;
	uint16 x,y;
	char *s;
	char i;
//	if(disp_in_use)
//		return -1;
	disp_in_use=1;
	cnt=0;
	flag=0;
	cnt2=0;
	x=m_x;
	y=m_y;
	s=m_s;
	while(*s!='\0')
	{
		if((*s>=0xa1)&&(*(s+1)>=0xa1))/*如果是汉字内码*/
		{
			flag=putcharex(x,y+cnt,*(int16 *)s,CharColor,BackColor);/*显示一个字符*/
			if(flag==-1)
			{
				disp_in_use=0;
				return -1;/*有错误*/
			}
			if(flag==1)
			{
				if(y+cnt+1<24)
				{
					s+=2;
					cnt++;
					cnt2+=2;
				}
				else 
					if(x+1<7)
					{
						s+=2;
						cnt=0;y=0;x++;
						cnt2+=2;
					}
					else
					{
						disp_in_use=0;
						return cnt2;/*显示到最后行列*/
					}
			}/*正常*/
		}
		else/*是ASIC码*/
		{
			if(*s>=32)/*大于32为可显示的ASIC字符*/
			{
				flag=putcharex(x,y+cnt,*(int16 *)(asic+(*s-32)*2),CharColor,BackColor);/*显示一个字符*/
				if(flag==-1)
				{
					disp_in_use=0;
					return -1;/*有错误*/
				}
				if(flag==1)
				{
					if(y+cnt+1<24)
					{
						s+=1;
						cnt++;
						cnt2+=1;
					}
					else 
						if(x+1<7)
						{
							s+=1;
							cnt=0;y=0;x++;
							cnt2+=1;
						}
						else
						{
							disp_in_use=0;
							return cnt2;/*显示到最后行列*/
						}
				}/*正常*/
			}
			else
				if(*s==13)/*判断是否为回车*/
				{
					if(x+1<7)
					{
						s+=1;
						cnt=0;y=0;x++;
						cnt2+=1;
					}
					else
					{
						disp_in_use=0;
						return cnt2;/*显示到最后行列*/
					}
				}
				else
					if(*s==9)/*判断是否为TAB*/
					{
						for(i=0;i<4;i++)/*TAB显示4个空格*/
						{
							flag=putcharex(x,y+cnt,*(int16 *)" ",CharColor,BackColor);/*显示一个字符*/
							if(flag==-1)
							{
								disp_in_use=0;
								return -1;/*有错误*/
							}
							if(flag==1)
							{
								if((y+cnt+1)<24)cnt++;
								else 
									if((x+1)<7)
									{
										cnt=0;y=0;x++;
									}
									else
									{
										disp_in_use=0;
										return cnt2;/*显示到最后行列*/
									}
							}/*正常*/
						}
						s+=1;
						cnt2+=1;
					}
					else
					{
						s+=1;
						cnt2+=1;
					}
		}
	}
	disp_in_use=0;
	return 0;/*返回显示的字符数*/
}

/***************************************
	扩展方式输出一串字符,用于标题显示
	输入X,Y坐标
****************************************/
int8 sprint_title(uint16 x,uint16 y,char *s,uint16 CharColor,uint16 BackColor) //reentrant
{
	int16 cnt=0;
	int16 flag=0;
	int16 cnt2=0;
//	if(disp_in_use)return -1;
	disp_in_use=1;
	while(*s!='\0')
	{

⌨️ 快捷键说明

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