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

📄 disdrive.c

📁 单片机控制的12864液晶显示器的驱动程序,通过按键控制
💻 C
字号:
//2003.1.10
//write by sunny

#include "main.h"
#include "disdrive.h"

void HardInitialLED()
{
        LedReset(FALSE);
        SetLedE_1();
        SetLedReadDataMode();

        DriveControlChip(0x00,0x00);
        SetLedZAddress(0x00);
        SetLedXAddress(0x00);
        SetLedYAddress(0x00);
        LedDisplay(TRUE);

        DriveControlChip(0x00,0x08);
        SetLedZAddress(0x00);
        SetLedXAddress(0x00);
        SetLedYAddress(0x00);
        LedDisplay(TRUE);
}

void DataOnLine(UCHAR ucSend)
{
        P0 = ucSend; //put data to LED data line
}
void SetLedDI_D()
{
        P20 = 1; //DI=1
}

void SetLedDI_I()
{
        P20 = 0;//DI=0
}

void SetLedRW_R()
{
        P21 = 1;//WR=1
}

void SetLedRW_W()
{
        P21 = 0;//WR=0
}

void SetLedE_1()
{
        P22 = 1;//E=1
}

void SetLedE_0()
{
        P22 = 0;//E=0
}

void SelectLeft()
{
        P23 = 1;//pc4=1 CSA=1
        P24 = 0;//pc5=0 CSB=0
}

void SelectRight()
{
        P23 = 0; //pc4=0  CSA=0
        P24 = 1; //pc5=1  CSB=0
}

void LedReset(UCHAR Reset)
{
        if (Reset) //the LED can't work normal ;i don't know why
		{
//			P25 = 0;//reset   pc7=0
//			delay(0xFFFF);
//			SendLedInstruction(0xE2);
		}
//        else P25 = 1; //reset off    pc7=1
		P25 = 1; //reset off    pc7=1  RST=1
		P25 = 1; //reset off    pc7=1  RST=1
}

//drive chips whih contral page and segment address
void DriveControlChip(UCHAR page_x, UCHAR seg_y)
{
        page_x = page_x;
        if ( seg_y < 8)  //select segmetn drive chip 0
        {
                SelectLeft();
        }
        else             //select segmetn drive chip 1
        {
                SelectRight();
        }
}

void SetLedWriteInstructionMode()
{
        SetLedDI_I();//D/I select I
        SetLedRW_W();//R/W select W
}

void SetLedWriteDataMode()
{
        SetLedDI_D();//D/I select D
        SetLedRW_W();//R/W select W
}

void SetLedReadDataMode()
{
        SetLedDI_I();
        SetLedRW_R();
}

void SendLedData(UCHAR charData)
{
        DataOnLine(charData);
        SetLedE_0();
        SetLedWriteDataMode();
        SetLedE_1();
        SetLedE_0();
        SetLedReadDataMode();
        SetLedE_1();
}

void SendLedInstruction(UCHAR charData)
{
        DataOnLine(charData);
        SetLedE_0();
        SetLedWriteInstructionMode();
        SetLedE_1();
        SetLedE_0();
        SetLedReadDataMode();
        SetLedE_1();
}


void LedDisplay(UCHAR On)
{
        if (On) SendLedInstruction(0x3F);
        else SendLedInstruction(0x3E);
}


void SetLedXAddress(UCHAR cXaddress)
{
        SendLedInstruction(0xB8 | cXaddress);
}

void SetLedYAddress(UCHAR cYaddress)
{
        SendLedInstruction(0x40 | cYaddress);
}

void SetLedZAddress(UCHAR cZaddress)
{
        SendLedInstruction(0xC0 | cZaddress);
}

⌨️ 快捷键说明

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