標題: 單片機C程序12864,開發(fā)板試驗成功。 [打印本頁]

作者: xl49462870    時間: 2018-1-17 14:30
標題: 單片機C程序12864,開發(fā)板試驗成功。
#include<reg52.h>
#include<intrins.h>
//#include<stdlib.h>  //rand();
#define uint unsigned int
#define uchar unsigned char

#define LCD_data P0;
sbit LCD_RS =P2^6;
sbit LCD_RW =P2^5;
sbit LCD_EN =P2^7;
sbit LCD_PSB = P3^2;
sbit wela =P1^2;
sbit dula=P1^3;

//uchar dis1[10];
uchar code dis1[]={"床前明月光,"};
uchar code dis2[]={"疑是地上霜。"};
uchar code dis3[]={"舉頭望明月,"};
uchar code dis4[]={"低頭思故鄉(xiāng)。"};
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;
LCD_EN=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;
LCD_EN= 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 lcd_init()
{
LCD_PSB=1;
write_cmd(0x30);
delay_1ms(5);
write_cmd(0x0c);
delay_1ms(5);
write_cmd(0x01);
delay_1ms(5);
}

void main()
{
uchar i;
wela=0;
dula=0;
delay_1ms(5);
lcd_init();

while(1)
{
  lcd_pos(0,0);
  i=0;
  while(dis1[i]!='\0')
  {
   write_dat(dis1[i]);
   i++;
  }

lcd_pos(1,0);
i=0;
while(dis2[i]!='\0')
{
  write_dat(dis2[i]);
  i++;
}
delay_1ms(10);


lcd_pos(2,0);
i=0;
while(dis3[i]!='\0')
{
  write_dat(dis3[i]);
  i++;
}
delay_1ms(10);


lcd_pos(3,0);
i=0;
while(dis4[i]!='\0')
{
  write_dat(dis4[i]);
  i++;
}
delay_1ms(10);
}


//delay_1ms(10);


}






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1