你说代码是论坛上的,难道照抄都不会?可见粗心至极!
- #include <STC8h.h>
- #include <stdio.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit RS=P2^5;
- sbit E= P2^6;
- sbit RW=P2^7;
- //sbit DB=P2;
- void delay(uint del) //延时1ms
- {
- uint i,j;
- for(i=0;i<del;i++)
- for(j=0;j<=168;j++);
- }
-
- void writecmd(uchar com)
- {
- E=0; //为什么要写这一条呢,看看时序图就清楚了
- RS=0;
- RW=0;
- P0 = com;
- delay(2); //延时一下会稳定很多,后面一条也是一样的
- E=1;
- delay(2);
- E=0;
- }
- void writedata(uchar dat)
- {
- E=0; //为什么要写这一条呢,看看时序图就清楚了
- RS=1;
- RW=0;
- P0 = dat;
- delay(2); //延时一下会稳定很多,后面一条也是一样的
- E=1;
- delay(2);
- E=0;
- }
- void init(void)
- {
- delay(15);
- writecmd(0x38);
- delay(5);
- writecmd(0x38);
- delay(5);
- writecmd(0x38);
- writecmd(0x38);
- writecmd(0x08);
- writecmd(0x01);
- writecmd(0x06);
- writecmd(0x0c);
- }
- uchar tab1[]=" www.51hei.com "; //要显示什么就在这儿改
- uchar a[]="0123456";
- uchar table2[]="sun";
- uchar week[][3] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
- void main()
- {
- uchar j;
- P_SW2 |= 0x80; //扩展寄存器XFR访问使能
- P0M1 = 0x00; P0M0 = 0x00; //设置为准双向口
- P1M1 = 0x00; P1M0 = 0x00; //设置为准双向口
- P2M1 = 0x00; P2M0 = 0x00; //设置为准双向口
- P3M1 = 0x00; P3M0 = 0x00; //设置为准双向口
- P4M1 = 0x00; P4M0 = 0x00; //设置为准双向口
- P5M1 = 0x00; P5M0 = 0x00; //设置为准双向口
- P6M1 = 0x00; P6M0 = 0x00; //设置为准双向口
- P7M1 = 0x00; P7M0 = 0x00; //设置为准双向口
-
- init();
- writecmd(0x80); //告诉液晶在哪个地方显示 (设置地址指针)//80H+00
- for(j=0;j<16;j++) //有16个字符,要循环16次
- {
- writedata(tab1[j]);
- delay(2);
- }
- while(1);
- }
复制代码
|