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

📄 graphics.c

📁 在Freescale16位单片机MC9s12dp256上移植了J1939源码和操作系统(ucOSII)。
💻 C
📖 第 1 页 / 共 3 页
字号:
 /*-------------------------------------------------------------------*/
 /*    GRAPHICS.C																											*/
 /*-------------------------------------------------------------------*/
 /*    Copyright (C) 2006, By ZhaiGang																*/
 /*																																		*/
 /*    Function: LCD Graphics Functions       												*/
 /*-------------------------------------------------------------------*/
 
/**************************************************/
/*包含的头文件。                                 	*/
/**************************************************/
#include <stdlib.h> 
#include "Graphics.h"
#include "Hzk16.h"
#include "Picture.h"
 
/**************************************************/
/*位。定义一个字节,用于位操作。                	*/
/**************************************************/
const unsigned char vLcdBit[8]=
  {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
  
 
unsigned int vLcdRow,vLcdCol,HzNumber;
unsigned int OldSpeedValue=0;   //车速
unsigned int OldWaterTValue=0;  //水温	
unsigned int OldOilValue=0;     //燃油	
 
/**************************************************/
/*初始化端口。                                  	*/
/**************************************************/
void vLcd_DeviceInit(void) {
  DDRA=0xFF;
  DDRB=0xFF;
  PORTA=0xFF;
  PORTB=0xFF;
}

/**************************************************/
/*设置光标。先选择行,再选择列。图形方式。        */
/**************************************************/
void vLcd_SetCursor(unsigned int col,unsigned int row){
  vLcd_WRCommand(Lcd_YAxisR,row);
  vLcd_WRCommand(Lcd_XAxisR,col);
  vLcd_WRCommand(Lcd_CntrlR,((col/256)<<2)|(row/256));
}

/**************************************************/
/*写指令、数据子程序。                          	*/
/**************************************************/  
void vLcd_WRCommand(byte bIndex,unsigned int bValue){  
  DDRB= 0xff;
  switch (bIndex) {
    case Lcd_XAxisR:		 /* Select X-Axis R        */
      A1=0; A0=0;
      break;
    case Lcd_YAxisR:		 /* Select Y-Axis R        */
      A1=0; A0=1;
      break;
    case Lcd_CntrlR:		 /* Select Cntrl R          */
      A1=1; A0=0;
      break;
    case Lcd_DataR:	 /* Select Data R           */
      A1=1; A0=1;
      break;
  }/* switch */
  PORTB=bValue;				 /* Write Value to PortB    */    
  CS=0; WR=0;
  WR=1; CS=1;
}
 
 
/**************************************************/
/*清屏。全屏清零,可设置背景色。                 	*/
/**************************************************/ 	 
void vLcd_ClearViewport(unsigned char BColor){
  unsigned int x,y;
  vLcd_DeviceInit();
  for(y=0;y<480;y++){
    x=0;
	 vLcd_SetCursor(x,y);
    for(;x<640;x++) 
    vLcd_WRCommand(Lcd_DataR,BColor);
  }											
}
 
/**************************************************/
/*清屏。局部清零,可设置背景色。                 	*/
/**************************************************/ 
void vLcd_ClearRect(unsigned int x1,unsigned int y1,
                     unsigned int x2,unsigned int y2,unsigned char BColor){
  unsigned int i,j;
  for(j=y1;j<y2;j++){
    i=x1;
    vLcd_SetCursor(i,j);
    for(;i<x2;i++)
    vLcd_WRCommand(Lcd_DataR,BColor);
  }    
}			

/**************************************************/
/*延时。                                        	*/
/**************************************************/ 
static void vLcd_Delay1ms(void){
  unsigned int cnt=0;
  while(cnt<Delay) cnt++;  
} 
void vLcd_DelayNms(int Nms){
  unsigned int i;
  for(i=1;i<Nms;i++)
  vLcd_Delay1ms();
}

 
/**************************************************/
/*画点。可设置前景色。                          	*/
/**************************************************/ 
 void vLcd_DrawPoint(int x0,int y0,unsigned char FColor){
   vLcd_SetCursor(x0,y0);
   vLcd_WRCommand(Lcd_DataR,FColor);
 }
 
/**************************************************/
/*画线。可设置前景色。                          	*/
/**************************************************/
void vLcd_DrawLine(int x0,int y0,int x1,int y1, unsigned int color){
   int i,DeltaX,DeltaY,DeltaX2,DeltaY2,x_inc,y_inc,Err;
   
   DeltaX= x1-x0;
   DeltaY= y1-y0;
  
   if(DeltaX>=0){
     x_inc= 1;
   }
   else{
     x_inc= -1;
     DeltaX= -DeltaX;
   }
  
   if(DeltaY>=0){
     y_inc= 1;
   } 
   else{
     y_inc= -1;
     DeltaY= -DeltaY;
   }
  
   DeltaX2= DeltaX<<2;
   DeltaY2= DeltaY<<2;
  
   if(DeltaX>DeltaY){
     Err= DeltaY2- DeltaX;
     for(i=0;i<=DeltaX;i++){
       vLcd_DrawPoint(x0,y0,color);     
       if(Err>=0){
         Err-= DeltaX2;        
         y0+= y_inc;
       }
       Err+= DeltaY2;
       x0+= x_inc;
     }
   } 
   else{
     Err= DeltaY2- DeltaX;
     for(i=0;i<=DeltaY;i++){
       vLcd_DrawPoint(x0,y0,color);  
       if(Err>=0){
         Err-= DeltaY2;
         x0+= x_inc;
       }
       Err+= DeltaX2;
       y0+= y_inc;
     }
   }
}

void vLcd_DrawLine2(int x0,int y0,int x1, int y1,int FColor){
  int x,y,dx,dy,e;
  unsigned int i;
  dx=x1-x0;
  dy=y1-y0;
  e=-dx;
  x=x0;
  y=y0;
  for(i=0;i<dx;i++){
    vLcd_DrawPoint(x,y,FColor);  
    x++;
    e=e+2*dy;
    if(e>=0){
      y++;
      e=e-2*dx;
    }
  }
}

/**************************************************/
/*画圆弧。可设置前景色。 1/8象限圆弧              */
/**************************************************/ 
void vLcd_DrawPartArc(unsigned int ox,unsigned int oy,unsigned int Rx,
                      unsigned char FColor,unsigned char quad){
  unsigned int xx,rr,xt,yt,rs;
  unsigned int col,row;
  yt=Rx;
  rr=Rx*Rx+1;
  rs=(yt+(yt>>1))>>1;
  for(xt=0;xt<=rs;xt++){
    xx=xt*xt;
    while((yt*yt)>(rr-xx)) yt--;
    switch(quad){
      case 0:
        col=ox+xt; row=oy-yt; break;
      case 1:
        col=ox-xt; row=oy-yt; break;
      case 2:
        col=ox-xt; row=oy+yt; break;
      case 3:
        col=ox+xt; row=oy+yt; break;
      case 4:
        col=ox+yt; row=oy-xt; break;
      case 5:
        col=ox-yt; row=oy-xt; break;
      case 6:
        col=ox-yt; row=oy+xt; break; 
      case 7:
        col=ox+yt; row=oy+xt; break;
    }
    vLcd_DrawPoint(col,row,FColor);
  }
} 


/**************************************************/
/*画圆。可设置前景色、方式(0:不填充;1:填充)。  */
/**************************************************/ 
void vLcd_DrawCircle(int centerx, int centery, int radius, unsigned char FColor, int type){
  int x = 0;
  int y = radius;
  int delta = 2*(1-radius);
  int direction;
  while (y >= 0) {
  
    if(!type) {
      vLcd_DrawPoint(centerx+x, centery+y, FColor);
      vLcd_DrawPoint(centerx-x, centery+y, FColor);
      vLcd_DrawPoint(centerx-x, centery-y, FColor);
      vLcd_DrawPoint(centerx+x, centery-y, FColor);   
    }
    else{
      vLcd_DrawLine(centerx+x, centery+y, centerx+x, centery-y, FColor);
      vLcd_DrawLine(centerx-x, centery+y, centerx-x, centery-y, FColor);
    }
    
    if(delta < 0){
      if((2*(delta+y)-1) < 0) {
        direction = 1;
      }
      else {
        direction = 2;
      }
    }
    else if(delta > 0){
      if((2*(delta-x)-1) <= 0) {
        direction = 2;
      }
      else{
        direction = 3;
      }
    }
    else {
      direction=2;
    }
  
    switch(direction) {
    case 1:
      x++;
      delta += (2*x+1);
      break;
    case 2:
      x++;
      y--;
      delta += 2*(x-y+1);
      break;
    case 3:
      y--;
      delta += (-2*y+1);
      break;
    }

  }
}

/**************************************************/
/*单个汉字显示(16×16)。													*/
/*    FColor:字体颜色。                           */
/*		HzSituation:待显汉字在字库(HZK16)中的位置。 */
/**************************************************/ 
void vLcd_Show16DotWord(unsigned char HzSituation,unsigned char FColor){
  unsigned char i,j,k;
  unsigned int delta,HzS;
  delta=vLcdCol+HzNumber*8;
  if(delta>624){
		vLcdCol=0; vLcdRow+=24; 
		HzNumber=0;
		delta=vLcdCol+HzNumber*8;  
	}
	HzS=HzSituation*32;
  for(i=0;i<2;i++){		
		for(j=0;j<16;j++){
		  for(k=0;k<8;k++)
		    if(HZK16[HzS+j*2+i]&vLcdBit[k])
		       vLcd_DrawPoint(delta+i*8+k,vLcdRow+j,FColor); 	    
	  }
    HzNumber++; 
	}
}

/**************************************************/
/*多个汉字显示(16×16)。													*/
/*    FColor:字体颜色。 HzNum:待显汉字的总数。    */
/*		Hz:多个待显汉字的位置顺序。 								*/
/*    可自动换行,超出屏幕下沿时,余字将不再显示。*/
/**************************************************/ 
void vLcd_Disply16DotHz(unsigned int row,unsigned int col,unsigned char *Hz,
                        unsigned char HzNum,unsigned char FColor){
  unsigned char i;
  HzNumber=0;  
  vLcdCol=col; vLcdRow=row;
  vLcd_SetCursor(vLcdCol,vLcdRow);
  for(i=0;i<HzNum;i++){
    vLcd_Show16DotWord(Hz[i],FColor);
    if(vLcdRow>464) break;
  }	
}			



void vLcd_LeftScroll1(void){
  unsigned int y,n;
	for(y=0;y<75;y++){
	  //vLcd_WRCommand(Lcd_YAxisR,300+y);
    //vLcd_WRCommand(Lcd_CntrlR,(y+100)/256);
    //vLcd_WRCommand(Lcd_XAxisR,100);
   
	  //vLcd_SetCursor(100,100+y);
    for(n=0;n<101;n++)  {
      vLcd_SetCursor(270+n,340+y);
      //vLcd_WRCommand(Lcd_XAxisR,400+n);		 

⌨️ 快捷键说明

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