| 你液晶初始化函数运行两遍试试? 我当时测试的程序,不知道为什么,初始化一遍总是没办**常点亮
 #include<xc.h>
#define _XTAL_FREQ 4000000
#pragma config WDTE=OFF,FOSC=INTRCIO,MCLRE=OFF
#define MOOD 1
#define byte        unsigned char
#define SD                 GP0
#define WR                GP1
#define CS                 GP2
#define LED                GP5
#define Button        GP3
#define SYS_EN        0x01
#define        LCD_ON        0x03
#define        BISA2        0x28
#define        BISA3        0x29
#define        TEST        0xE0
#define        NORMAL        0xE3
#define InitArraysize        sizeof(InitArray)
//byte InitArray[]={SYS_EN,LCD_ON,BISA2,TEST};
byte InitArray[]={SYS_EN,LCD_ON,BISA2,NORMAL};
byte Adr;
byte Dat;
//系统初始化
void SysInit(void)
{
        OPTION_REG=0X0F;
        //GPIO=0X00;//端口初始值全部设为0
        CMCON=0X07;//关闭比较器
        TRISIO=0x08;//设置端口方向:除GP3外全部为输出
        GPIO=0X00;//端口初始值全部设为0
}
//HT1621_Pin_nCS        CS
//HT1621_Pin_WR                WR
//HT1621_W_Bit0                Bit0
void Bit0(void)
{
        WR=0;
        SD=0;
        //__delay_us(5);
        asm("NOP");
        WR=1;
        //__delay_us(5);
        asm("NOP");
        WR=0;
        SD=0;
}
void Bit1(void)
{
        WR=0;
        SD=1;
        //__delay_us(5);
        asm("NOP");
        WR=1;
        //__delay_us(5);
        asm("NOP");
        WR=0;
        SD=0;
}
void HT1621_Cmd(byte cmd)
{
        byte i;
        CS=0;
        //__delay_us(5);
        asm("NOP");
        Bit1();
        Bit0();
        Bit0();
        for(i=0;i<9;i++)
        {
                if(cmd&0x80)
                        Bit1();
                else        
                        Bit0();
                cmd<<=1;
        }
        CS=1;
}
void HT1621_W(byte Addr,byte Data)
{
        byte i;
        CS=0;
        //__delay_us(5);
        asm("NOP");
        Bit1();
        Bit0();
        Bit1();
        for(i=0;i<6;i++)
        {
                if(Addr&0x20)
                        Bit1();
                else
                        Bit0();
                Addr<<=1;
        }
        for(i=0;i<4;i++)
        {
                if(Data&0x01)
                        Bit1();
                else
                        Bit0();
                Data>>=1;
        }
        CS=1;
}
void HT1621_Init(void)
{
        byte i;
        for(i=0;i<InitArraysize;i++)
                HT1621_Cmd(InitArray[i]);
        for(i=0;i<32;i++)
                HT1621_W(i,0x00);
}
void main(void)
{
        SysInit();
        __delay_ms(1);
        HT1621_Init();
        __delay_ms(1);
        HT1621_Init();
        __delay_ms(1);
        HT1621_Init();
        Adr=0;
        Dat=1;
        while(1)
        {
                HT1621_W(Adr,Dat);
                __delay_ms(500);
                while(Button);
                __delay_ms(100);
                while(!Button);
#if MOOD==0
                Adr++;
                LED=0;
                if(Adr==32)
                {
                        LED=1;
                        Adr=0;
                        if(Dat==0x0F)
                        {
                                __delay_ms(100);
                                LED=0;
                                __delay_ms(100);
                                LED=1;
                                Dat=0;
                        }
                        Dat<<=1;
                        Dat|=1;
                }
#else
        #if MOOD==1
                LED=0;
                Dat<<=1;
                if(Dat==0x20)
                {
                        LED=1;
                        Dat=1;
                        Adr++;
                        if(Adr==32)
                        {
                                __delay_ms(100);
                                LED=0;
                                __delay_ms(100);
                                LED=1;
                                Adr=0;
                        }        
                }
        #else
                #error : "Not define the MOOD"
        #endif
#endif
//                __delay_ms(50);
        }
}
 |