c51驅動12864顯示隨機數proteus無法出結果??!:初學單片機,想做個顯示隨機數的電路,但是怎么都無法出結果,程序通過編譯了。。。。高手幫忙指點迷津?。?!謝謝啊~~~~
電路圖: (圖片可能顯示不出來,電路圖也上傳了附件)
http://www.eehome.cn/file:///C:/Users/lzt/AppData/Local/Temp/msohtml1/01/clip_image002.jpg
程序:
#include<reg51.h>
#include<intrins.h>
#include<stdlib.h>
#define uchar unsigned char
#define uint unsigned int
/*端口定義*/
#define LCD_data P0
sbit LCD_RS = P3^5;
sbit LCD_RW = P3^6;
sbit LCD_EN = P3^4;
sbit LCD_PSB = P3^7;
sbit wela = P2^6;
sbit dula = P2^7;
uchar dis0[10];
uchar code dis1[]={"ww"};
uchar code dis2[]={"ww"};
uchar code dis3[]={"ww"};
void delay_1ms(uint x)
{
uint i,j;
for(j=0;j<x;j++)
for(i=0;i<110;i++);
}
/*寫指令數據到LCD*/
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;
}
/*寫顯示數據到LCD*/
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 makerand()
{
uint ran;
ran=rand();
dis0[0]=ran/10000+0x30;
dis0[1]=ran%10000/1000+0x30;
dis0[2]=ran%1000/100+0x30;
dis0[3]=ran%100/10+0x30;
dis0[4]=ran%10+0x30;
ran=rand();
dis0[5]=ran/10000+0x30;
dis0[6]=ran%10000/1000+0x30;
dis0[7]=ran%1000/100+0x30;
dis0[8]=ran%100/10+0x30;
dis0[9]=ran%10+0x30;
}
/*LCD初始化設定*/
void lcd_init()
{
LCD_PSB = 1;
write_cmd(0x30);
delay_1ms(5);
write_cmd(0x0C);
delay_1ms(5);
write_cmd(0x01);
delay_1ms(5);
}
main()
{
uchar i;
wela=0;
dula=0;
delay_1ms(10); //延時
lcd_init(); //初始化LCD
lcd_pos(1,0); //設置顯示位置為第二行的第一個字符
i=0;
while(dis1!='\0')
{
write_dat(dis1);
i++;
}
lcd_pos(2,0);
i=0;
while(dis2!='\0')
{
write_dat(dis2);
i++;
}
lcd_pos(3,0);
i=0;
while(dis3!='\0')
{
write_dat(dis3);
i++;
}
while(1)
{
lcd_pos(0,0);
makerand();
for(i=0;i<10;i++)
{
write_dat(dis0);
}
}
}