實驗目的:
1.瞭解 LCD 的基本概念和工作原理。
2.理解 LCD 控制器顯示的原理。
3.熟悉 LCD 驅動程式的基本框架。
4.熟悉 LCD 驅動程式與應用程式的介面。
5.掌握 LCD 顯示圖形,圖片,文字的基本方法。
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2410addr.h"
#include "2410lib.h"
#include "2410slib.h"
#include "mmu.h"
#include "lcdlib.h"
#include "lab.h"
void * function[][2]=
{
(void *)Lab_Graphic, "LCD Test Lab",
(void *)Lab_Bitmap, "Bitmap Display Lab",
(void *)Lab_Text, "Text Display Lab",
0,0
};
extern __rt_lib_init(void);
void Main(void)
{
int i,j;
// MMU_Init();
#if ADS10
__rt_lib_init(); //for ADS 1.0
#endif
ChangeClockDivider(1,1); // 1:2:4
ChangeMPllValue(0xa1,0x3,0x1); // FCLK=202.8MHz
Port_Init();
rINTMOD = 0x0; //All=IRQ mode
rINTMSK = BIT_ALLMSK; //All interrupt is masked.
rINTSUBMSK = BIT_SUB_ALLMSK; //All sub-interrupt is masked. <- April 01, 2002
SOP
Uart_Init(0,115200);
Uart_Select(0);
rIISPSR=(2<<5)|(2<<0); //IIS_LRCK=44.1Khz @384fs,PCLK=50Mhz.
rGPHCON = rGPHCON & ~(0xf<<18)|(0x5<<18); //CLKOUT 0,1=OUTPUT to reduce the
power consumption.
rGPCUP=0xffffffff; // Disable Pull-up register
rGPCCON=0xaaaaaaaa; //Initialize VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND
rGPDUP=0xffffffff; // Disable Pull-up register
rGPDCON=0xaaaaaaaa; //Initialize VD[23:8]
Lcd_Init();
Lcd_PowerEnable(0, 1);
rLCDCON1|=1; // ENVID=ON
while(1)
{
i = 0;
Lcd_ClearScr(0);
Uart_Printf("\n");
Uart_Printf("\n");
Uart_Printf("\n");
Uart_Printf("\n");
Uart_Printf("\n");
Uart_Printf("\n");
Uart_Printf("YFARM9-EDU-I LCD Driver LAB Menu:\n");
Uart_Printf("\n");
while(1)
{ //display menu
Uart_Printf("%2d:%s",i,function[i][1]);
i++;
if((int)(function[i][0])==0)
{
Uart_Printf("\n");
break;
}
Uart_Printf("\n");
}
Uart_Printf("\nPlease Choose: ");
i = Uart_GetIntNum();
Uart_Printf("\n");
//GPG4 Output Port [9:8] 01 -> LCD power On
rGPGCON = (rGPGCON & 0xfffffcff) | (1<<8);
rGPGDAT = (rGPGDAT & 0xffef) | (1<<4);
j = (sizeof(function)/8);
if(i>=0 && (i<(j-1)) )
( (void (*)(void)) (function[i][0]) )();
}
}
#include <string.h>
#include "2410addr.h"
#include "2410lib.h"
#include "def.h"
#include "lcdlib.h"
#include "lab.h"
void Lab_Graphic(void)
{
int i,j,k;
Uart_Printf("\n[LCD Test Lab]\n");
Uart_Printf("\n");
Lcd_ClearScr(LCD_BLACK);
Lcd_FillRect(0,0,239,159,LCD_RED);
Lcd_FillRect(0,160,239,320,LCD_RED);
Uart_Printf("\nLCD Test 1. Press any key!\n");
Uart_Getch();
Lcd_ClearScr(LCD_BLACK);
Lcd_Rect(0,0,239,319,LCD_GREEN);
Lcd_FillRect(0,0,20,20,LCD_WHITE);
Lcd_Rect(220,300,239,319,LCD_WHITE);
Lcd_Line(0,0,239,319,LCD_BLUE);
Lcd_Line(239,0,0,319,LCD_RED);
Uart_Printf("\nLCD Test 2. Press any key!\n");
Uart_Getch();
Lcd_ClearScr(0);
k=0;
for(i=80;i<240;i+=10)
{
for(j=60;j<180;j+=10)
{
Lcd_FillRect(j,i,j+9,i+9,k);
k++;
}
}
Lcd_Rect(0,0,239,319,LCD_WHITE);
Lcd_Line(0,0,239,319,LCD_WHITE);
Lcd_Line(0,319,239,0,LCD_WHITE);
Lcd_Rect(0+240,0,239+240,319,255);
Lcd_Line(0+240,0,239+240,319,255);
Lcd_Line(0+240,319,239+240,0,255);
Lcd_Rect(0,0+320,239,319+320,255);
Lcd_Line(0,0+320,239,319+320,255);
Lcd_Line(0,319+320,239,0+320,255);
Lcd_Rect(0+240,0+320,239+240,319+320,255);
Lcd_Line(0+240,0+320,239+240,319+320,255);
Lcd_Line(0+240,319+320,239+240,0+320,255);
Lcd_Rect(40+240,40+320,480-41,640-41,LCD_BLUE);
Uart_Printf("\nLCD Test 3(Virtual Screen Test). Press any key( j or k )!\n");
Uart_Printf("Press ENTER key to exit !\n");
MoveViewPort();
Lcd_MoveViewPort(0,0);
}
void Lab_Text(void)
{
Uart_Printf("\n[Text Display Lab]\n");
Uart_Printf("\n");
Lcd_ClearScr(0);
Uart_Printf("\nDisplay English Text ! Press any key to continue...!\n");
Lcd_Printf(70,100,LCD_RED,"YFARM9-EDU-I ");
Lcd_Printf(10,150,LCD_GREEN,"Ta Hwa Institute of College ");
Lcd_Printf(20,200,LCD_BLUE,"Http://www.thit.edu.tw ");
Uart_Getch();
Lcd_ClearScr(0);
Uart_Printf("\nDisplay Chinese Text ! Press any key to continue...!\n");
Lcd_Printf(10,100,LCD_BLUE,"YFARM9-EDU-I 實驗板");
Lcd_Printf(10,150,LCD_RED,"大華技術學院電機系");
Lcd_Printf(10,200,LCD_GREEN,"網址:http://www.ee.thit.edu.tw");
Uart_Getch();
}
extern const unsigned char uc240x320Bitmap1[];
extern const unsigned char uc240x320Bitmap2[];
extern const unsigned char uc320x240Bitmap1[];
extern const unsigned char uc320x240Bitmap2[];
extern const unsigned char ucheBitmap[];
void Lab_Bitmap(void)
{
Uart_Printf("\n[ Bitmap Display Lab]\n");
Uart_Printf("\n");
Lcd_ClearScr(0);
Uart_Printf("\nDisplay Bitmap1( 240x320 ) ! Press any key to continue... \n");
Lcd_Bitmap240x320(uc240x320Bitmap1);
Uart_Getch();
Uart_Printf("\nDisplay Bitmap2( 240x320 ) ! Press any key to continue... \n");
Lcd_Bitmap240x320(uc240x320Bitmap2);
Uart_Getch();
Uart_Printf("\nDisplay Bitmap1( 320x240 ) ! Press any key to continue... \n");
Lcd_Bitmap320x240(uc320x240Bitmap1);
Uart_Getch();
Uart_Printf("\nDisplay Bitmap2( 320x240 ) ! Press any key to continue... \n");
Lcd_Bitmap320x240(uc320x240Bitmap2);
Uart_Getch();
Uart_Printf("\nDisplay Bitmap2( 320x240 ) ! Press any key to continue... \n");
Lcd_Bitmap320x240(ucheBitmap);
Uart_Getch();
}