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

📄 main.c

📁 利用 ADS1.2 开发的s3c2410平台下的汉字显示程序
💻 C
字号:
/*************************************************************************/
/*                                                                       */
/*               Copyright Shenzhen Watertek S.&T. Co.,Ltd  2002         */
/*                         All Rights Reserved.                          */
/*                                                                       */
/* THIS WORK CONTAINS TRADE SECRET AND PROPRIETARY INFORMATION WHICH IS  */
/* THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS AND IS   */
/* SUBJECT TO LICENSE TERMS.                                             */
/*                                                                       */
/*************************************************************************/

/*************************************************************************/
/*                                                                       */
/* FILE NAME                                               VERSION       */
/*                                                                       */
/*      main.c                                        S3c2410 display 1.0*/
/*                                                                       */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This file contains macro and main routines 		 */
/*                                                                       */
/* AUTHOR                                                                */
/*    	Zhi-gang yang   shenzhen watertek                                */
/*                                                                       */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*      None	                          				 */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         DATE                    REMARKS                               */
/*                                                                       */
/*      2004-12-27      Created initial version 1.0                      */
/*************************************************************************/
#include <string.h>
#include <stdarg.h>
#include "2410addr.h"
#include "def.h"

void Led1_On_or_Off(int flag);
void Led2_On_or_Off(int flag);
void Led4_On_or_Off(int flag);
void clrsrc(COLOR mcolor);
int setpixel(int x,int y,unsigned short pencolor);
unsigned short rgb(int red,int green,int blue);
 int drawtext(int x0,int y0,char *c,int pencolor)  ;
/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      C_Entry			                                         */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      C entry function				                 */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      Zhi-gang Yang          shenzhen watertek                         */
/*                                                                       */
/* INPUTS                                                                */
/*      None                                                             */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      None      	                                                 */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         DATE                    REMARKS                               */
/*                                                                       */
/*      2004-12-28      Created initial version 1.0                      */
/*************************************************************************/
void C_Entry()
{
	int i,j,k;
//	Led4_On_or_Off(TRUE);
//	while(i++<10000);
//	Led4_On_or_Off(FALSE);
	clrsrc(15);
//	while(i++<10000);
	for(i=0;i<320;i++)
	{
	 setpixel(i,239,rgb(255,0,0));
	 setpixel(i+1,239,rgb(255,0,0));
	 setpixel(i+1,238,rgb(255,0,0));
	 setpixel(i,238,rgb(255,0,0));
     setpixel(i,0,rgb(255,0,0));
	 setpixel(i+1,0,rgb(255,0,0));
	 setpixel(i+1,1,rgb(255,0,0));
	 setpixel(i,1,rgb(255,0,0));

	 }
	 
	for(i=0;i<320;i++)
	{
	 setpixel(0,i,rgb(255,0,0));
	 setpixel(1,i,rgb(255,0,0));
	 setpixel(1,i+1,rgb(255,0,0));
	 setpixel(0,i+1,rgb(255,0,0));
	  setpixel(319,i,rgb(255,0,0));
	 setpixel(318,i,rgb(255,0,0));
	 setpixel(319,i+1,rgb(255,0,0));
	 setpixel(318,i+1,rgb(255,0,0));

	 }

	
		drawtext(15,160,"南昌大学信息工程学院",0xf000);
	//	drawtext(14,159,"嵌入式实验教学系统",rgb(0,0,0));
	//	for(j=0;j<100000;j++);
		drawtext(95,110,"黄文礼",0);
	//	drawtext(16,131,"深圳旋极嵌入式实验教学系统",rgb(0,0,255));
	//	for(j=0;j<100000;j++);
	do
	{		
		Led4_On_or_Off(TRUE);
		for(i=0;i++<1000000;);
		Led4_On_or_Off(FALSE);
		for(i=0;i++<1000000;);
	}while(1);
	;
}


/****************************************************************************
* FUNCTION
*
*   setpixel
*
* DESCRIPTION
*
*    This function set the appointed pixel the specified color
*
* CALLED BY
*
*    
*
* CALLS
*
*    none
*
* INPUTS
*
*    int x,int y,unsigned short pencolor
* OUTPUTS
*
*    none
*                    
*
****************************************************************************/
unsigned short rgb(int red,int green,int blue)
{
	unsigned short pencolor;
	/*compose the color depend the red, blue and green*/
	pencolor=(((red&(~(~0<<RED_BITNUM)))<<RED_SHIFT)|((green&(~(~0<<GREEN_BITNUM)))<<GREEN_SHIFT)\
	                                                   |((blue&(~(~0<<BLUE_BITNUM)))<<BLUE_SHIFT));
	return pencolor;
}
		
int setpixel(int x,int y,unsigned short pencolor)
{
	int movetop;   /*THE PIXEL ADDRESS*/
	short *p;
	if (x<0||x>(int)x_limit) return ERROR;
	if (y<0||y>(int)y_limit) return ERROR;
	/*指向所要显示的像素偏移地址*/
	movetop=(x*x_size+y);//一个像素占1个字节   
	p=(short *)(VideoAddrStart+movetop);
	*p=pencolor;
	return 1;
}
void clrsrc(COLOR mcolor)
{
unsigned char *p;
for(p=(unsigned char *)VideoAddrStart;p<(unsigned char *)VideoAddrEnd;p++) *p=mcolor;
return ;
}

