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

📄 ex17.c

📁 vxworksS3C44B0开发板有关cedn开发板资料VxWorks实验代码 LCD实验(需外扩LCD)
💻 C
字号:
/****************************************************************************/
//
//
// Created by Starlight Embeded Studio
//         www.cedn.cn
// If there are any concerns on the code
// go to www.cedn.cn for discussion
//
/****************************************************************************/

#include <stdio.h>
#include "44B.H"


#define SCR_XSIZE 320
#define SCR_YSIZE 240
#define SCR_LINE   40

//***************************************************************************
#define MVAL_USED (0)  
#define MVAL    (13)    
#define INVCLK    (0) 
#define INVFRAME  (0) 
#define INVLINE   (0)   
#define CLKVAL_SL (8)   //VCLK=MCLK/(CLKVAL*2)    (CLKVAL >= 2)
#define M5D(n) ((n) & 0x1fffff)
unsigned char Bmp[9600];    


void Delay(int time)
{
  static int DelayLoopCount = 500;
  int i,j=0;
  for(j=0;j<time;j++)
  for(i=0;i<DelayLoopCount;i++);  
}


void LcdInit(void)
{
  int i;
  for (i=0;i<sizeof(Bmp);i++) Bmp[i]=0xF0;
  rPCOND=0xaaaa;
  rLCDCON1=(2)|(INVFRAME<<2)|(INVLINE<<3)|(INVCLK<<4)|(1<<5)|(MVAL_USED<<7)|(1<<8)|(1<<10)|(CLKVAL_SL<<12);
    //下降沿装载视频数据,禁止视频输出,LCD FIFO清空;行、帧信号取反;
    //4位单扫描模式;WDLY=8clk,WLH=8clk,CLKVAL_SL=38
  rLCDCON2=(239)|(79<<10)|(10<<21);
    //垂直点数为240,水平点数320=(80字),LINEBLANK=10
  rLCDSADDR1= (0x0<<27) | ( ((unsigned int)Bmp>>22)<<21 ) | M5D((unsigned int)Bmp>>1);
    // 黑白模式, LCDBANK, LCDBASEU
  rLCDSADDR2= (1<<29) | (M5D((unsigned int)Bmp + ((320/8)*(240)))>>1) | (MVAL<<21);
  rLCDSADDR3= (320/16) | ( 0<<9 );   
  rLCDCON1=(1)|(INVFRAME<<2)|(INVLINE<<3)|(INVCLK<<4)|(1<<5)|(MVAL_USED<<7)|(1<<8)|(1<<10)|(CLKVAL_SL<<12);
}

