您的位置:首页 > 其它

OLED 程序

2015-11-17 17:40 302 查看
没啥说的,直接上程序,想用啥自己去找吧:
/***************************
使用硬件 SPI
**************************/
void LCD_WrCmd(uint8 Command)
{
CS_OLED = 0;
G_CS = 1;
Delay_5us();
LCD_DC = 0;
SPI_Write_one_reg(Command);
Delay_5us();
CS_OLED = 1;

}

//--------------------------------------------------------------
// Prototype      : void I2C_SendGData(u8 Data)
// Calls          :
// Parameters     : u8 Data---Data to be send
// Description    : Send one Data byte to Oled
//--------------------------------------------------------------
/*******************************
硬件 SPI,不需要配置时序
*******************************/
void LCD_WrDat(uint8 Data)
{
CS_OLED = 0;
G_CS = 1;
Delay_5us();
LCD_DC = 1;
SPI_Write_one_reg(Data);
Delay_5us();
CS_OLED = 1;
}

#if 0
//--------------------------------------------------------------
// Prototype      : void OLED_Refresh_Gram(u8 line)
// Calls          :
// Parameters     : line 更新显示行号,1~4行
// Return Value   :
// Description    : 更新显存到OLED
//--------------------------------------------------------------
void OLED_Refresh_Gram()//u8 line
{
uint8 i,n;
I2C_Start_M();
LCD_WrCmd(0xA1); // Remap
for(i=0;i<8;i++)
{
LCD_WrCmd (0xb0+i);//+(line-1)*2);//设置页地址(0~7)
LCD_WrCmd (0x0);      //设置显示位置—列低地址,偏移了2列
LCD_WrCmd (0x10);      //设置显示位置—列高地址
for(n=0;n<128;n++)
I2C_SendGData(OLED_GRAM
[i]);

}
I2C_Stop_M();
}
#endif

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//  Instruction Setting
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Set_Start_Column(unsigned char d)
{
LCD_WrCmd(0x00+d%16);		// Set Lower Column Start Address for Page Addressing Mode
//   Default => 0x00
LCD_WrCmd(0x10+d/16);		// Set Higher Column Start Address for Page Addressing Mode
//   Default => 0x10
}

void Set_Addressing_Mode(unsigned char d)
{
LCD_WrCmd(0x20);			// Set Memory Addressing Mode
LCD_WrCmd(d);			//   Default => 0x02
//     0x00 => Horizontal Addressing Mode
//     0x01 => Vertical Addressing Mode
//     0x02 => Page Addressing Mode
}

void Set_Column_Address(unsigned char a, unsigned char b)
{
LCD_WrCmd(0x21);			// Set Column Address
LCD_WrCmd(a);			//   Default => 0x00 (Column Start Address)
LCD_WrCmd(b);			//   Default => 0x7F (Column End Address)
}

void Set_Page_Address(unsigned char a, unsigned char b)
{
LCD_WrCmd(0x22);			// Set Page Address
LCD_WrCmd(a);			//   Default => 0x00 (Page Start Address)
LCD_WrCmd(b);			//   Default => 0x07 (Page End Address)
}

void Set_Start_Line(unsigned char d)
{
LCD_WrCmd(0x40|d);			// Set Display Start Line
//   Default => 0x40 (0x00)
}

void Set_Contrast_Control(unsigned char d)
{
LCD_WrCmd(0x81);			// Set Contrast Control
LCD_WrCmd(d);			//   Default => 0x7F
}

void Set_Charge_Pump(unsigned char d)
{
LCD_WrCmd(0x8D);			// Set Charge Pump
LCD_WrCmd(0x10|d);			//   Default => 0x10
//     0x10 (0x00) => Disable Charge Pump
//     0x14 (0x04) => Enable Charge Pump
}

void Set_Segment_Remap(unsigned char d)
{
LCD_WrCmd(0xA0|d);			// Set Segment Re-Map
//   Default => 0xA0
//     0xA0 (0x00) => Column Address 0 Mapped to SEG0
//     0xA1 (0x01) => Column Address 0 Mapped to SEG127
}

void Set_Entire_Display(unsigned char d)
{
LCD_WrCmd(0xA4|d);			// Set Entire Display On / Off
//   Default => 0xA4
//     0xA4 (0x00) => Normal Display
//     0xA5 (0x01) => Entire Display On
}

void Set_Inverse_Display(unsigned char d)
{
LCD_WrCmd(0xA6|d);			// Set Inverse Display On/Off
//   Default => 0xA6
//     0xA6 (0x00) => Normal Display
//     0xA7 (0x01) => Inverse Display On
}

void Set_Multiplex_Ratio(unsigned char d)
{
LCD_WrCmd(0xA8);			// Set Multiplex Ratio
LCD_WrCmd(d);			//   Default => 0x3F (1/64 Duty)
}

void Set_Display_On_Off(unsigned char d)
{
if(d==0xAF)
Set_Charge_Pump(0x14);
LCD_WrCmd(0xAE|d);			// Set Display On/Off
//   Default => 0xAE
//     0xAE (0x00) => Display Off
//     0xAF (0x01) => Display On
if(d==0xAE)
Set_Charge_Pump(0x10);

}

void Set_Start_Page(unsigned char d)
{
LCD_WrCmd(0xB0|d);			// Set Page Start Address for Page Addressing Mode
//   Default => 0xB0 (0x00)
}

void Set_Common_Remap(unsigned char d)
{
LCD_WrCmd(0xC0|d);			// Set COM Output Scan Direction
//   Default => 0xC0
//     0xC0 (0x00) => Scan from COM0 to 63
//     0xC8 (0x08) => Scan from COM63 to 0
}

void Set_Display_Offset(unsigned char d)
{
LCD_WrCmd(0xD3);			// Set Display Offset
LCD_WrCmd(d);			//   Default => 0x00
}

void Set_Display_Clock(unsigned char d)
{
LCD_WrCmd(0xD5);			// Set Display Clock Divide Ratio / Oscillator Frequency
LCD_WrCmd(d);			//   Default => 0x80
//     D[3:0] => Display Clock Divider
//     D[7:4] => Oscillator Frequency
}

void Set_Precharge_Period(unsigned char d)
{
LCD_WrCmd(0xD9);			// Set Pre-Charge Period
LCD_WrCmd(d);			//   Default => 0x22 (2 Display Clocks [Phase 2] / 2 Display Clocks [Phase 1])
//     D[3:0] => Phase 1 Period in 1~15 Display Clocks
//     D[7:4] => Phase 2 Period in 1~15 Display Clocks
}

void Set_Common_Config(unsigned char d)
{
LCD_WrCmd(0xDA);			// Set COM Pins Hardware Configuration
LCD_WrCmd(0x02|d);			//   Default => 0x12 (0x10)
//     Alternative COM Pin Configuration
//     Disable COM Left/Right Re-Map
}

void Set_VCOMH(unsigned char d)
{
LCD_WrCmd(0xDB);			// Set VCOMH Deselect Level
LCD_WrCmd(d);			//   Default => 0x20 (0.77*VCC)
}

void Set_NOP()
{
LCD_WrCmd(0xE3);			// Command for No Operation
}

