#include <reg51.h>
#include <intrins.h>
#include <stdlib.h>
#define uchar unsigned char
#define uint unsigned int
#define LCD_data P0
sbit LCD_RS = P2^0;
sbit LCD_RW = P2^1;
sbit LCD_EN = P1^2;
sbit LCD_PSB = P2^6;
uchar dis1[10];
uchar code dis2[] = {"www.txmcu.com"};
uchar code dis3[] = {"龙卷风"};
uchar code dis4[] = {"--------"};
void cls_buzz(void)
{
P2 = (P2&0x1f|0xA0);
P0 = 0x00;
P2 = 0x1f;
P2 = (P2&0x1f|0x80);
P0 = 0xff;
P2 = 0x1f;
P2 = (P2&0x1f|0xc0);
P0 = 0x00;
P2 = 0x1f;
P2 = (P2&0x1f|0xe0);
P0 = 0xff;
P2 = 0x1f;
}
void delay_1ms(uint x)
{
uint i,j;
for(j=0;j<x;j++)
for(i=0;i<110;i++);
}
void write_cmd(uchar cmd)
{
LCD_RS = 0;
LCD_RW = 0;
P0 = cmd;
delay_1ms(5);
LCD_EN = 1;
delay_1ms(5);
LCD_EN = 0;
}
void write_dat(uchar dat)
{
LCD_RS = 1;
LCD_RW = 0;
P0 = dat;
delay_1ms(5);
LCD_EN = 1;
delay_1ms(5);
LCD_EN = 0;
}
void lcd_pos(uchar X,uchar Y)
{
uchar pos;
if (X==0)
{X=0x80;}
else if (X==1)
{X=0x90;}
else if (X==2)
{X=0x88;}
else if (X==3)
{X=0x98;}
pos = X+Y ;
write_cmd(pos);
}
void makerand()
{
uint ran;
ran=rand();
dis1[0]=ran/10000+0x30;
dis1[1]=ran%10000/1000+0x30;
dis1[2]=ran%1000/100+0x30;
dis1[3]=ran%100/10+0x30;
dis1[4]=ran%10+0x30;
ran=rand();
dis1[5]=ran/10000+0x30;
dis1[6]=ran%10000/1000+0x30;
dis1[7]=ran%1000/100+0x30;
dis1[8]=ran%100/10+0x30;
dis1[9]=ran%10+0x30;
}
void lcd_init()
{
LCD_PSB = 1; //2¢¿ú·½ê½
write_cmd(0x30); //»ù±¾Ö¸áî2ù×÷
delay_1ms(5);
write_cmd(0x0C); //ÏÔ꾿a£¬1Ø1a±ê
delay_1ms(5);
write_cmd(0x01); //Çå3yLCDμÄÏÔê¾ÄúèY
delay_1ms(5);
}
void main()
{
uchar i;
cls_buzz();
delay_1ms(10);
lcd_init();
lcd_pos(1,0);
while(dis2[i] != '\0')
{
write_dat(dis2[i]);
i++;
}
lcd_pos(2,0);
i = 0;
while(dis3[i] != '\0')
{
write_dat(dis3[i]);
}
lcd_pos(3,0);
i = 0;
while(dis4[i] != '\0')
{
write_dat(dis4[i]);
i++;
}
while(1)
{
lcd_pos(0,0);
makerand();
for(i=0;i<10;i++)
{
write_dat(dis1[i]);
}
}
}
原代码如上,用12864液晶显示三行数据
代码是例程,我就改了sbit的端口数据,因为是在另一块板子上弄
但是怎么都没显示
求指教~
|