|
发表于 2012-7-22 17:26:32
|
显示全部楼层
zyp000 发表于 2012-7-22 12:39 ![](static/image/common/back.gif)
额,DAT那个,是我发帖时打字打错了,应该是UP的。
上拉我试过,开启或关闭,现象基本一样的。
GPDCON = ...
当然,不知道能不能入得了您的法眼
lcd480x272.c
#include "lcd480x272.h"
#include "s3c24x0.h"
#include "font.h"
#include "hzk.h"
#include "globl_def.h"
static unsigned short LCD_BUFF[LCD_480X272_YSIZE][LCD_480X272_XSIZE];
//#define LCD_BUFF ((unsigned long *)0x30008000)
extern char hzk16x16tab[];
static void s3c_init_lcdport (void)
{
rGPCUP = 0;
rGPCCON = 0xaaaa56a9;
rGPDUP = 0;
rGPDCON = 0xaaaaaaaa;
}
static void s3c_init_lcdreg (void)
{
rLCDCON1 = (CLKVAL_480X272 << 8) | (0<<7) | (TFT << 5) | (MODE16BPP << 1) | 0;
rLCDCON2 = (VBPD_480X272 << 24) | (LINEVAL_480X272 << 14) | (VFPD_480X272 << 6) | (VSPW_480X272);
rLCDCON3 = (HBPD_480X272 << 19) | (HOZVAL_480X272 << 8) | (HFPD_480X272);
rLCDCON4 = (MVAL_480X272 << 8) | (HSPW_480X272);
rLCDCON5 = (RGB565 << 11) /*| (1<<10)*/ | (INVVLINE << 9) | (FRAME << 8) | (0<<6) | (PWREN << 3) | (0<<1) | (HWSWP_480X272);
rLCDSADDR1 = (((U32)LCD_BUFF>>22) << 21) | M5D ( (U32)LCD_BUFF >> 1);
rLCDSADDR2 = M5D( ( (U32)LCD_BUFF + (LCD_480X272_XSIZE*LCD_480X272_YSIZE*2) ) >> 1);
rLCDSADDR3 = (( (LCD_480X272_XSIZE - LCD_480X272_XSIZE)/1 ) << 11) | (LCD_480X272_XSIZE/1);
rLCDINTMSK |= 3;
rTPAL = 0;
}
void put_pixel (U32 x, U32 y, U16 c)
{
if ((x < LCD_480X272_XSIZE) && (y < LCD_480X272_YSIZE))
LCD_BUFF[y][x] = c;
//*((U16 *)LCD_BUFF + y*LCD_480X272_XSIZE+x) = c;
}
static void put_ascii (U32 x, U32 y, U16 c, char *dat)
{
U8 i, j, temp;
U8 *idx;
idx = &ascii8x16_tab[dat[0]-0x20] [0];
for (i=0; i<16; i++)
{
temp = *idx++;
for (j=0; j<8; j++)
{
if (temp & 0x80)
put_pixel (x+j, y+i, c);
else
put_pixel (x+j, y+i, 0xffff); // white background
temp <<= 1;
}
}
}
static void put_hz (U32 x, U32 y, U32 c, char *dat)
{
U16 i, j, tmp;
U32 idx;
i = dat[0] - 0xa0;
j = dat[1] - 0xa0;
idx = (94*(i-1)+(j-1))*32; // get neima of the hz
for (i=0; i<16; i++)
{
tmp = hzk16x16tab[idx+2*i];
tmp *= 0x100;
tmp |= hzk16x16tab[idx+2*i+1];
for (j=0; j<16; j++)
{
if (tmp & 0x8000)
put_pixel (x+j, y+i, c);
else
put_pixel (x+j, y+i, 0);
tmp <= 1;
}
}
}
void put_asciistr_to_lcd (U32 x, U32 y, U16 c, char *str) // *str 为字符串
{
U8 i=0;
while (str != 0x00)
{
put_ascii (x, y, c, &str);
i += 1;
x += 8;
if (x >= LCD_480X272_XSIZE)
{
x = 0;
y += 16;
}
}
}
void put_hzstr_to_lcd (U32 x, U32 y, U32 c, char *str)
{
U8 i=0;
while (str != 0x00)
{
put_hz (x, y, c, &str);
i += 2;
x += 16;
if (x >= LCD_480X272_XSIZE)
{
x = 0;
y += 16;
}
}
}
void lcd_clr (U16 c)
{
volatile U32 x,y;
for (y=0; y<LCD_480X272_YSIZE; y++)
{
for (x=0; x<LCD_480X272_XSIZE; x++)
{
LCD_BUFF[y][x] = c;
}
//*((U16 *)LCD_BUFF + y*LCD_480X272_XSIZE+x) = c;
}
}
static void lcd_envid_onoff (int onoff)
{
if (onoff == 1)
rLCDCON1 |= 1;
else
rLCDCON1 &= 0x3fffe;
}
void s3c_init_lcd (void)
{
s3c_init_lcdport();
s3c_init_lcdreg();
lcd_envid_onoff(1);
}
/*
U16 RGB565_Alpha(U16 FrColor,U16 BkColor ,U8 Alpha)
{
int R,G,B,R0,G0,B0,R1,G1,B1;
U32 Alpha0,Alpha1;
////
R0 =(FrColor>>11)&0x1f;
G0 =(FrColor>>5)&0x3f;
B0 =(FrColor&0x1f);
R1 =(BkColor>>11)&0x1f;
G1 =(BkColor>>5)&0x3f;
B1 =(BkColor&0x1f);
Alpha0 =256-Alpha;
Alpha1 =Alpha;
R =(R0*Alpha0+R1*Alpha1)>>8;
G =(G0*Alpha0+G1*Alpha1)>>8;
B =(B0*Alpha0+B1*Alpha1)>>8;
return rgb565(R,G,B);
}
*/
static void Glib_Line(int x1,int y1,int x2,int y2, U16 color)
{
int dx,dy,e;
dx=x2-x1;
dy=y2-y1;
if(dx>=0)
{
if(dy >= 0) // dy>=0
{
if(dx>=dy) // 1/8 octant
{
e=dy-dx/2;
while(x1<=x2)
{
put_pixel(x1,y1,color);
if(e>0){y1+=1;e-=dx;}
x1+=1;
e+=dy;
}
}
else // 2/8 octant
{
e=dx-dy/2;
while(y1<=y2)
{
put_pixel(x1,y1,color);
if(e>0){x1+=1;e-=dy;}
y1+=1;
e+=dx;
}
}
}
else // dy<0
{
dy=-dy; // dy=abs(dy)
if(dx>=dy) // 8/8 octant
{
e=dy-dx/2;
while(x1<=x2)
{
put_pixel(x1,y1,color);
if(e>0){y1-=1;e-=dx;}
x1+=1;
e+=dy;
}
}
else // 7/8 octant
{
e=dx-dy/2;
while(y1>=y2)
{
put_pixel(x1,y1,color);
if(e>0){x1+=1;e-=dy;}
y1-=1;
e+=dx;
}
}
}
}
else //dx<0
{
dx=-dx; //dx=abs(dx)
if(dy >= 0) // dy>=0
{
if(dx>=dy) // 4/8 octant
{
e=dy-dx/2;
while(x1>=x2)
{
put_pixel(x1,y1,color);
if(e>0){y1+=1;e-=dx;}
x1-=1;
e+=dy;
}
}
else // 3/8 octant
{
e=dx-dy/2;
while(y1<=y2)
{
put_pixel(x1,y1,color);
if(e>0){x1-=1;e-=dy;}
y1+=1;
e+=dx;
}
}
}
else // dy<0
{
dy=-dy; // dy=abs(dy)
if(dx>=dy) // 5/8 octant
{
e=dy-dx/2;
while(x1>=x2)
{
put_pixel(x1,y1,color);
if(e>0){y1-=1;e-=dx;}
x1-=1;
e+=dy;
}
}
else // 6/8 octant
{
e=dx-dy/2;
while(y1>=y2)
{
put_pixel(x1,y1,color);
if(e>0){x1-=1;e-=dy;}
y1-=1;
e+=dx;
}
}
}
}
}
/**************************************************************
在LCD屏幕上画一个矩形
**************************************************************/
void Glib_Rectangle(int x1,int y1,int x2,int y2, U16 color)
{
Glib_Line(x1,y1,x2,y1,color);
Glib_Line(x2,y1,x2,y2,color);
Glib_Line(x1,y2,x2,y2,color);
Glib_Line(x1,y1,x1,y2,color);
}
/**************************************************************
在LCD屏幕上用颜色填充一个矩形
**************************************************************/
void Glib_FillRectangle(int x1,int y1,int x2,int y2, U16 color)
{
int i;
for(i=y1;i<=y2;i++)
Glib_Line(x1,i,x2,i,color);
}
#if 0
/**************************************************************
在LCD屏幕上指定坐标点画一个指定大小的图片
**************************************************************/
static void Paint_Bmp(int x0,int y0,int h,int l,unsigned char bmp[])
{
int x,y;
U32 c;
int p = 0;
for( y = 0 ; y < l ; y++ )
{
for( x = 0 ; x < h ; x++ )
{
c = bmp[p+1] | (bmp[p]<<8) ;
if ( ( (x0+x) < SCR_XSIZE) && ( (y0+y) < SCR_YSIZE) )
LCD_BUFFER[y0+y][x0+x] = c ;
p = p + 2 ;
}
}
}
/**************************************************************
**************************************************************/
void TFT_LCD_Init(void)
{
LCD_Init();
LcdBkLtSet( 70 ) ;
Lcd_PowerEnable(0, 1);
Lcd_EnvidOnOff(1); //turn on vedio
Lcd_ClearScr( (0x00<<11) | (0x00<<5) | (0x00) );
#if LCD_TYPE==LCD_TYPE_N35
Paint_Bmp(0, 0, 240, 320, sunflower_240x320);
#elif LCD_TYPE==LCD_TYPE_A70
Paint_Bmp(0, 0, 800, 480, sunflower_800x480);
#elif LCD_TYPE==LCD_TYPE_VGA1024x768
Paint_Bmp(0, 0, 1024, 768, sunflower_1024x768);
#endif
}
/**************************************************************
**************************************************************/
void TFT_LCD_Test(void)
{
#if LCD_TYPE==LCD_TYPE_N35
Uart_Printf("\nTest TFT LCD 240x320!\n");
#elif LCD_TYPE==LCD_TYPE_A70
Uart_Printf("\nTest TFT LCD 800×480!\n");
#elif LCD_TYPE==LCD_TYPE_VGA1024x768
Uart_Printf("\nTest VGA 1024x768!\n");
#endif
Lcd_Port_Init();
LCD_Init();
Lcd_EnvidOnOff(1); //turn on vedio
Lcd_ClearScr( (0x00<<11) | (0x00<<5) | (0x00) ) ; //clear screen
Uart_Printf( "\nLCD clear screen is finished! press any key to continue!\n" );
Uart_Getch() ; //wait uart input
Lcd_ClearScr( (0x1f<<11) | (0x3f<<5) | (0x1f) ) ; //clear screen
Uart_Printf( "LCD clear screen is finished! press any key to continue!\n" );
Uart_Getch() ; //wait uart input
Lcd_ClearScr(0xffff); //fill all screen with some color
#define LCD_BLANK 30
#define C_UP ( LCD_XSIZE - LCD_BLANK*2 )
#define C_RIGHT ( LCD_XSIZE - LCD_BLANK*2 )
#define V_BLACK ( ( LCD_YSIZE - LCD_BLANK*4 ) / 6 )
Glib_FilledRectangle( LCD_BLANK, LCD_BLANK, ( LCD_XSIZE - LCD_BLANK ), ( LCD_YSIZE - LCD_BLANK ),0x0000); //fill a Rectangle with some color
Glib_FilledRectangle( (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*0), (C_RIGHT), (LCD_BLANK*2 + V_BLACK*1),0x001f); //fill a Rectangle with some color
Glib_FilledRectangle( (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*1), (C_RIGHT), (LCD_BLANK*2 + V_BLACK*2),0x07e0); //fill a Rectangle with some color
Glib_FilledRectangle( (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*2), (C_RIGHT), (LCD_BLANK*2 + V_BLACK*3),0xf800); //fill a Rectangle with some color
Glib_FilledRectangle( (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*3), (C_RIGHT), (LCD_BLANK*2 + V_BLACK*4),0xffe0); //fill a Rectangle with some color
Glib_FilledRectangle( (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*4), (C_RIGHT), (LCD_BLANK*2 + V_BLACK*5),0xf81f); //fill a Rectangle with some color
Glib_FilledRectangle( (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*5), (C_RIGHT), (LCD_BLANK*2 + V_BLACK*6),0x07ff); //fill a Rectangle with some color
Uart_Printf( "LCD color test, please look! press any key to continue!\n" );
Uart_Getch() ; //wait uart input
#if LCD_TYPE==LCD_TYPE_N35
Paint_Bmp(0, 0, 240, 320, sunflower_240x320);
#elif LCD_TYPE==LCD_TYPE_A70
Paint_Bmp(0, 0, 800, 480, sunflower_800x480);
#elif LCD_TYPE==LCD_TYPE_VGA1024x768
Paint_Bmp(0, 0, 1024, 768, sunflower_1024x768);
#endif
Uart_Printf( "LCD paint a bmp, please look! press any key to continue! \n" );
Uart_Getch() ; //wait uart input
Lcd_EnvidOnOff(0); //turn off vedio
}
//*************************************************************
#endif
lcd480x272.h
#ifndef _lcd_h_
#define _lcd_h_
#include "globl_def.h"
#define M5D(n) (n & 0x1fffff)
#define LCD_480X272_XSIZE (480)
#define LCD_480X272_YSIZE (272)
#define HOZVAL_480X272 (LCD_480X272_XSIZE - 1)
#define LINEVAL_480X272 (LCD_480X272_YSIZE - 1)
#define CLKVAL_480X272 (3)
#define MVAL_480X272 (13)
#define HWSWP_480X272 (1)
#define VBPD_480X272 (1) // 垂直同步信号的后肩
#define VFPD_480X272 (5) // 垂直同步信号的前肩
#define VSPW_480X272 (9) // 垂直同步信号的脉宽
#define HBPD_480X272 (1) // 水平同步信号
#define HFPD_480X272 (1)
#define HSPW_480X272 (40)
#define TFT (3)
#define MODE16BPP (12)
#define RGB565 (1)
#define INVVLINE (1)
#define FRAME (1)
#define PWREN (1)
#define rgb565(r,g,b) (((r>>3)<<11)|((g>>2)<<5)|(b>>3))
void lcd_clr (U16 c);
void put_pixel (U32 x, U32 y, U16 c);
void put_asciistr_to_lcd (U32 x, U32 y, U16 c, char *str);
void put_hzstr_to_lcd(U32 x, U32 y, U32 c, char *str);
void Glib_Rectangle(int x1,int y1,int x2, int y2, U16 color);
void Glib_FillRectangle(int x1, int y1, int x2, int y2, U16 color);
#endif
|
|