void HalHW_WaitMS(uint16 t)
{
   uint16 i;
 
   while(t--)
   {
      for (i=1000; i>0; i--);
   }
}
<span style="white-space:pre">	</span>/*********************LCD 设置坐标************************************/  
<span style="white-space:pre">	</span>void LCD_Set_Pos(unsigned char x, unsigned char y)   
<span style="white-space:pre">	</span>{   
<span style="white-space:pre">	</span>    LCD_WrCmd(0xb0|y);  
<span style="white-space:pre">	</span>    //LCD_WrCmd(((x&0xf0)>>4)|0x10);  
<span style="white-space:pre">	</span>    //LCD_WrCmd((x&0x0f)|0x01); 
           
            LCD_WrCmd(0x00+x%16);  
<span style="white-space:pre">	</span>    LCD_WrCmd(0x10+x/16); 
              
<span style="white-space:pre">	</span>}   
<span style="white-space:pre">	</span>/*********************LCD全屏************************************/  
<span style="white-space:pre">	</span>void LCD_Fill(unsigned char bmp_dat)   
<span style="white-space:pre">	</span>{  
<span style="white-space:pre">	</span>    unsigned char y,x;  
<span style="white-space:pre">	</span>    for(y=0;y<5;y++)  
<span style="white-space:pre">	</span>    {  
<span style="white-space:pre">	</span>        LCD_WrCmd(0xb0+y);  
<span style="white-space:pre">	</span>        LCD_WrCmd(0x01);  
<span style="white-space:pre">	</span>        LCD_WrCmd(0x10);  
<span style="white-space:pre">	</span>        for(x=0;x<X_WIDTH;x++)  
<span style="white-space:pre">	</span>            LCD_WrDat(bmp_dat);  
<span style="white-space:pre">	</span>    }  
<span style="white-space:pre">	</span>}  
<span style="white-space:pre">	</span>  
<span style="white-space:pre">	</span>  
<span style="white-space:pre">	</span>/***************功能描述:行填充, y为页范围0~5****************/  
<span style="white-space:pre">	</span>void LCD_FillLine(unsigned char y,unsigned char ch)  
<span style="white-space:pre">	</span>{  
<span style="white-space:pre">	</span>    unsigned char x;      
<span style="white-space:pre">	</span>    LCD_WrCmd(0xb0+y);  
<span style="white-space:pre">	</span>    LCD_WrCmd(0x01);<span style="white-space:pre">	</span>   
            LCD_WrCmd(0x10);   
<span style="white-space:pre">	</span>    for(x=0;x<X_WIDTH;x++)  
<span style="white-space:pre">	</span>        LCD_WrDat(ch);  
<span style="white-space:pre">	</span>}  
<span style="white-space:pre">	</span>  
<span style="white-space:pre">	</span>  
<span style="white-space:pre">	</span>/*********************LCD复位************************************/  

<span style="white-space:pre">	</span>void LCD_CLS(void)  
<span style="white-space:pre">	</span>{  
           PWR = 0;//测试
<span style="white-space:pre">	</span>    unsigned char y,x;      
<span style="white-space:pre">	</span>    for(y=0;y<5;y++)  
<span style="white-space:pre">	</span>    {  
<span style="white-space:pre">	</span>        LCD_WrCmd(0xb0+y);  
<span style="white-space:pre">	</span>        LCD_WrCmd(0x01);  
<span style="white-space:pre">	</span>        LCD_WrCmd(0x10);   
<span style="white-space:pre">	</span>        for(x=0;x<X_WIDTH;x++)  
<span style="white-space:pre">	</span>            LCD_WrDat(0);  
<span style="white-space:pre">	</span>    }  
            PWR = 1;//测试 
<span style="white-space:pre">	</span>}  

        void LCD_CLS0(unsigned char m,unsigned char n,unsigned char p,unsigned char l)  
<span style="white-space:pre">	</span>{  
<span style="white-space:pre">	</span>    unsigned char y,x;      
<span style="white-space:pre">	</span>    for(y=m;y<n;y++)  
<span style="white-space:pre">	</span>    {  
<span style="white-space:pre">	</span>        LCD_WrCmd(0xb0+y);  
<span style="white-space:pre">	</span>        LCD_WrCmd(0x01);  
<span style="white-space:pre">	</span>        LCD_WrCmd(0x10);   
<span style="white-space:pre">	</span>        for(x=p;x<l;x++)  
<span style="white-space:pre">	</span>            LCD_WrDat(0);  
<span style="white-space:pre">	</span>    }  
<span style="white-space:pre">	</span>}  

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//  Show Regular Pattern (Full Screen)
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Fill_RAM(unsigned char Data)
{
unsigned char i,j;

<span style="white-space:pre">	</span>for(i=0;i<8;i++)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>Set_Start_Page(i);
<span style="white-space:pre">		</span>Set_Start_Column(0x00);

<span style="white-space:pre">		</span>for(j=0;j<128;j++)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">			</span>LCD_WrDat(Data);
<span style="white-space:pre">		</span>}
<span style="white-space:pre">	</span>}
}
<span style="white-space:pre">	</span>

