📄 main.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"
#include "2410lib.h"
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);
void INT_ADC_Enable(int flag);
int LCD_Init(void);
unsigned short rgb(int red,int green,int blue);
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* main */
/* */
/* 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 main()
{
int i,j,k;
ChangeClockDivider(1,1); // 1:2:4
ChangeMPllValue(0xa1,0x3,0x1); // FCLK=202.8MHz
Port_Init();
__vInitHaltHandlers();
CONSOL_Select(0);
CONSOL_Init(115200);
LCD_Init();
clrsrc(rgb(0,0,255));
drawtext(15,160,"嵌入式实验教学系统",rgb(255,255,0));
drawtext(95,110,"深圳旋极",rgb(255,255,0));
do
{
Led4_On_or_Off(TRUE);
for(i=0;i++<1000000;);
Led4_On_or_Off(FALSE);
for(i=0;i++<1000000;);
}while(1);
}
void INT_ADC_Enable(int flag)
{
int temp;
if(flag == FALSE)
{
temp = rINTSUBMSK;
temp |=(1<<10);
rINTSUBMSK = temp;
temp = rINTMSK;
temp |=0x80000000;
rINTMSK = temp;
}
else
{
temp = rINTSUBMSK;
temp = 0x5ff;
rINTSUBMSK = temp;
temp = rINTMSK;
temp &= ~(0x80000000) ;
rINTMSK = temp;
}
}
int LCD_Init(void)
{
rLCDCON2=0x14FC081;
rLCDCON3=0x188EF0F;
rLCDCON4=0xD;
rLCDCON5=0xB09;
rLCDSADDR1=0x18000000;
rLCDSADDR2=0x9600;
rLCDCON1=0x477;
rLCDSADDR3=0x0;
rREDLUT=0x0;
rGREENLUT=0x0;
rBLUELUT=0x0;
rDITHMODE=0x0;
rTPAL=0x0;
rLCDINTPND=0x0;
rLCDSRCPND=0x0;
rLCDINTMSK=0x3;
rLPCSEL=0x4;
rADCTSC=0xD3;
rADCDLY=0xff;
INT_ADC_Enable(TRUE);
return 0;
}
/****************************************************************************
* 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
*
*
****************************************************************************/
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);
}
}
}
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 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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -