#include "lcd_12864.h"
#include "SPI.h"
#include "Delay.h"
#include "ASCII_8x5.h"
/*******************************************************************************
//oˉêyÃû£o Lcdwritecom
//1|Äü£olcdD′Ö¸áî
//êäèë£ocomÖ¸áî
//êä3ö£oÎT
********************************************************************************/
void Lcdwritecom(uint8_t com)
{
LCD_CS_RESET; //Ƭѡà-μí£¬Ñ¡ÖDLCD
LCD_RS_RESET; //éèÖÃÎaD′Ãüáî
SPI_SendData(com);
LCD_CS_SET; //Ƭѡà-¸ß£¬êí·ÅLCD
}
/*******************************************************************************
//oˉêyÃû£oLcdwritedata
//1|Äü£olcdD′êy¾Y
//êäèë£odatêy¾Y
//êä3ö£oÎT
********************************************************************************/
void Lcdwritedata(uint8_t dat)
{
LCD_CS_RESET; //Ƭѡà-μí£¬Ñ¡ÖDLCD
LCD_RS_SET; //éèÖÃÎaD′êy¾Y
SPI_SendData(dat);
LCD_CS_SET; //Ƭѡà-¸ß£¬êí·ÅLCD
}
/*******************************************************************************
//oˉêyÃû£oinitial_lcd
//1|Äü£oLCDÄ£¿é3õê¼»ˉ
//êäèë£ocomÖ¸áî
//êä3ö£oÎT
********************************************************************************/
void init_lcd()
{
LCD_CS_RESET;
LCD_RST_RESET; /*μíμçƽ¸′λ*/
Delay(20);
LCD_RST_SET ; /*¸′λíê±Ï*/
Delay(20);
Lcdwritecom(0xe2); /*èí¸′λ*/
Delay(5);
Lcdwritecom(0x2c); /*éyÑ12½¾Û1*/
Delay(5);
Lcdwritecom(0x2e); /*éyÑ12½¾Û2*/
Delay(5);
Lcdwritecom(0x2f); /*éyÑ12½¾Û3*/
Delay(5);
Lcdwritecom(0x25); /*′Öμ÷¶Ô±è¶è£¬¿ééèÖ÷¶Î§0x20¡«0x27*/
Lcdwritecom(0x81); /*΢μ÷¶Ô±è¶è*/
Lcdwritecom(0x20); /*0x28,΢μ÷¶Ô±è¶èμÄÖ죬¿ééèÖ÷¶Î§0x00¡«0x3f*/
Lcdwritecom(0xa2); /*1/9Æ«Ñ1±è£¨bias£©*/
Lcdwritecom(0xc8); /*DDé¨ÃèË3Dò£o′óéÏμ½ÏÂ*/
Lcdwritecom(0xa0); /*áDé¨ÃèË3Dò£o′ó×óμ½óò*/
Lcdwritecom(0x40); /*Æeê¼DD£oμúò»DD¿aê¼*/
Lcdwritecom(0xaf); /*¿aÏÔê¾*/
LCD_CS_SET;
}
/*******************************************************************************
//oˉêyÃû£oclear_screen
//1|Äü£oÇåÆá
//êäèë£ocomÖ¸áî
//êä3ö£oÎT
********************************************************************************/
void clear_screen()
{
unsigned char i,j;
for(i=0;i<9;i++)
{
lcd_address(1+i,1);
for(j=0;j<132;j++)
{
Lcdwritedata(0x00);
}
}
}
/*******************************************************************************
//oˉêyÃû£olcd_address
//1|Äü£oLCDéÏÏÔê¾μÄλÖã¨ò3¡¢áD£©
//êäèë£ocomÖ¸áî
//êä3ö£oÎT
********************************************************************************/
void lcd_address(uint8_t page,uint8_t column)
{
column=column-1; //ÎòÃÇƽ3£ËùËμμÄμú1áD£¬ÔúLCDÇy¶ˉICàïêÇμú0áD¡£ËùòÔÔúÕaàï¼õè¥1.
page=page-1; //éèÖÃò3μØÖ·¡£ÿò3êÇ8DD(dian)¡£ò»¸ö»-ÃæμÄ64DD±»·Ö3é8¸öò3¡£ÎòÃÇƽ3£ËùËμμÄμú1ò3£¬ÔúLCDÇy¶ˉICàïêÇμú0ò3£¬ËùòÔÔúÕaàï¼õè¥1*/
Lcdwritecom(0xb0+page); /*éèÖÃò3μØÖ·1-8*/
Lcdwritecom(0x10+(column>>4&0x0f)); /*éèÖÃáDμØÖ·μĸß4λ*/ //0-127
Lcdwritecom(column&0x0f); /*éèÖÃáDμØÖ·μÄμí4λ*/
}
/*******************************************************************************
//oˉêyÃû£odisplay_ASCII£¨μ¥¸ö×Ö·û£©
//1|Äü£oÏÔê¾μ¥¸ö8*5μãÕóí¼Ïñ¡¢ASCIIÂë
//êäèë£odataêy¾Y
//êä3ö£oÎT
********************************************************************************/
void display_ASCII(uint8_t page,uint8_t column,uint8_t n)
{
uint16_t i;
uint8_t *dp;
dp=ASCII8x5+(n-32)*5 ;
lcd_address(page,column); //éèÖÃò3¡¢áD
for (i=0;i<5;i++)
{
Lcdwritedata(*dp);
dp++;
}
}
/*******************************************************************************
//oˉêyÃû£odisplay_string£¨×Ö·û′®£©
//1|Äü£o×Ö·û′® 8*5μãÕó
//êäèë£odataêy¾Y
//êä3ö£oÎT
********************************************************************************/
void display_string(uint8_t page,uint8_t column,uint8_t *s)
{
while(*s!='\0')
{
display_ASCII( page, column, s[0]);
s++;
column=column+6;
}
}
/*******************************************************************************
//oˉêyÃû£odisplay_hanzi£¨μ¥¸öoo×Ö£©
//1|Äü£o×Ö·û′®
//êäèë£odataêy¾Y
//êä3ö£oÎT
********************************************************************************/
void display_hanzi(uint16_t page,uint16_t column,uint8_t *dw)
{
uint16_t i,j;
for(j=0;j<2;j++)
{
lcd_address(page+j,column);
for (i=0;i<16;i++)
{
Lcdwritedata(*dw);
dw++;
}
}
}
/*******************************************************************************
//oˉêyÃû£odisplay_tupian
//1|Äü£oÏÔê¾í¼Æ¬
//êäèë£odataêy¾Y
//êä3ö£oÎT
********************************************************************************/
void display_128x64(uint8_t *dz)
{
uint16_t i,j;
for(j=0;j<8;j++)
{
lcd_address(j+1,1);
for (i=0;i<128;i++)
{
Lcdwritedata(*dz);
dz++;
}
}
}
|