void OLED_Init_I()<span style="white-space:pre">	</span>    // VCC Generated by Internal DC/DC Circuit
{
unsigned char i;

        P1SEL &= ~0xC2;    /* Set pin function to GPIO */
        P1DIR |= 0xC2;     //输出模式
        P2SEL &= ~0x01;
        P2DIR |= 0x01;
        
        PWR = 0;
        Delay_5us();
        LCD_RST=0;
<span style="white-space:pre">	</span>for(i=0;i<200;i++)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>uDelay(200);
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>LCD_RST=1;
        Set_Display_On_Off(0xAE);<span style="white-space:pre">		</span>// Display Off (0xAE/0xAF)
<span style="white-space:pre">	</span>Set_Display_Clock(0x80);<span style="white-space:pre">		</span>// Set Clock as 160 Frames/Sec
<span style="white-space:pre">	</span>Set_Multiplex_Ratio(0x27);<span style="white-space:pre">		</span>// 1/39 Duty (0x0F~0x3F)
<span style="white-space:pre">	</span>Set_Display_Offset(0x00);<span style="white-space:pre">		</span>// Shift Mapping RAM Counter (0x00~0x3F)
<span style="white-space:pre">	</span>Set_Start_Line(0x00);<span style="white-space:pre">			</span>// Set Mapping RAM Display Start Line (0x00~0x3F)
<span style="white-space:pre">	</span>Set_Charge_Pump(0x14);<span style="white-space:pre">			</span>// Enable Built-in DC/DC Converter (0x10/0x14)
<span style="white-space:pre">	</span>Set_Addressing_Mode(0x02);<span style="white-space:pre">		</span>// Set Page Addressing Mode (0x00/0x01/0x02)
<span style="white-space:pre">	</span>Set_Segment_Remap(0xA1);<span style="white-space:pre">		</span>// Set SEG/Column Mapping (0xA0/0xA1)
<span style="white-space:pre">	</span>Set_Common_Remap(0xC8);<span style="white-space:pre">			</span>// Set COM/Row Scan Direction (0xC0/0xC8)
<span style="white-space:pre">	</span>Set_Common_Config(0x12);<span style="white-space:pre">		</span>// Set Alternative Configuration (0x02/0x12)
<span style="white-space:pre">	</span>Set_Contrast_Control(Brightness);<span style="white-space:pre">	</span>// Set SEG Output Current
<span style="white-space:pre">	</span>Set_Precharge_Period(0x25);<span style="white-space:pre">		</span>// Set Pre-Charge as 2 Clocks & Discharge as 5 Clock
<span style="white-space:pre">	</span>Set_VCOMH(0x20);<span style="white-space:pre">			</span>// Set VCOM Deselect Level
<span style="white-space:pre">	</span>Set_Entire_Display(0xA4);<span style="white-space:pre">		</span>// Disable Entire Display On (0xA4/0xA5)
<span style="white-space:pre">	</span>Set_Inverse_Display(0xA6);<span style="white-space:pre">		</span>// Disable Inverse Display On (0xA6/0xA7)

<span style="white-space:pre">	</span>Fill_RAM(0x00);<span style="white-space:pre">				</span>// Clear Screen

<span style="white-space:pre">	</span>Set_Display_On_Off(0xAF);<span style="white-space:pre">		</span>// Display On (0xAE/0xAF)
}

