📄 main.c
字号:
#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"
#include "myplmm.h"
#include "plmm1.h"
#include "plmm2.h"
#include "plmm3.h"
#include "plmm4.h"
/**************这里不用虚拟屏幕,所以SCR_XSIZE=LCD_XSIZE; SCR_YSIZE=LCD_XSIZE ***********/
#define SCR_XSIZE (320)
#define SCR_YSIZE (240)
#define LCD_XSIZE (320)
#define LCD_YSIZE (240)
#define M5D(n) ((n) & 0x1fffff)
/**************** 定义 4 种模式的每行数据量 *************************/
#define ARRAY_SIZE_MONO (SCR_XSIZE/8*SCR_YSIZE)
#define ARRAY_SIZE_G4 (SCR_XSIZE/4*SCR_YSIZE)
#define ARRAY_SIZE_G16 (SCR_XSIZE/2*SCR_YSIZE)
#define ARRAY_SIZE_COLOR (SCR_XSIZE/1*SCR_YSIZE)
#define HOZVAL (LCD_XSIZE/4-1)
#define HOZVAL_COLOR (LCD_XSIZE*3/8-1)
#define LINEVAL (LCD_YSIZE-1)
#define MVAL (13)
/************** 每种模式扫描频率定义****************************/
#define CLKVAL_MONO (13) //60Mhz, CLKVAL=19 ->78.6Hz
#define CLKVAL_G4 (13) //60Mhz, CLKVAL=19 ->78.6Hz
#define CLKVAL_G16 (13) //60Mhz, CLKVAL=19 ->78.6Hz
#define CLKVAL_COLOR (10) //60Mhz, CLKVAL=19 ->78.6Hz
/*************************************************/
#define XTOTAL 256
#define YTOTAL 320
#define EVERYX 32
#define HIGHB 32
unsigned int (*frameBuffer1)[SCR_XSIZE/32];
unsigned int (*frameBuffer4)[SCR_XSIZE/16];
unsigned int (*frameBuffer16)[SCR_XSIZE/8];
unsigned int (*frameBuffer256)[SCR_XSIZE/4];
///////////////////////////////////////////////////////////
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
////////////////////////////
void Lcd_MonoInit(void);
void displaylcd(char num);
void displaylcd32(char x, char y, char num);
void clear(void);
void Lcd_kb_MonoInit_one(void);
void kb_displaylcd(unsigned short int type);
/////////////////////////////
void Main(void)
{
U8 which_key;
U8 aa;
unsigned short int type=0, i=0,j=0;
rSYSCFG=SYSCFG_8KB;
#if (PLLON==1)
ChangePllValue(PLL_M,PLL_P,PLL_S);
#endif
Isr_Init();
Port_Init();
Uart_Init(0,115200);
Uart_Select(0);
Delay(0); //calibrate Delay()
Led_Display(7);
Delay(1000); //calibrate Delay()
Led_Display(0);
Delay(5000); //calibrate Delay()
Led_Display(7);
rPCONG=0x00ff; //EINT7~0
rPUPG=0x0; //pull up enable
Lcd_kb_MonoInit_one();
clear();
Uart_Printf("\n now let's start, enter a key please,you can see a picture in lcd \n");
Uart_Printf(" press any key return\n");
while(!Uart_GetKey())
{
while((rPDATG & 0xf0)==0xf0 && type==0)
{
for (i=7; i<12; i++)
{
displaylcd32(j, 228, 15); // clear the last one bmp
j=(i-7)*16;
displaylcd32(j, 228, i);
if ((rPDATG & 0xf0) !=0xf0)
{ break ;}
Delay(2200);
}
for (i=12; i<17; i++)
{
displaylcd32(j, 228, 15); // clear the last one bmp
j=(i-7)*16;
displaylcd32(j, 228, i-5);
if ((rPDATG & 0xf0) !=0xf0)
{ break ;}
Delay(2200);
}
for (i=17; i<22; i++)
{
displaylcd32(j, 228, 15); // clear the last one bmp
j=(i-7)*16;
displaylcd32(j, 228, i-10);
if ((rPDATG & 0xf0) !=0xf0)
{ break ;}
Delay(2200);
}
for (i=22; i<24; i++)
{
displaylcd32(j, 228, 15); // clear the last one bmp
j=(i-7)*16;
displaylcd32(j, 228, i-15);
if ((rPDATG & 0xf0) !=0xf0)
{ break ;}
Delay(2200);
}
}
which_key=rPDATG&0xf0;
if (which_key >0 && type ==0)
{
Lcd_MonoInit();
type=1;
}
switch(which_key)
{
case 0xe0: kb_displaylcd(0x1);
break;
case 0xd0:
kb_displaylcd(0x2);
break;
case 0xb0:
kb_displaylcd(0x3);
break;
case 0x70:
kb_displaylcd(0x4);
break;
default :
break;
}
}
}
void Lcd_MonoInit(void)
{
//160x240 1bit/1pixel LCD
#define MVAL_USED 0
if((U32)frameBuffer16==0)
{
if (( frameBuffer16=(unsigned int (*)[SCR_XSIZE/8])malloc(ARRAY_SIZE_G16))==NULL)
{
Uart_Printf("ERROR !!!!!!!! NO MEMERY !!!!!!! \n");
}
else
{
Uart_Printf("ARRAY_SIZE_g16= %d \n", ARRAY_SIZE_G16);
}
}
rLCDCON1=(0)|(1<1)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_G16<<12);
// disable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
rLCDCON2=(LINEVAL)|(HOZVAL<<10)|(10<<21);
//LINEBLANK=10 (without any calculation)
rLCDSADDR1= (0x2<<27) | ( ((U32)frameBuffer16>>22)<<21 ) | M5D((U32)frameBuffer16>>1);
// 16-lever gray mode , LCDBANK, LCDBASEU
rLCDSADDR2= M5D (((U32)frameBuffer16+(SCR_XSIZE*(LINEVAL+1))/2)>>1) | (MVAL<<21) |(0<<29);//MVAL
// 4*SCR_XSIZE*LCD_YSIZE/8
rLCDSADDR3= (LCD_XSIZE/4) | ( ((SCR_XSIZE-LCD_XSIZE)/4)<<9 );
rLCDCON1=(1)|(1<<1)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_G16<<12);
// enable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
}
void Lcd_kb_MonoInit_one(void)
{
//160x240 1bit/1pixel LCD
#define MVAL_USED 0
if((U32)frameBuffer1==0)
{
if (( frameBuffer1=(unsigned int (*)[SCR_XSIZE/32])malloc(256/8*SCR_YSIZE))==NULL)
{
Uart_Printf("ERROR !!!!!! NO MEMERY !!!!!!!!! \n");
}
}
rLCDCON1=(0)|(1<<5)|(0<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_MONO<<12);
// disable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
rLCDCON2=(LINEVAL)|(256/4-1<<10)|(10<<21);
//LINEBLANK=10 (without any calculation)
rLCDSADDR1= (0x0<<27) | ( ((U32)frameBuffer1>>22)<<21 ) | M5D((U32)frameBuffer1>>1);
// monochrome, LCDBANK, LCDBASEU
rLCDSADDR2= M5D( (((U32)frameBuffer1+(256*LCD_YSIZE/8))>>1) ) | (MVAL<<21);
rLCDSADDR3= (256/16) | ( ((SCR_XSIZE-LCD_XSIZE)/16)<<9 );
rLCDCON1=(1)|(1<<5)|(0<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_MONO<<12);
// enable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
}
void displaylcd32(char x, char y, char num)
{
unsigned int *pbuffer,temp_data;
unsigned int i=0, j=0, m=0;
pbuffer =(U32*) frameBuffer1;
for(m=0; m<HIGHB; m++)
{
i = (y+m)*XTOTAL/EVERYX+x/EVERYX;
//Uart_Printf("the i is : %x \n", i);
temp_data = (Bitmap32[num][m*4] << 24) + (Bitmap32[num][m*4+1] << 16) + (Bitmap32[num][m*4+2] << 8) +(Bitmap32[num][m*4+3]);
j=(pbuffer[i]>>(EVERYX- x%EVERYX))<<(EVERYX-x%EVERYX);
pbuffer[i]=j|(temp_data>>(x%EVERYX));
//Uart_Printf("pbuffer[%d]= %x \n", i, pbuffer[i]);
j=(pbuffer[i+1]<<(x%EVERYX))>>(x%EVERYX);
pbuffer[i+1] = j|(temp_data<<(EVERYX-x%EVERYX)); // ~temp_data;
// Uart_Printf("pbuffer[%d]= %x \n", i+1, pbuffer[i+1]);
}
}
void clear(void)
{
unsigned int *pbuffer;
int i;
pbuffer =(U32*) frameBuffer1;
for(i = 0; i< (9600/4) ;i++)
{
pbuffer[i] = 0;
}
}
void kb_displaylcd(unsigned short int type)
{
unsigned int *pbuffer,temp_data;
int i,j=0;
pbuffer =(U32*) frameBuffer16;
clear();
if (type==1)
{
for(i = 0; i< (38400/4) ;i++)
{
temp_data = (plmmBitmap1[i*4] << 24) + (plmmBitmap1[i*4+1] << 16) + (plmmBitmap1[i*4+2] << 8) +(plmmBitmap1[i*4+3]);
pbuffer[i] = temp_data;
}
}
if (type==2)
{
for(i = 0; i< (38400/4) ;i++)
{
temp_data = (plmmBitmap2[i*4] << 24) + (plmmBitmap2[i*4+1] << 16) + (plmmBitmap2[i*4+2] << 8) +(plmmBitmap2[i*4+3]);
pbuffer[i] = temp_data;
}
}
if (type==3)
{
for(i = 0; i< (38400/4) ;i++)
{
temp_data = (plmmBitmap3[i*4] << 24) + (plmmBitmap3[i*4+1] << 16) + (plmmBitmap3[i*4+2] << 8) +(plmmBitmap3[i*4+3]);
pbuffer[i] = temp_data;
}
}
if (type==4)
{
for(i = 0; i< (38400/4) ;i++)
{
temp_data = (plmmBitmap4[i*4] << 24) + (plmmBitmap4[i*4+1] << 16) + (plmmBitmap4[i*4+2] << 8) +(plmmBitmap4[i*4+3]);
pbuffer[i] = temp_data;
}
}
}
/******************************************************************/
void Isr_Init(void)
{
U32 i;
pISR_UNDEF=(unsigned)HaltUndef;
pISR_SWI =(unsigned)HaltSwi;
pISR_PABORT=(unsigned)HaltPabort;
pISR_DABORT=(unsigned)HaltDabort;
for(i=_RAM_STARTADDRESS;i<(_RAM_STARTADDRESS+0x20);i+=4)
{
*((volatile unsigned *)i)=0xEA000000+0x1FFE;
}
rINTCON=0x5; // Non-vectored,IRQ enable,FIQ disable
rINTMOD=0x0; // All=IRQ mode
rINTMSK|=BIT_GLOBAL|BIT_EINT3; // All interrupt is masked.
}
void HaltUndef(void)
{
Uart_Printf("Undefined instruction exception!!!\n");
while(1);
}
void HaltSwi(void)
{
Uart_Printf("SWI exception!!!\n");
while(1);
}
void HaltPabort(void)
{
Uart_Printf("Pabort exception!!!\n");
while(1);
}
void HaltDabort(void)
{
Uart_Printf("Dabort exception!!!\n");
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -