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

📄 n6610.c

📁 this is avr code for nokia color lcd
💻 C
字号:
#include <ATmega128.h>
#include <math.h>
#include "N6610.h"
#include "Font.h"
// System clock 16Mhz
// SPI initialisation
// Master mode,SCK phase low,SCK idle low
// Double speech, clock rate: 8Mhz 
void SPI_Init(void)
{
    SPCR = 0x50; //setup SPI
    SPSR = 0x01; //setup SPI
}
//==========================================================
void Send_SPI(UByte Data)
{
    SPI_ENABLE;       // Enable SPI port	 
    SPDR = Data;
    while (!(SPSR & 0x80)); 
      SPI_DISABLE;	  // Desable SPI port			  
}
//==========================================================
void Wait(UByte m)
{
    UByte i;
    unsigned int j;
    for(i=1;i<=m;i++)
      for(j=1;j<=1000;j++); 	 	 
}
//==========================================================
void SPI_CMD(UByte CMD)
{
    CLR_nCS;          // Select chip
    CLR_SCK;          // Send bit 0 for command
    CLR_SDA;
    SET_SCK; 				 				 			 
    Send_SPI(CMD);    // Send command byte
    SET_nCS;          // Deselect chip							 
}
//==========================================================
void SPI_DATA(UByte Data)
{
    CLR_nCS;          // Select chip
    CLR_SCK;          // Send bit 1 for Data
    SET_SDA;
    SET_SCK; 				 				  
    Send_SPI(Data);   // Send command byte
    SET_nCS;          // Deselect chip	 
}
//==========================================================
void LCD_Init(void)
{
    unsigned int i; 
    SET_PULLUP;      // Pull up
    SET_INPUT;       // First all pins are input
    SET_OUTPUT;      // change all pins to output 					 			  
    SPI_Init();      // Init SPI port
    SPI_DISABLE;     // Desable SPI port
	
    CLR_nRST;        // Reset to low
    SET_nRST;        // Reset to high 
    Wait(10);        // Wait some times
                            
    SPI_CMD(DISINV); // Display Control
    SPI_DATA(3);     // P1: CL,F1,F2
    SPI_DATA(32);    // P2: Drive Duty					 
    SPI_DATA(12);    // P3: FR,inverse-setvalue	
                
    SPI_CMD(COMSCN); // Commond scan direction
    SPI_DATA(1);     // P1: Commond scan direction
            
    SPI_CMD(OSCON);  // Internal oscillation on
            
    SPI_CMD(SLPOUT); // Sleep out
            
    SPI_CMD(VOLCTR); // Electronic volume control
    SPI_DATA(30);    // P1: Volume value alpha 20
    SPI_DATA(11);    // P2: 1+Rb/Ra v=11
            
    SPI_CMD(PWRCTR); // Power control
    SPI_DATA(15);    // P1: LCD drive power
    Wait(100);       // Wait some times
            
    SPI_CMD(DISINV); // Inverse display
            
    SPI_CMD(DATCTL); // Data scan direction
    SPI_DATA(0);     // P1: page address scan direction
    SPI_DATA(0);     // P2: RGB arrangement					 
    SPI_DATA(1);     // P3: Gray-scale: 1->8,2->16 gray scale
            
    SPI_CMD(RGBSET8);// 256-color position set
    SPI_DATA(0);     // RED tone	
    SPI_DATA(2);
    SPI_DATA(4);
    SPI_DATA(6);
    SPI_DATA(8);
    SPI_DATA(10);
    SPI_DATA(12);
    SPI_DATA(15);
    SPI_DATA(0);      // GREEN tone	
    SPI_DATA(2);
    SPI_DATA(4);
    SPI_DATA(6);
    SPI_DATA(8);
    SPI_DATA(10);
    SPI_DATA(12);
    SPI_DATA(15);
    SPI_DATA(0);      // BLUE tone
    SPI_DATA(4);
    SPI_DATA(9);
    SPI_DATA(15);
       
    SPI_CMD(LCDNOP);  // No operation
    
    SPI_CMD(PASET);   // Page address set
    SPI_DATA(2);      // P1: Start page
    SPI_DATA(131);    // P2: End page	     
            
    SPI_CMD(CASET);   // Colum address set
    SPI_DATA(0);      // P1: Start address
    SPI_DATA(131);    // P2: End address	
                                             
    SPI_CMD(RAMWR);   // Write to memory this command
    // auto cancel if any other command is entered
    // Back ground LCD screen
    //Color =RRRGGGBB
    for(i=0;i<18000;i++) SPI_DATA(0xFF);
            
    SPI_CMD(DISON);    // Display on
            
    for(i=0;i<145;i++) // 150 160
    {
      SPI_CMD(VOLUP);  // Increment electronic control
      Wait(2);
    } 
}
//==========================================================
void Clear_Display(void)
{
    unsigned int i;
    Put_Pixel(0xFF,0,0); // Goto zero axis
    SPI_CMD(RAMWR);  // Write to memory this command
    // auto cancel if any other command is entered
    // Back ground LCD screen
    //Color =RRRGGGBB
    for(i=0;i<18000;i++) SPI_DATA(0xFF); 
}
//==========================================================
void Put_Pixel(UByte x,UByte y,UByte Color)															
{
    x=x+2;
    SPI_CMD(PASET);  // Page address set
    SPI_DATA(x);	 // P1: Start page
    SPI_DATA(131);	 // P2: End page
    SPI_CMD(CASET);  // Colum address set
    SPI_DATA(y);	 // P1: Start address
    SPI_DATA(131);	 // P2: End address
    SPI_CMD(RAMWR);  // Write to memory this command	      	 
    SPI_DATA(Color); // Put pixel RRRGGGBB
}
//==========================================================
//            Zoom the Pixel
//==========================================================
void Z_Pixel(UByte x,UByte y,UByte xz,UByte yz,UByte zoom,UByte Color)
{
    UByte i,j;
      for(i=0;i<zoom;i++)
        for(j=0;j<zoom;j++)
	{
          Put_Pixel(x+xz-i,y+yz-j,Color); 					 
	}
}
//==========================================================
//            Display Character 5x7 dot
//==========================================================
void PRINT_CHAR(UByte x,UByte y,UByte Index,UByte zoom,UByte FColor,UByte BColor)
{
    unsigned char i,j,xz,yz;
      for(j=0;j<=4;j++)
        for(i=0;i<=7;i++)
	{
          xz=(i+1)*zoom-1;
          yz=(j+1)*zoom-1;
          if((FontLookup[Index-32][j])&(1<<i)) // Index-32 change to ASCII code
            Z_Pixel(x,y,xz,yz,zoom,FColor);    // For dot	  								 
	  else
             Z_Pixel(x,y,xz,yz,zoom,BColor);    // For dot
	}   
}
//==========================================================
//	Draw line connect two points (x1,y1) to (x1,y2)														     
//	range (0..129)
//==========================================================

