代碼如下:
- #ifndef lcd_h
- #define lcd_h
- #include <reg51.h>
- #include <intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define R_D 0xfe //讀數據
- #define R_C 0xfa //讀指令
- #define W_D 0xfc //寫數據
- #define W_C 0xf8 //寫指令
- sbit CS=P3^4;
- sbit SID=P3^3;
- sbit SCLK=P3^2;
- sbit PSB=P2^7;
- sbit RST=P2^6;
- void init_LCD();
- void Write_LCD(uchar con,uchar date);
- //uchar Read_BF(uchar con);
- /********************************************
- 延時毫秒程序
- ********************************************/
- void delay_ms(uint i)
- {
- uint j;
- for(;i>0;i--)
- for(j=114;j>0;j--)
- ;
- }
- void delay_us(uchar i)
- {
-
- for(i;i>0;i--)
- _nop_();
- }
- void Send_Byte(uchar date)
- {
- uchar i;
- //SCLK=0;
- for (i=0;i<8;i++)
- {
- SCLK=0;
- if(date&0x80)
- SID=1;
- else
- SID=0;
- SCLK=1;
- date<<=1;
-
- }
- }
- uchar Read_Byte()
- {
- uchar i;
- uchar temp,temp1,temp2;
- for(i=0;i<8;i++)
- {
- temp1<<=1;
- SCLK=0;
- SCLK=1;
- SCLK=0;
- if(SID)
- temp1+=1;
- //SCLK=1;
- }
- for(i=0;i<8;i++)
- {
- temp2<<=1;
- SCLK=0;
- SCLK=1;
- SCLK=0;
- if(SID)
- temp2+=1;
- //SCLK=1;
- }
- temp1=0xf0&temp1;
- temp2>>=4;
- temp=temp1+temp2;
- return temp;
-
- }
- void CheckBusy()
- {
- Send_Byte(0xfc);
- while(0x80&Read_Byte());
-
- }
-
- void Write_LCD(uchar con,uchar date)
- {
- uchar date_h,date_l;
- date_h=date&0xf0;
- date_l=(date&0x0f)<<4;
- CS=1;
- CheckBusy();
- Send_Byte(con);
- //delay_us(100);
- Send_Byte(date_h);
- //delay_us(100);
- Send_Byte(date_l);
- CS=0;
- delay_us(100);
- }
- void init_LCD()
- {
-
- delay_ms(40);
- RST=0;
- delay_us(100);
- RST=1;
- PSB=0;
- Write_LCD(W_C,0x30);
- delay_us(100);
- Write_LCD(W_C,0x30);
- delay_us(137);
- Write_LCD(W_C,0x0c);
- delay_us(100);
- Write_LCD(W_C,0x01);
- delay_ms(10);
- Write_LCD(W_C,0x06);
- }
- #endif
復制代碼
main函數
- #include <reg51.h>
- #include "lcd.h"
- //#include "sht11.h"
- uchar str[]={"1234567890123456"};
- void main()
- {
- uchar i;
- init_LCD();
- while(1)
- {
-
- Write_LCD(W_C,0x80);
- for(i=0;i<16;i++)
- {
- Write_LCD(W_D,str[i]);
- }
- }
- }
復制代碼
照著各種資料都調試了,就是不行,跪求大神指點
|