用过160128dot uc1698driver的人进来看看

2020-01-26 12:56发布

电路和程序都放上来,大家帮我看看,现在屏还是显示不了数据,只是背光亮了而已。
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int

sbit bm=P1^0;
sbit cs=P1^1;
sbit cd=P1^2;
sbit rd=P1^3;//WR1
sbit wr=P1^4;//WR0
sbit rst=P1^5;
#define dport P2

void delay_us(uint us)
{
        while(us--);
}

void delay_ms(uint ms)
{
        uchar i;
        while(ms--)
                for(i=0;i<120;i++);
}
//
//void write(bit flag,uchar dat)
//{                   cs=0;
//_nop_();
//                cd=flag;
//                _nop_();
//         rd=0;
//                 wr=0;
//     
//       _nop_();
//     dport=dat;
//     
//     _nop_();
////     _nop_();
//     wr=1;
//         rd=1;
//         _nop_();
//     cd=~flag;
//         _nop_();
//     cs=1;
//
//       
//}

void write(bit flag,uchar dat)
{
        cs=0;
        cd=flag;                                        //flag=1,write command;flag=0,write data
        wr=0;
        rd=1;
        dport=dat;
        wr=1;
}


void lcdscan(uchar dat1,uchar dat2)
{
        uchar i,j;
        write(0,0x60);                        //row address LSB
        write(0,0x70);                        //row address MSB
        write(0,0x00);                        //culomn address LSB
        write(0,0x10);                        //culomn address MSB

        for(j=0;j<160;j++)
        {
                for(i=0;i<40;i++)
                {
                        if(j%2==0)
                        {
                                write(1,dat1);
                                write(1,dat1);
                                write(1,dat1);
                        }
                        else
                        {
                                write(1,dat2);
                                write(1,dat2);
                                write(1,dat2);
                        }               
                }
        }
}

//void init()
//{
//cs=0 ;
///*reset*/
//rst=0;
//delay_ms(2);//power on reset
//rst=1;
//delay_ms(200);
//write(0,0xe2);
//delay_ms(10);    //delay(2000);
//write(0,0x2b);   
//write(0,0xa0);
//           
//write(0,0xeb);    //set bias                        BR[1:0]  111010xx   
//write(0,0xf1);    //set com end                     CEN      11110001
//write(0,0x9f);    //duty=1/160
//write(0,0x81);    //set VLCD value          
//write(0,0x45);    //VLCD=(CV0+Cpm*pm)*(1+(T-25)*CT%)
//write(0,0xc4);    //LCD mapping control LC[2:0]=100
//write(0,0x89);    //set ram address control
//
//write(0,0xd1);    //set color pattern=RGB
//write(0,0xd5);    //set color mode=4k-color
//write(0,0xc8);    //设置不当会有flicker
//write(0,0x18);    //LCMCOMM=0x0018;
//write(0,0xa6);    //inverse display: 0:darkest 15:lightest
////write(0,0xad);  //set ON/OFF display enable
//write(0,0xaf);//set ON/OFF display enable G16        
////set column addr: 0,0
//write(0,0x60);   
//write(0,0x70);   
////set row addr: 0,0
//write(0,0x10);  
//write(0,0x00);
//}

void init(void)
{
        cs=0;

        /*reset*/
        rst=0;
        delay_ms(2);                        //power on reset
        rst=1;
        delay_ms(200);
        write(0,0xe2);                        //reset by command
        delay_ms(2);

        /*power control*/                                       
        write(0,0xe9);                        //Bias Ratio:1/10 bias
        write(0,0x2b);                        //power control set as internal power
        write(0,0x24);                        //set temperate compensation as 0%
        write(0,0x81);                        //electronic potentionmeter
        write(0,198);       

        /*display control*/
        write(0,0xa4);                        //all pixel off
        write(0,0xa6);                        //inverse display off

        /*lcd control*/
        write(0,0xc0);                        //19:partial display and MX disable,MY enable
        write(0,0xa3);                        //line rate 15.2klps
        write(0,0xd1);                        //rgb-rgb
        write(0,0xd5);                        //4k color mode
        write(0,0x84);                        //12:partial display control disable


        /*n-line inversion*/
        write(0,0xc8);
        write(0,0x10);                        //enable NIV

        /*com scan fuction*/
        write(0,0xda);                        //enable FRC,PWM,LRM sequence

        /*window*/
        write(0,0xf4);                        //wpc0:column
        write(0,0x25);                        //start from 130
        write(0,0xf6);                        //wpc1
        write(0,0x5A);                        //end:272

        write(0,0xf5);                        //wpp0:row
        write(0,0x00);                        //start from 0
        write(0,0xf7);                        //wpp1
        write(0,0x9F);                        //end 160

        write(0,0xf8);                        //inside mode

        write(0,0x89);                        //RAM control

        write(0,0xad);                        //display on,select on/off mode.Green Enhance mode disable
       
        /*scroll line*/
        write(0,0x40);                        //low bit of scroll line
        write(0,0x50);                        //high bit of scroll line
        write(0,0xc4);                        //19,enable FLT and FLB
        write(0,0x90);                        //14:FLT,FLB set
        write(0,0x00);

        /*partial display*/
        write(0,0x84);                        //12,set partial display control:off
        write(0,0xf1);                        //com end
        write(0,0x9f);                        //160
        write(0,0xf2);                        //display start
        write(0,0);                                //0
        write(0,0xf3);                        //display end
        write(0,159);                        //160
}


void main()
{
        bm=0;
        rst=1;
        delay_us(10);
        init();       
        while(1)
        {
//                write(0,0x84);
                lcdscan(0xf0,0x0f);
                delay_ms(1000);

               
                write(0xff,0xff);                                //all pixel on
                delay_ms(1500);

                lcdscan(0xff,0x00);                                //横线
                delay_ms(1000);
                write(0,0x41);                                        //scroll 1 line
                delay_ms(1300);
                write(0,0x40);                                        //no scroll

                lcdscan(0x0f,0x0f);                                //竖线
                delay_ms(1000);
                write(0,0xa7);                                        //inverse display
                delay_ms(1500);
                write(0,0xa6);
        }
}
0条回答

一周热门 更多>