void ascii_168(int x0,int y0,char *code,int pencolor)
{
	 /*define the code group for compare the code*/
	 char mask[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
	  char mat[16];
	  char *hzpos;
	  int i,k,m,offset;
	  offset=(*code)*16;
	  hzpos=(char *)(asciibufbase+offset);
	  /*transmit the lattice message to the group*/
	  for (m=0;m<16;m++)
  	  {
  	  	  mat[m]=*hzpos;
  		  hzpos++;
  	   }
  	  /*display the character depend on the messsage of the group*/
  	  for (i=0;i<16;i++)
	  		for (k=0;k<8;k++)
	  		{
	  		 	if (mask[k%8]&mat[i])
	  		 	{
	 			 setpixel(x0+k,y0+i,pencolor);

	 			 }
 	   		}
}

int drawascii168(int x0,int y0,char *c,int pencolor)             
{    
	int x,y,counter;
	x=x0;
	y=y0;
	counter=0;
	while(*c!='\0')    /*while don't reach to the end of the string*/
	{
		while(x<320 && (*c!='\0'))   /*while the X coordinate don't exceed the scope of X limit*/
		{
			ascii_168(x,y,c,pencolor);  /*display the character*/
			x+=8;
			c+=1;
			counter+=1;
		}
        	x=0;  /*exchange the next row*/                                              
        	y+=16;
    }
     return(counter);
}       

void ascii_1616(int x0,int y0,char *code,int pencolor)
{
	/*define the code group for compare the code*/
	 char mask[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
	  char mat[32];
	  char *hzpos;
	  int i,j,k,m,offset;
	  /*computer the excurison of the base address*/
	  offset=(*code)*32;
	  hzpos=(char *)(asciibufbase+offset);
	  /*get the character lattice message*/
	  for (m=0;m<32;m++)
  	  {
  	  	mat[m]=*hzpos;
  		  hzpos++;
  	   }
  	   /*display the character*/
  	  for (i=0;i<16;i++)
	  	for (j=0;j<2;j++)
	  		for (k=0;k<8;k++)
	  		{
	  		 	if (mask[k%8]&mat[2*i+j])
	 			 setpixel(x0+8*j+k,y0+i,pencolor);
 	   		}
}


int drawascii1616(int x0,int y0,char *c,int pencolor)             
{    
	int x,y,counter;
	x=x0;
	y=y0;
	counter=0;
	/*while don't reach to the end of the string*/
	while(*c!='\0')
	{
		while(x<320 && (*c!='\0'))  /*while the X coordinate don't exceed the scope of X limit*/ 
		{
			ascii_1616(x,y,c,pencolor);  /*display the character*/
			x+=16;
			c+=1;
			counter+=1;
		}
        	x=0;    /*exchange the next row*/                                              
        	y+=16;
      	}
     return(counter);
}       

void get_hz(int x0,int y0,char incode[],int pencolor)                   
{	 
	  /*define the code group for compare the code*/
	  char mask[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
	  char mat[32];
	  char wh,qh;   /*the position code of the chinese characters*/
	  char *hzpos;
	  int i,j,k,m,offset;
	  /*get the position code from the ISN*/
	  qh=incode[0]-0xa0;
	  wh=incode[1]-0xa0;
	  /*get the excuriosn of chinese character and add it to the base address of chinese characters storeroom*/
	  offset=(94*(qh-1)+(wh-1))*32;
	  hzpos=(char *)(hzbufbase+offset);
	  /*get the chinese character lattice message*/
	  for (m=0;m<32;m++)
  	  {
  	  	  mat[m]=(*hzpos);
  		  hzpos++;
  	   }
  	   /*display the chinese character*/
  	  for (i=0;i<16;i++)
	  	for (j=0;j<2;j++)
	  		for (k=0;k<8;k++)
	  		{
	  		 	if (mask[k%8]&mat[2*i+j])
	  		 	{
	 			 setpixel(x0+2*(8*j+k),y0-2*i,pencolor);
//	 			 setpixel(x0+2*(8*j+k),y0-2*i-1,pencolor);
	 			 }
 	   		}
}
 
 
 int drawtext(int x0,int y0,char *c,int pencolor)             
{    
	int x,y,counter;
	x=x0;
	y=y0;
	counter=0;
	while(*c!='\0')
	{
		/*if don't reach to the end of the string display the character in LCD*/
		while(x<320 && (*c!='\0'))
		{
			get_hz(x,y,c,pencolor);  /*display the Chines character*/
			x+=32;
			c+=2;
			counter+=1;
		}
        	x=0;                                                
        	y+=32;
      	}
     return(counter);
}       
 

void Led1_On_or_Off(int flag)
{
 
 int temp;
 if(flag ==TRUE)    //led1 on
    {
     //set GPF4
     temp = rGPFCON;
     rGPFCON = temp |(1<<8);
     temp = rGPFDAT;
     rGPFDAT = temp&(0<<4);
     }
     else			//led1 off
     {
     //set GPF4
     temp = rGPFCON;
     rGPFCON = temp |(1<<8);
     temp = rGPFDAT;
     rGPFDAT = temp|(1<<4);
     }
 }


void Led2_On_or_Off(int flag)
{
 
 int temp;
 if(flag ==TRUE)    //led1 on
    {
     //set GPF4
     temp = rGPFCON;
     rGPFCON = temp |(1<<10);
     temp = rGPFDAT;
     rGPFDAT = temp&(0<<5);
     }
     else			//led1 off
     {
     //set GPF4
     temp = rGPFCON;
     rGPFCON = temp |(1<<10);
     temp = rGPFDAT;
     rGPFDAT = temp|(1<<5);
     }
 }

void Led3_On_or_Off(int flag)
{
 
 int temp;
 if(flag ==TRUE)    //led1 on
    {
     //set GPF4
     temp = rGPFCON;
     rGPFCON = temp |(1<<12);
     temp = rGPFDAT;
     rGPFDAT = temp&(0<<6);
     }
     else			//led1 off
     {
     //set GPF4
     temp = rGPFCON;
     rGPFCON = temp |(1<<12);
     temp = rGPFDAT;
     rGPFDAT = temp|(1<<6);
     }
 }

void Led4_On_or_Off(int flag)
{
 
 int temp;
 if(flag ==TRUE)    //led1 on
    {
     //set GPF4
     temp = rGPFCON;
     rGPFCON = temp |(1<<14);
     temp = rGPFDAT;
     rGPFDAT = temp&(0<<7);
     }
     else			//led1 off
     {
     //set GPF4
     temp = rGPFCON;
     rGPFCON = temp |(1<<14);
     temp = rGPFDAT;
     rGPFDAT = temp|(1<<7);
     }
 }

void EINT0_Enable(int flag)
{
	int temp;
	if(flag == TRUE)
	{
	}
	
}

⌨️ 快捷键说明

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