void Line(UByte x1,UByte y1,UByte x2,UByte y2,UByte Color)
{
    UByte x,y,minx,maxx,miny,maxy;
    float yr;
    miny=y1;
    maxy=y2;
    if(miny>maxy)
    {
      miny=y2;
      maxy=y1; 			 
    }
    if (x1==x2)
      for(y=miny;y<=maxy;y++)
        Put_Pixel(x1,y,Color);
    else
    {
      minx=x1;
      maxx=x2;
      if (minx>maxx)
      {
        minx=x2;
	maxx=x1;
      }
      for(x=minx;x<maxx;x++)
      {
        yr=((y2-y1)*x+y1*x2-x1*y2)/(x2-x1); // Line equation
        y=floorf(yr);
        Put_Pixel(x,y,Color); 					  					  
      }
    }    
}
//==========================================================
//    Draw a rectangle  
//    (x1,y1) uper left axis
//    (x2,y2) lower right axis
//    Solid: 1 for solid color rectangle 
//==========================================================
void Rect(UByte x1,UByte y1,UByte x2,UByte y2,UByte Solid,UByte Color)
{
    UByte x,y;
    if(Solid)
    for(x=x1;x<=x2;x++)
      for(y=y1;y<=y2;y++)
        Put_Pixel(x,y,Color);	  // Solid color rectangle 	
      else
      {
        Line(x1,y1,x1,y2,Color);
        Line(x1,y1,x2,y1,Color);
	Line(x1,y2,x2,y2,Color);
	Line(x2,y1,x2,y2,Color);
      }	
}
void Circle(UByte xo,UByte yo,UByte r,UByte Solid,UByte Color)
{
    UByte x,y,x1,y1;
    float yr;
     
    if(Solid==0)
    {
      y1=yo-r;
      x1=xo;     
      for(y=yo-r+1;y<=yo+r;y++)
      {
        yr=xo-sqrt(r*r-(y-yo)*(y-yo));
        x=floorf(yr);
        if((yr>=0)&&(x<=129))
        {
          Line(x1,y1,x,y,Color);
          x1=x;
          y1=y;
        }
      }
      y1=yo-r;
      x1=xo;
      for(y=yo-r+1;y<=yo+r;y++)
      {
        yr=xo+sqrt(r*r-(y-yo)*(y-yo));
        x=floorf(yr);
        if((yr>=0)&&(x<=129))
        {
          Line(x1,y1,x,y,Color);
          x1=x;
          y1=y;
        }
      }
    }
    else
      for(x=xo-r;x<=xo+r;x++)
        for(y=yo-r;y<=yo+r;y++)
         if ((x-xo)*(x-xo)+(y-yo)*(y-yo)<=r*r)
           Put_Pixel(x,y,Color);	
}

⌨️ 快捷键说明

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