<span style="white-space:pre">	</span>/***************功能描述:显示6*8一组标准ASCII字符串    显示的坐标(x,y),y为页范围0~7****************/  
<span style="white-space:pre">	</span>void LCD_P6x8Str(unsigned char x, unsigned char y,unsigned char ch[])  
<span style="white-space:pre">	</span>{  
<span style="white-space:pre">	</span>    unsigned char c=0,i=0,j=0;        
<span style="white-space:pre">	</span>    while (ch[j]!='\0')  
<span style="white-space:pre">	</span>    {      
<span style="white-space:pre">	</span>        c =ch[j]-32;  
<span style="white-space:pre">	</span>        if(x>96){x=0;y++;}  
<span style="white-space:pre">	</span>        LCD_Set_Pos(x,y);      
<span style="white-space:pre">	</span>        for(i=0;i<6;i++)       
<span style="white-space:pre">	</span>            LCD_WrDat(F6x8[c][i]);    
<span style="white-space:pre">	</span>        x+=6;  
<span style="white-space:pre">	</span>        j++;  
<span style="white-space:pre">	</span>    }  
<span style="white-space:pre">	</span>}  
<span style="white-space:pre">	</span>  
<span style="white-space:pre">	</span>  
<span style="white-space:pre">	</span>/***********功能描述:显示一行ascii 码?无显示的点阵显示黑色,     y为页的范围0~7*****************/  
<span style="white-space:pre">	</span>void HalLcd_HW_WriteLine(unsigned char line, const char *pText)  
<span style="white-space:pre">	</span>{  
<span style="white-space:pre">	</span>    LCD_FillLine(line-1, 0);                            //先把这一行显示成黑色  
<span style="white-space:pre">	</span>    LCD_P6x8Str(0, line-1, (unsigned char *)pText);  
<span style="white-space:pre">	</span>}  
<span style="white-space:pre">	</span>  
<span style="white-space:pre">	</span>  
<span style="white-space:pre">	</span> 
<span style="white-space:pre">	</span>/*******************功能描述:显示8*16一组标准ASCII字符串     显示的坐标(x,y),y为页范围0~7****************/  
<span style="white-space:pre">	</span>void LCD_P8x16Str(unsigned char x, unsigned char y,unsigned char ch[])  
<span style="white-space:pre">	</span>{  
<span style="white-space:pre">	</span>    unsigned char c=0,i=0,j=0;  
<span style="white-space:pre">	</span>    while (ch[j]!='\0')  
<span style="white-space:pre">	</span>    {      
<span style="white-space:pre">	</span>        c =ch[j]-32;  
<span style="white-space:pre">	</span>        if(x>96){x=0;y++;}  
<span style="white-space:pre">	</span>        LCD_Set_Pos(x,y);      
<span style="white-space:pre">	</span>        for(i=0;i<8;i++)       
<span style="white-space:pre">	</span>            LCD_WrDat(F8X16[c*16+i]);  
<span style="white-space:pre">	</span>        LCD_Set_Pos(x,y+1);      
<span style="white-space:pre">	</span>        for(i=0;i<8;i++)       
<span style="white-space:pre">	</span>            LCD_WrDat(F8X16[c*16+i+8]);    
<span style="white-space:pre">	</span>        x+=8;  
<span style="white-space:pre">	</span>        j++;  
<span style="white-space:pre">	</span>    }  
<span style="white-space:pre">	</span>}  
<span style="white-space:pre">	</span>/*****************功能描述:显示16*16点阵  显示的坐标(x,y),y为页范围0~7**************************** 
<span style="white-space:pre">	</span>void LCD_P16x16Ch(unsigned char x, unsigned char y, unsigned char N)  
<span style="white-space:pre">	</span>{  
<span style="white-space:pre">	</span>    unsigned char wm=0;  
<span style="white-space:pre">	</span>    unsigned int adder=32*N;  //        
<span style="white-space:pre">	</span>    LCD_Set_Pos(x , y);  
<span style="white-space:pre">	</span>    for(wm = 0;wm < 16;wm++)  //               
<span style="white-space:pre">	</span>    {  
<span style="white-space:pre">	</span>        LCD_WrDat(F16x16[adder]);      
<span style="white-space:pre">	</span>        adder += 1;  
<span style="white-space:pre">	</span>    }        
<span style="white-space:pre">	</span>    LCD_Set_Pos(x,y + 1);   
<span style="white-space:pre">	</span>    for(wm = 0;wm < 16;wm++) //           
<span style="white-space:pre">	</span>    {  
<span style="white-space:pre">	</span>        LCD_WrDat(F16x16[adder]);  
<span style="white-space:pre">	</span>        adder += 1;  
<span style="white-space:pre">	</span>    }             
<span style="white-space:pre">	</span>}  
<span style="white-space:pre">	</span> ***********************************************************************************************************/ 
<span style="white-space:pre">	</span>  
<span style="white-space:pre">	</span>/***********功能描述:显示显示BMP图片128×64起始点坐标(x,y),x的范围0~127,y为页的范围0~7*****************/  
<span style="white-space:pre">	</span>void Draw_BMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,const unsigned char BMP[])  
<span style="white-space:pre">	</span>{       
<span style="white-space:pre">	</span>    unsigned int j=0;  
<span style="white-space:pre">	</span>    unsigned char x,y;  
<span style="white-space:pre">	</span>      
<span style="white-space:pre">	</span>    //if(y1%8==0) y=y1/8;        
<span style="white-space:pre">	</span>    //else y=y1/8+1;  
<span style="white-space:pre">	</span>    for(y=y0;y<y1;y++)  
<span style="white-space:pre">	</span>    {  
              LCD_Set_Pos(x0,y);
              
<span style="white-space:pre">	</span>        for(x=x0;x<x1;x++)  
<span style="white-space:pre">	</span>        {        
<span style="white-space:pre">	</span>            LCD_WrDat(BMP[j++]);              
<span style="white-space:pre">	</span>        }  
<span style="white-space:pre">	</span>    }  
<span style="white-space:pre">	</span>}   

//*********************************************************************
//显示英文字母与字符(含空格)的函数,其中X的范围是0<=X<16,Y的范围是0<=y<8
//*********************************************************************
void Show_English(unsigned char *pcStr,unsigned char x,unsigned char y)//0<=X<16;0<=Y<8
{   
<span style="white-space:pre">	</span>unsigned int ucTemp,max1,max2;
<span style="white-space:pre">	</span>int i=0,x_h=0,x_l=0;
<span style="white-space:pre">	</span>y+=0xb0;
<span style="white-space:pre">	</span>
<span style="white-space:pre">	</span>LCD_WrCmd(x_h);
<span style="white-space:pre">	</span>LCD_WrCmd(x_l);
<span style="white-space:pre">	</span>while(*pcStr != 0)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">	</span>  <span style="white-space:pre">	</span>x_h=x/2+0x10;
<span style="white-space:pre">		</span>x_l=(x%2==0)?0x00:0x08;
<span style="white-space:pre">	</span>    ucTemp = (*pcStr++ -32)* 0x10;
<span style="white-space:pre">	</span>    max1=ucTemp+8;
<span style="white-space:pre">		</span>max2=ucTemp+16;
<span style="white-space:pre">	</span>   <span style="white-space:pre">	</span>LCD_WrCmd(x_h);
<span style="white-space:pre">	</span>    LCD_WrCmd(x_l);
<span style="white-space:pre">	</span>    LCD_WrCmd(y);
<span style="white-space:pre">	</span>    for(i=ucTemp;i<max1;i++)
<span style="white-space:pre">	</span>        LCD_WrDat(F8X16[i]);
<span style="white-space:pre">		</span>LCD_WrCmd(x_h);
<span style="white-space:pre">	</span>    LCD_WrCmd(x_l);
<span style="white-space:pre">	</span>    LCD_WrCmd(y+0x01);
<span style="white-space:pre">	</span>    for(i=max1;i<max2;i++)
<span style="white-space:pre">	</span>        LCD_WrDat(F8X16[i]);
<span style="white-space:pre">		</span>x++;
<span style="white-space:pre">		</span>if(x>16)
<span style="white-space:pre">			</span>break;<span style="white-space:pre">	</span>        
<span style="white-space:pre">	</span>} 
}

//*********************************************************************
//显示数值
//*********************************************************************
unsigned char Show_Num(unsigned long Num,unsigned char x_pos,unsigned char y_pos)
{
<span style="white-space:pre">	</span>unsigned int ucTemp,max1,max2;
<span style="white-space:pre">	</span>unsigned int i=0,x_h=0,x_l=0;

<span style="white-space:pre">	</span>unsigned long temp=0;
<span style="white-space:pre">	</span>unsigned char BitNum=0;
<span style="white-space:pre">	</span>
<span style="white-space:pre">	</span>if(Num==0)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>Show_English("0",x_pos,y_pos);
<span style="white-space:pre">		</span>BitNum=1;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>else
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>temp=Num;
<span style="white-space:pre">		</span>while(temp){temp/=10;BitNum++;}
<span style="white-space:pre">	</span>
<span style="white-space:pre">		</span>temp=1;
<span style="white-space:pre">		</span>for(i=0;i<(BitNum-1);i++)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">			</span>temp*=10;
<span style="white-space:pre">		</span>}