void PortInit(void)
{
  //  PORT A GROUP
  /*  BIT   9   8   7   6   5   4   3   2   1   0 */
  /*  A24   A23 A22 A21 A20 A19 A18 A17 A16 A0  */        
  /*  0   1 1 1 1 1 1 1 1 1 */
  rPCONA = 0x0ff; 
  rPDATA = 0x0ff;

  // PORT B GROUP
  /*  BIT 10  9   8   7   6   5   4   3   2   1   0   */
  /*  /CS5  /CS4  /CS3  /CS2  /CS1  nWBE3 nWBE2 /SRAS /SCAS SCLK  SCKE  */
  /*  EXT   NIC   USB   IDE   SMC   NC    NC    Sdram Sdram Sdram Sdram */
  /*      0,        0,   0,   0,    1,    0,       0,     1,    1,    1,   1          */
  rPDATB = 0x7ff;
  rPCONB = 0x7ff;

         //改动 by yang 2003.5
  //PORT C GROUP
  //BUSWIDTH=16                         */
  /*  PC15    14    13    12    11    10    9   8 */
  /*  o   o   RXD1  TXD1  o   o   o   o */
  /*  NC    NC    Uart1 Uart1 NC    NC    NC    NC  */
  /*   01   01    11    11    01    01    01    01  */

  /*  PC7   6   5   4   3   2   1   0 */
  /*   o    o   o   o   o   o   o   o */
  /*   NC   NC    NC    NC    SMCALE  SMCCLE  SMCCE SMCRB*/
  /*   01   01    01    01    01    01    01    01  */
  rPDATC = 0x0000;  //All IO is low
  rPCONC = 0xfff45555;  
  rPUPC  = 0x3000;  //PULL UP RESISTOR should be enabled to I/O

  //PORT D GROUP
  /*  PORT D GROUP(I/O OR LCD)                    */
  /*  BIT7    6   5   4   3   2   1   0 */
  /*      VF    VM    VLINE VCLK  VD3   VD2   VD1   VD0 */
  /*     01   01    01    01    01    01    01    01  */
  rPDATD= 0x55;
  rPCOND= 0xaaaa; 
  rPUPD = 0x00;
  //These pins must be set only after CPU's internal LCD controller is enable
///////////////////////////////////////////////////// 
  //PORT E GROUP 
  /*  Bit 8   7   6   5   4   3   2   1   0   */
  /*    ENDLAN  LED3  LED2  LED1  LED0  BEEP  RXD0  TXD0  CLKOUT  */ 
  /*      00    01    01    01    01    01    10    10    01    */
  rPDATE  = 0x157;
  rPCONE  = 0x5528; 
  rPUPE = 0xff;
  
  //PORT F GROUP
  /*  Bit8    7   6   5    4    3   2   1   0   */   
  /*  IISCLK  IISDI IISDO IISLRCK Input Input Input IICSDA  IICSCL  */
  /*  100   010   010   001   00    01    01    10    10    */
  rPDATF = 0x0;
  rPCONF = 0x22401a;
  rPUPF  = 0x1d3;

  //PORT G GROUP
  /*  BIT7    6   5   4   3   2   1   0  */
  /*  INT7    INT6    INT5    INT4    INT3    INT2    INT1    INT0  */
  /*    S3    S4    S5    S6    NIC   EXT   IDE   USB */
  /*      11      11      11      11      11      11      11      11       */
  rPDATG = 0xFF;
  rPCONG = 0xFFFF;
  rPUPG  = 0x00;  //should be enabled  

  rSPUCR=0x7;  //D15-D0 pull-up disable

  /*定义非Cache区*/
  rNCACHBE0 = 0xc0002000; 

  /*所有的外部硬件中断为低电平触发*/
  rEXTINT=0x0044;
}

void PutPixel(int x,int y,int c)
{
    if(x<SCR_XSIZE && y<SCR_YSIZE)
	    Bmp[(y)*SCR_LINE+(x)/8]=( Bmp[(y)*SCR_LINE+(x)/8] & ~(0x80>>((x)%8)*1) )
            | ( (c)<< ((8-1-((x)%8))*1) );
}

void DrawLine(int x1,int y1,int x2,int y2,int 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)
				{
					PutPixel(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)
				{
					PutPixel(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)
				{
					PutPixel(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)
				{
					PutPixel(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)
				{
					PutPixel(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)
				{
					PutPixel(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)
				{
					PutPixel(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)
				{
					PutPixel(x1,y1,color);
					if(e>0){x1-=1;e-=dy;}	
					y1-=1; 					e+=dx;
				}
			}
		}	
	}
}
	
void DrawRect(int x1,int y1,int x2,int y2,int color)
{
    DrawLine(x1,y1,x2,y1,color);
    DrawLine(x2,y1,x2,y2,color);
    DrawLine(x1,y2,x2,y2,color);
    DrawLine(x1,y1,x1,y2,color);
}

void Test17()
{
  unsigned int i,j;
  PortInit();
  LcdInit();
  printf("\nStart LCD Test!\n");
  for (i=0;i<sizeof(Bmp);i++) Bmp[i]=00;


  while (1) {    
    for (i=0,j=0;i<160;i+=5,j+=3) {
      DrawRect(i,j,319-i,239-j,1);
      Delay(200);
    }
  
    for (;i>0;i-=5,j-=3) {
      DrawRect(i,j,319-i,239-j,0);
      Delay(200);
    }
  }
  printf("\nFinish LCD Test!\n");
}

⌨️ 快捷键说明

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