<span style="white-space:pre">		</span>y_pos+=0xb0;<span style="white-space:pre">				</span>//计算页地址
<span style="white-space:pre">		</span>LCD_WrCmd(x_h);
<span style="white-space:pre">		</span>LCD_WrCmd(x_l);

<span style="white-space:pre">		</span>while(temp!=0)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">			</span>x_h=x_pos/2+0x10;<span style="white-space:pre">	</span>        //计算列地址高位
<span style="white-space:pre">			</span>x_l=(x_pos%2==0)?0x00:0x08;<span style="white-space:pre">	</span>//计算列地址低位

<span style="white-space:pre">			</span>ucTemp = (Num/temp + 16) * 16;

<span style="white-space:pre">	</span>    <span style="white-space:pre">	</span>        max1=ucTemp+8;
<span style="white-space:pre">			</span>max2=ucTemp+16;
<span style="white-space:pre">		</span>   <span style="white-space:pre">	</span>LCD_WrCmd(x_h);<span style="white-space:pre">			</span>//设置列地址高位
<span style="white-space:pre">		</span>        LCD_WrCmd(x_l);<span style="white-space:pre">			</span>//设置列地址低位
<span style="white-space:pre">		</span>        LCD_WrCmd(y_pos);

<span style="white-space:pre">		</span>    for(i=ucTemp;i<max1;i++)
<span style="white-space:pre">		</span>       LCD_WrDat(F8X16[i]);

<span style="white-space:pre">			</span>LCD_WrCmd(x_h);
<span style="white-space:pre">		</span>    LCD_WrCmd(x_l);
<span style="white-space:pre">		</span>    LCD_WrCmd(y_pos+0x01);

<span style="white-space:pre">		</span>    for(i=max1;i<max2;i++)
<span style="white-space:pre">		</span>       LCD_WrDat(F8X16[i]);

<span style="white-space:pre">			</span>x_pos++;
<span style="white-space:pre">			</span>Num%=temp;
<span style="white-space:pre">			</span>temp/=10;<span style="white-space:pre">	</span>
<span style="white-space:pre">		</span>}
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>return BitNum;     
}

//*********************************************************************
//顯示點
//*********************************************************************
void Show_Doc(unsigned char x,unsigned char y)
{
  unsigned char x_h,x_l,y1,i;
  //if(y > 63)return;
  //y = 63 - y;
  x_h = x >> 4;
  x_h |= 0x10;
  x_l = x & 0x0f;
  y1 = y >> 3;
  y1 |= 0xb0;
  //擦除點
  if(x < 128)
  {
    for(i=0; i<8; i++)
    {
      LCD_WrCmd(x_h);
      LCD_WrCmd(x_l);
      LCD_WrCmd(i | 0xb0);
      LCD_WrDat(0); 
    } 
    //畫點
    LCD_WrCmd(x_h);
    LCD_WrCmd(x_l);
    LCD_WrCmd(y1);
    LCD_WrDat(0x01 << (y % 8));
  }

}

/*****************************

              显示字符

******************************/
void LCD_P13x24Str(unsigned char *Buf,unsigned char j)  
{  
    unsigned char i=0;
    unsigned char c; 
    //while ( Buf[j] !='\0')
    {
        //c = Buf[j] - 32;
        //j++;
        for(i=0;i<j;i++)
        {
            c = Buf[i] - 32;
            if( c == 16 )
            {
                Draw_BMP( 35+i*13 , 0 , 48+i*13 , 3 , gImage_0 );
            }
            if( c == 17 )
            {
                Draw_BMP( 35+i*13 , 0 , 48+i*13 , 3 , gImage_1 );
            }
            if( c == 18 )
            {
                Draw_BMP( 35+i*13 , 0 , 48+i*13 , 3 , gImage_2 );
            }
            if( c == 19 )
            {
                Draw_BMP( 35+i*13 , 0 , 48+i*13 , 3 , gImage_3 );
            }
            if( c == 20 )
            {
                Draw_BMP( 35+i*13 , 0 , 48+i*13 , 3 , gImage_4 );
            }
            if( c == 21 )
            {
                Draw_BMP( 35+i*13 , 0 , 48+i*13 , 3 , gImage_5 );
            }
            if( c == 22 )
            {
                Draw_BMP( 35+i*13 , 0 , 48+i*13 , 3 , gImage_6 );
            }
            if( c == 23 )
            {
                Draw_BMP( 35+i*13 , 0 , 48+i*13 , 3 , gImage_7 );
            }
            if( c == 24 )
            {
                Draw_BMP( 35+i*13 , 0 , 48+i*13 , 3 , gImage_8 );
            }
            if( c == 25 )
            {
                Draw_BMP( 35+i*13 , 0 , 48+i*13 , 3 , gImage_9 );
            }
            if( c == 26 )
            {
                Draw_BMP( 37+i*13 , 0 , 44+i*13 , 3 , gImage_Doc );
            }
        }  
    }
} 

/*********************************

              显示数字

*********************************/
void LCD_P13x24_Num(unsigned char *Buf,unsigned char j,unsigned char x,unsigned char y)  
{  
    unsigned char i=0;
    unsigned char a=0;
    //while ( Buf[j] !='\0')
    {
        //c = Buf[j] - 32;
        //j++;
        for(i=0;i<j;i++)
        {
            a = Buf[i];
            if( a == 0 )
            {
                Draw_BMP( x+i*13 , y , x+13+i*13 , y+3 , gImage_0 );
            }
            if( a == 1 )
            {
                Draw_BMP( x+i*13 , y , x+13+i*13 , y+3 , gImage_1 );
            }
            if( a == 2 )
            {
                Draw_BMP( x+i*13 , y , x+13+i*13 , y+3 , gImage_2 );
            }
            if( a == 3 )
            {
                Draw_BMP( x+i*13 , y , x+13+i*13 , y+3 , gImage_3 );
            }
            if( a == 4 )
            {
                Draw_BMP( x+i*13 , y , x+13+i*13 , y+3 , gImage_4 );
            }
            if( a == 5 )
            {
                Draw_BMP( x+i*13 , y , x+13+i*13 , y+3 , gImage_5 );
            }
            if( a == 6 )
            {
                Draw_BMP( x+i*13 , y , x+13+i*13 , y+3 , gImage_6 );
            }
            if( a == 7 )
            {
                Draw_BMP( x+i*13 , y , x+13+i*13 , y+3 , gImage_7 );
            }
            if( a == 8 )
            {
                Draw_BMP( x+i*13 , y , x+13+i*13 , y+3 , gImage_8 );
            }
            if( a == 9 )
            {
                Draw_BMP( x+i*13 , y , x+13+i*13 , y+3 , gImage_9 );
            }
        }  
    }
}

#if 1
void LCD_Num( unsigned long Num,unsigned char x,unsigned char y)
{
    unsigned long Temp;
    unsigned long Temp_0;
    unsigned char Send_Num[16]={0};
    unsigned char Send_Num_0[16]={0};
    unsigned char Bit_Num=0;
    uint8 Temp_1;
    uint8 Send_num;
    uint8 i=0,j=0,k=0;
    
    
    Temp = Num;
    if( Temp == 0)
    {
        Send_num = (uint8)Temp;
        Send_Num[0] = Send_num;
        LCD_P13x24_Num(Send_Num,1,x,y);
    }
    if(Temp > 0 )
    {
        while(Temp)
        {
            Temp = (Temp/10);
            Bit_Num++;
        }
        for(i=0;i<Bit_Num;i++)
        {
            Temp_0 = (Num / 10);
            Temp_1 = (Num % 10);
      
            Send_num = (uint8)Temp_1;
            Send_Num[i] = Send_num;
            Num = Temp_0;
        }
        k = i - 1;
        for( j=0;j<=i;j++)
        {
            Send_Num_0[j] = Send_Num[k];
            k--;
        }
        LCD_P13x24_Num(Send_Num_0,i,x,y);
    } 
}
#endif
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: