lzf713 发表于 2010-5-3 19:37:22

俄罗斯方块(LCD12864显示+仿真)

参考网上资料,编写了一个俄罗斯方块,使用LCD12864显示。效果自我感觉还可以。
界面如下:
http://cache.amobbs.com/bbs_upload782111/files_28/ourdev_551271.JPG
仿真界面 (原文件名:方块.JPG)

程序:
#include <AT89X51.H>
#define uchar unsigned char
#define uintunsigned int
#define DOWNTIME 30
#define MAXHANG 20
#define MAXLIE16
#define MAXPIX3
#define PUSHON50

#define LCD P2
#define ENP3_0
#define RWP3_1
#define RSP3_2
#define CS1 P3_3
#define CS2 P3_4

#define KEYLEFT P3_5
#define KEYDOWN P3_6
#define KEYRIGH P3_7
#define KEYROTATION P1_0

uchar gkey=0xff,keystate=0,t0ms1=0,t0ms=0,downtimegap=0;
uchar miao=0,fen=0;
uchar downok;
bit keyflag,timeupdate,fashionupdate;
uchar idata cubeMap;
typedef struct{
               uchar code * box;
                           uchar cube : 4;
                           uchar state : 4;
                           char row;
                           char column;
                           } block;
block this;
uint score=0;
uchar speed=1;
uchar code bittable={1,2,4,8,0x10,0x20,0x40,0x80};
uchar code cube[]=
{
/*■
■■■
*/
0,4,0xe,0,0,2,6,2,   0,7,2,0,   4,6,4,0,

/*■
■■■
*/
0,8,0xe,0,0,4,4,0xc,   0,0,0xe,2,   0,6,4,4,
/*■■■
■   
*/
0,0xe,8,0,0,4,4,6,   0,1,7,0,   6,2,2,0,
/*■■
    ■■
*/
0,0xc,6,0,0,2,6,4,   0,6,3,0,   2,6,4,0,
/*■■
■■
*/
0,6,0xc,0,0,4,6,2,   0,3,6,0,   4,6,2,0,
/*■■■■
*/
0,0xf,0,0,4,4,4,4,   0,0,0xf,0,   2,2,2,2,
/*■■
■■
*/
0,6,6,0,    0,6,6,0,   0,6,6,0,   0,6,6,0
};
uchar code asii[]=
{
    0x3E,0x51,0x49,0x45,0x3E, // -0-
    0x00,0x42,0x7F,0x40,0x00, // -1-
    0x62,0x51,0x49,0x49,0x46, // -2-
    0x21,0x41,0x49,0x4D,0x33, // -3-
    0x18,0x14,0x12,0x7F,0x10, // -4-
    0x27,0x45,0x45,0x45,0x39, // -5-
    0x3C,0x4A,0x49,0x49,0x31, // -6-
    0x01,0x71,0x09,0x05,0x03, // -7-
    0x36,0x49,0x49,0x49,0x36, // -8-
    0x46,0x49,0x49,0x29,0x1E, // -9-
    0x00,0x36,0x36,0x00,0x00, // -:-10
//next
    0x7F,0x04,0x08,0x10,0x7F, // -N-11
    0x7F,0x49,0x49,0x49,0x41, // -E-12
    0x63,0x14,0x08,0x14,0x63, // -X-13
    0x01,0x01,0x7F,0x01,0x01, // -T-14
//speed
    0x26,0x49,0x49,0x49,0x32, // -S-15
    0x7F,0x09,0x09,0x09,0x06, // -P-16
    0x7F,0x49,0x49,0x49,0x41, // -E-17
    0x7F,0x41,0x41,0x41,0x3E, // -D-18
//score
    0x3E,0x41,0x41,0x41,0x22, // -C-19   
    0x3E,0x41,0x41,0x41,0x3E, // -O-20
    0x7F,0x09,0x19,0x29,0x46, // -R-21
    0x00,0x00,0x00,0x00,0x00,// - -22
//GAME OVER
    0x3E,0x41,0x51,0x51,0x72, // -G-23
    0x7C,0x12,0x11,0x12,0x7C, // -A-24
    0x7F,0x02,0x0C,0x02,0x7F, // -M-25
    0x1F,0x20,0x40,0x20,0x1F, // -V-26
//TIME
//0x00,0x41,0x7F,0x41,0x00// -I-27
};
////////////////////////////////////////////////////////////////////////////////
void lcdCmd(uchar cmd)
{
bit ea;
ea=EA;
EA=0;
EN=0;
RW=0;
RS=0;
LCD=cmd;
EN=1;
EN=1;
EN=0;
EA=ea;
}
//-------------------------------------------------------------------------------
void lcdWriteByte(uchar ch)
{
EN=0;
RS=1;
RW=0;
LCD=ch;
EN=1;
EN=1;
EN=0;
}
//--------------------------------------------------------------------------------
void lcdSetPage(uchar page)
{
page &=0x7;
page +=0xb8;
lcdCmd(page);
}
//--------------------------------------------------------------------------------
void lcdSetColumn(uchar column)
{
column &=0x3f;
column +=0x40;
lcdCmd(column);
}
//--------------------------------------------------------------------------------
//character fron=5*8
void lcdPlayChar(uchar index,uchar page,uchar colume)
{
uchar i,temp;
uint p;
p=5*index;
for(i=colume;i<colume+5;i++)
{
    if(i<64)
       {
          CS1=1;
          CS2=0;
          temp=i;
       }
        else
       {
          CS1=0;
          CS2=1;
          temp=i-64;
       }
        lcdSetPage(page);
        lcdSetColumn(temp);
        lcdWriteByte(asii);
}
}
//---------------------------------------------------------------------------------
//rectangle(3,0,50,60)
void rectangle(void)
{
uchar i,page;
CS1=1;
CS2=0;
lcdSetPage(0);
lcdSetColumn(2);
EN=0;
RS=1;
RW=0;
LCD=0xff;
EN=1;
EN=1;
EN=0;
for(i=3;i<51;i++)
   {
   EN=0;
   RS=1;
   RW=0;
   LCD=0x1;
   EN=1;
   EN=1;
   EN=0;   
   }
EN=0;
RS=1;
RW=0;
LCD=0xff;
EN=1;
EN=1;
EN=0;
//---------------------------
for(page=1;page<7;page++)
{
lcdSetPage(page);
lcdSetColumn(2);
EN=0;
RS=1;
RW=0;
LCD=0xff;
EN=1;
EN=1;
EN=0;
for(i=3;i<51;i++)
   {
   EN=0;
   RS=1;
   RW=0;
   LCD=0x0;
   EN=1;
   EN=1;
   EN=0;   
   }
EN=0;
RS=1;
RW=0;
LCD=0xff;
EN=1;
EN=1;
EN=0;
}
//---------------------------
lcdSetPage(7);
lcdSetColumn(2);
EN=0;
RS=1;
RW=0;
LCD=0x1f;
EN=1;
EN=1;
EN=0;
for(i=3;i<51;i++)
   {
   EN=0;
   RS=1;
   RW=0;
   LCD=0x10;
   EN=1;
   EN=1;
   EN=0;   
   }
EN=0;
RS=1;
RW=0;
LCD=0x1f;
EN=1;
EN=1;
EN=0;
}
//--------------------------------------------------------------------
//x:列;y行,页 3*3
void lcdPutPix(uchar x, uchar y,uchar flag)
{
uchar i,dat,bitmask,nextbit;
bit bflag,pflag,ea;
x=x*MAXPIX;
y=y*MAXPIX;
bflag=0;
pflag=0;
i=y%8;
if(i==0)
   bitmask=0x7;
else if(i==1)
   bitmask=0xe;
else if(i==2)
   bitmask=0x1c;
else if(i==3)
   bitmask=0x38;
else if(i==4)
   bitmask=0x70;
else if(i==5)
   bitmask=0xe0;
else if(i==6)
   {
    bflag=1;
    bitmask=0xc0;
    nextbit=1;
   }
else if(i==7)
   {
    bflag=1;
    bitmask=0x80;
    nextbit=3;
   }
if(x<62)
   {
    CS1=1;
    CS2=0;
   }
else if(x>63)
   {
    x-=64;
    CS1=0;
    CS2=1;
   }
else
   pflag=1;
lcdSetPage(y/8);
for(i=x;i<x+MAXPIX;i++)
   {
    if(pflag)
   {
      if(i==62 || i==63)
       {
         CS1=1;
         CS2=0;
         lcdSetPage(y/8);
      }
      else if(pflag && i==64)
       {
      CS1=0;
      CS2=1;
      lcdSetPage(y/8);
       }
      }
   lcdSetColumn(i);
   ea=EA;
   EA=0;
   EN=0;
   LCD=0xff;
   RS=1;
   RW=1;
   EN=1;
   EN=0;

   EN=1;
   dat=LCD;
   EN=0;
   if(flag==1)
       dat|=bitmask;
   else
       dat&=~bitmask;
   lcdSetColumn(i);

   EN=0;
   RW=0;
   RS=1;
   LCD=dat;
   EN=1;
   EN=1;
   EN=0;
   EA=ea;
   }
if(bflag)
{
   lcdSetPage(y/8+1);
   for(i=x;i<x+MAXPIX;i++)
   {
    if(pflag)
   {
      if(i==62 || i==63)
       {
      CS1=1;
      CS2=0;
      lcdSetPage(y/8+1);
       }
      else if(pflag && i==64)
       {
      CS1=0;
      CS2=1;
      lcdSetPage(y/8+1);
       }
      }
   lcdSetColumn(i);
   ea=EA;
   EA=0;
   EN=0;
   LCD=0xff;
   RS=1;
   RW=1;
   EN=1;
   EN=0;

   EN=1;
   dat=LCD;
   EN=0;
   if(flag==1)
       dat|=nextbit;
   else
       dat&=~nextbit;
   lcdSetColumn(i);

   EN=0;
   RW=0;
   RS=1;
   LCD=dat;
   EN=1;
   EN=1;
   EN=0;
   EA=ea;
}
}
}
//------------------------------------------------------------------
void lcdClear(void)
{
uchar i,page;
CS1=1;
CS2=0;
for(page=0;page<8;page++)
   {
    lcdSetPage(page);
    lcdSetColumn(0);
    for(i=0;i<64;i++)
           lcdWriteByte(0);
   }
CS1=0;
CS2=1;
for(page=0;page<8;page++)
   {
    lcdSetPage(page);
    lcdSetColumn(0);
    for(i=0;i<64;i++)
           lcdWriteByte(0);
   }
}
//-----------------------------------------------------------------
#define STAR 53
#define WIDE 6
void lcdIni(void)
{
lcdCmd(0x3f);
lcdCmd(0xc0);
lcdClear();
rectangle();
//NEXT
lcdPlayChar(11,0,STAR);
lcdPlayChar(12,0,STAR+1*WIDE);
lcdPlayChar(13,0,STAR+2*WIDE);
lcdPlayChar(14,0,STAR+3*WIDE);
//SPEED
lcdPlayChar(15,3,STAR);
lcdPlayChar(16,3,STAR+1*WIDE);
lcdPlayChar(17,3,STAR+2*WIDE);
lcdPlayChar(17,3,STAR+3*WIDE);
lcdPlayChar(18,3,STAR+4*WIDE);
//01
lcdPlayChar(0,4,STAR+2*WIDE);
lcdPlayChar(1,4,STAR+3*WIDE);

//SCORE
lcdPlayChar(15,5,STAR);
lcdPlayChar(19,5,STAR+1*WIDE);
lcdPlayChar(20,5,STAR+2*WIDE);
lcdPlayChar(21,5,STAR+3*WIDE);
lcdPlayChar(12,5,STAR+4*WIDE);

lcdPlayChar(0,6,STAR+1*WIDE);
lcdPlayChar(0,6,STAR+2*WIDE);
lcdPlayChar(0,6,STAR+3*WIDE);
lcdPlayChar(0,6,STAR+4*WIDE);
//TIME
lcdPlayChar(0,7,STAR);
lcdPlayChar(0,7,STAR+1*WIDE);
lcdPlayChar(10,7,STAR+2*WIDE);
lcdPlayChar(0,7,STAR+3*WIDE);
lcdPlayChar(0,7,STAR+4*WIDE);
}
//-----------------------------------------------------------------
void showScoreSpeed(void)
{
uchar num;
char i;
uint temp;
temp=score;
for(i=0;i<5;i++)
   {
   num=temp%10;
       temp=temp/10;
   }
for(i=4;i>0;i--)
   {
   if(num==0)
          num=22;
       else
          break;
   }
for(i=4;i>-1;i--)
   lcdPlayChar(num,6,STAR+(4-i)*WIDE);

lcdPlayChar(speed/10,4,STAR+2*WIDE);
lcdPlayChar(speed%10,4,STAR+3*WIDE);
}
//-------------------------------------------------------------------
void timeServer(void)
{
if(timeupdate)
   {
    timeupdate=0;
    lcdPlayChar(fen/10,7,STAR);
    lcdPlayChar(fen%10,7,STAR+1*WIDE);
    lcdPlayChar(10,7,STAR+2*WIDE);
    lcdPlayChar(miao/10,7,STAR+3*WIDE);
    lcdPlayChar(miao%10,7,STAR+4*WIDE);   
   }
if(fashionupdate)
   {
   fashionupdate=0;
   lcdPlayChar(22,7,STAR+2*WIDE);
   }
}
//===================================================================
void t0isr(void) interrupt 1
{
uchar key;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
downtimegap++;
t0ms=++t0ms%100;
if(t0ms==0)
   {
   timeupdate=1;
   miao=++miao%60;
       if(miao==0)
          fen=++fen%60;
   }
if(t0ms==50)
   fashionupdate=1;
//----------------------------
key=0xff;
KEYLEFT=1;
KEYRIGH=1;
KEYROTATION=1;
KEYDOWN=1;
if(!KEYLEFT)
    key=0;
if(!KEYRIGH)
    key=1;
if(!KEYROTATION)
    key=2;
if(!KEYDOWN)
    key=3;

switch(keystate)
   {
    case 0: if(key!=gkey)
                 {
                          gkey=key;
                          keystate=1;
                       }
                        break;
   case 1: if(key==gkey)
             {
                           t0ms1=0;
                           keystate=2;
                           if(key!=0xff)
                             keyflag=1;
                       }
                   else
                     keystate=0;
                   break;
   case 2: if(key==gkey)
             {
                           if(t0ms1<PUSHON)
                             t0ms1++;
                       }
                   else
                  {
                          keystate=0;
                          keyflag=0;
                          gkey=0xff;
                        }
                   break;
   }

}
//===================================================================
void showNextCube(uchar code * p,uchar x,uchar y)
{
uchar i,j,temp;
for(i=0;i<4;i++)
   {
      temp=1;
      for(j=0;j<4;j++)
      {
      if(p & temp)
         lcdPutPix(x+j,y+i,1);
      else
         lcdPutPix(x+j,y+i,0);
      temp<<=1;
      }
   }
}
//------------------------------------------------------------------
void createCube(void)
{
static uchar next;
this.cube=next;
next=TL0%7;
this.row=0;
this.column=6;
this.state=0;
this.box=cube+16*this.cube;
showNextCube(cube+16*next,19,3);
}
//------------------------------------------------------------------
void showCubeMap(void)
{
unsigned char hang,lie,temp;
for(hang=MAXHANG-1;hang>0;hang--)
{
   if(cubeMap==0 && cubeMap==0)
   break;

   for(lie=0;lie<(MAXLIE/8);lie++)
    {
   temp=8*lie;
   if(cubeMap&0x01)
       lcdPutPix(temp+1,hang,1);

   if(cubeMap&0x02)
       lcdPutPix(temp+2,hang,1);

   if(cubeMap&0x04)
       lcdPutPix(temp+3,hang,1);

   if(cubeMap&0x08)
       lcdPutPix(temp+4,hang,1);

   if(cubeMap&0x10)
       lcdPutPix(temp+5,hang,1);

   if(cubeMap&0x20)
       lcdPutPix(temp+6,hang,1);

   if(cubeMap&0x40)
       lcdPutPix(temp+7,hang,1);

   if(cubeMap&0x80)
       lcdPutPix(temp+8,hang,1);
    }
}
}
//-------------------------------------------------------------------
void writeCubeToMap(void)
{
uchar row,column,temp;
uchar hang,lie;
for(row=0;row<4;row++)
   {
   temp=1;
   for(column=0;column<4;column++)
          {
          if(this.box & temp)
               {
                   hang=this.row+row;
                   lie=this.column+column;
         cubeMap |=bittable;
             lcdPutPix(lie+1,hang,1);                          
               }
                temp<<=1;
          }
   }
}
//-------------------------------------------------------------------
void clearCubeFromMap(void)
{
uchar row,column,temp;
uchar hang,lie;
for(row=0;row<4;row++)
   {
   temp=1;
   for(column=0;column<4;column++)
          {
          if(this.box & temp)
               {
                   hang=this.row+row;
                   lie=this.column+column;
         cubeMap &=~bittable;
             lcdPutPix(lie+1,hang,0);                  
               }
                temp<<=1;
          }
   }
}
//-------------------------------------------------------------------
uchar checkBorder(void)
{
if(this.box!=0 && this.row>(MAXHANG-4))
    return 1;
else if(this.box!=0 && this.row>(MAXHANG-3))
    return 1;
else if(this.box!=0 && this.row>(MAXHANG-2))
    return 1;
else if(this.box!=0 && this.row>(MAXHANG-1))
    return 1;
//---------------------
if((this.box & 0x01) || (this.box & 0x01) || (this.box & 0x01) ||(this.box & 0x01) )
   {
   if(this.column<0)
      return 1;
   }   
else if((this.box & 0x02) || (this.box & 0x02) || (this.box & 0x02) ||(this.box & 0x02) )
   {
   if(this.column<-1)
      return 1;
   }
else if((this.box & 0x04) || (this.box & 0x04) || (this.box & 0x04) ||(this.box & 0x04) )
   {
   if(this.column<-2)
      return 1;
   }
   else if((this.box & 0x08) || (this.box & 0x08) || (this.box & 0x08) ||(this.box & 0x08) )
   {
   if(this.column<-3)
      return 1;
   }
//---------------------
if((this.box & 0x08) || (this.box & 0x08) || (this.box & 0x08) ||(this.box & 0x08) )
   {
   if(this.column>(MAXLIE-4))
      return 1;
   }   
else if((this.box & 0x04) || (this.box & 0x04) || (this.box & 0x04) ||(this.box & 0x04) )
   {
   if(this.column>(MAXLIE-3))
      return 1;
   }
else if((this.box & 0x02) || (this.box & 0x02) || (this.box & 0x02) ||(this.box & 0x02) )
   {
   if(this.column>(MAXLIE-2))
      return 1;
   }
else if((this.box & 0x08) || (this.box & 0x08) || (this.box & 0x08) ||(this.box & 0x08) )
   {
   if(this.column>(MAXLIE-1))
      return 1;
   }
//--------------------
return 0;
}
//------------------------------------------------------------------
uchar checkClask(void)
{
uchar row,column,temp;
uchar hang,lie;
for(row=0;row<4;row++)
   {
   temp=1;
   for(column=0;column<4;column++)
          {
          if(this.box & temp)
              {
                  hang=this.row+row;
                        lie=this.column+column;
                  if(cubeMap & bittable)
                          return 1;
                  }
                temp<<=1;
          }
   }
return 0;
}
//-------------------------------------------------------------------
void checkMap(void)
{
uchar i,j,delete;
bit full;
full=0;
delete=0;
for(i=MAXHANG-1;i>0;i--)
   {
   if(cubeMap==0 && cubeMap==0)
           break;
       if(cubeMap==0xff && cubeMap==0xff)
           {
             delete++;
               full=1;
               for(j=i;j>0;j--)
                  {
                  cubeMap=cubeMap;
                  cubeMap=cubeMap;
                  }
               i++;
               cubeMap=0;
               cubeMap=0;
           }
   }
if(full)
{
    if(delete==1)
          score++;
        else if(delete==2)
          score+=4;
        else if(delete==3)
          score+=9;
        else if(delete==4)
          score+=16;
        rectangle();
        showCubeMap();
    if(score<50)
       speed=1;
        else if(score<100)
       speed=2;
        else if(score<500)
       speed=3;
        else if(score<1000)
       speed=4;
        else if(score<5000)
       speed=5;
        else if(score<10000)
       speed=6;
        else if(score<20000)
       speed=7;
        else if(score<30000)
       speed=8;
        else if(score<40000)
       speed=9;
        else if(score<50000)
       speed=10;
        else if(score<60000)
       speed=11;
        else
       speed=12;
        showScoreSpeed();
}
}
//-------------------------------------------------------------------
void moveLeft(void)
{
clearCubeFromMap();
this.column--;
if(checkBorder() || checkClask())
    this.column++;
writeCubeToMap();
}
//-------------------------------------------------------------------
void moveRigh(void)
{
clearCubeFromMap();
this.column++;
if(checkBorder() || checkClask())
    this.column--;
writeCubeToMap();
}
//-------------------------------------------------------------------
void moveDown(void)
{
clearCubeFromMap();
this.row++;
if(checkBorder() || checkClask())
   {
    this.row--;
        downok=1;
   }
else
   downok=0;
writeCubeToMap();
if(downok)
    checkMap();
}
//------------------------------------------------------------------
void cubeRotation(void)
{
uchar temp;
temp=this.state;
clearCubeFromMap();
this.state=++this.state%4;
this.box=cube+16*this.cube+4*this.state;
if(checkBorder() || checkClask())
   {
   this.state=temp;
   this.box=cube+16*this.cube+4*this.state;
   }
writeCubeToMap();
}
/////////////////////////////////////////////////////////////////////
void main(void)
{
TMOD=0x1;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
EA=1;
ET0=1;
TR0=1;
lcdIni();
for(t0ms=0;t0ms<MAXHANG;t0ms++)
   {
   cubeMap=0;
   cubeMap=0;
   }
while(1)
   {
   createCube();
       if(checkClask())
          {
       rectangle();
#define SHOWSTAR 12
#define GAP 8
       lcdPlayChar(23,2,SHOWSTAR); //GAME
       lcdPlayChar(24,2,SHOWSTAR+GAP);           
       lcdPlayChar(25,2,SHOWSTAR+2*GAP);
       lcdPlayChar(12,2,SHOWSTAR+3*GAP);

       lcdPlayChar(20,4,SHOWSTAR); //OVER   
       lcdPlayChar(26,4,SHOWSTAR+GAP);
       lcdPlayChar(12,4,SHOWSTAR+2*GAP);
       lcdPlayChar(21,4,SHOWSTAR+3*GAP);
       t0ms=0;
       while(t0ms<95);//延时2秒
           t0ms=0;
       while(t0ms<95);
       ((void (code *) (void)) 0x0000) ( );           
          }
   while(1)
          {
                timeServer();
          if(keyflag)
               {
                   keyflag=0;
                   t0ms1=0;
                   if(gkey==0)
                     moveLeft();
                   if(gkey==1)
                     moveRigh();
                   if(gkey==2)
                     cubeRotation();
                   if(gkey==3)
                     moveDown();                     
               }
       if(gkey==0 && t0ms1==PUSHON)
          {
                  t0ms1-=10;
                  moveLeft();
                }
       if(gkey==1 && t0ms1==PUSHON)
          {
                  t0ms1-=10;
                  moveRigh();
                }
       if(gkey==3 && t0ms1==PUSHON)
          {
                  t0ms1-=10;
                  moveDown();
                }
           if(downtimegap>(DOWNTIME-speed))
          {
             moveDown();
               downtimegap=0;
                }
           if(downok)
          {
                  downok=0;
                  break;
                }
          }
   }
}

lv998127 发表于 2010-5-3 19:44:12

沙发

lzf713 发表于 2010-5-3 19:50:24

整个工程文件(编译软件:KEIL)以及仿真文件:
俄罗斯方块ourdev_551273.rar(文件大小:76K) (原文件名:myblock.rar)
参考资料:
http://www.ourdev.cn/bbs/bbs_content.jsp?bbs_sn=1429911&bbs_page_no=1&search_mode=1&search_text=俄罗斯方块&bbs_id=1006
以及在PC,DOS系统下运行的(编译软件:TC2.0)(将后缀名txt改为:c)
点击此处下载 ourdev_551278.txt(文件大小:20K) (原文件名:els.txt)

jokecoke 发表于 2010-5-3 20:07:19

不错嘛,要是有详细注释就好了。。。

jeep 发表于 2010-5-3 21:11:08

可以横显示吗

lzf713 发表于 2010-5-3 22:35:50

本程序不可以横着显示,但是可以改,很简单的事情,我刚开始的时候是横着方向下落方块的,后来才改为垂直下落方块的。
方法是:
描点的方式改一下,检查冲突也要改,显示数字和字母所取点方式也要改。

guhenggao 发表于 2010-5-4 11:21:24

mark

binaimei2007 发表于 2010-5-4 11:51:34

厉害mark

yusufu 发表于 2010-5-4 12:44:38

mark

zzg207 发表于 2010-5-4 16:56:42

楼主,向你学习!!!!!

lzf713 发表于 2010-5-4 23:33:14

回复【5楼】lzf713
本程序不可以横着显示,但是可以改,很简单的事情,我刚开始的时候是横着方向下落方块的,后来才改为垂直下落方块的。
方法是:
描点的方式改一下,检查冲突也要改,显示数字和字母所取点方式也要改。
-----------------------------------------------------------------------
也许有人不相信,上图:
http://cache.amobbs.com/bbs_upload782111/files_28/ourdev_551583.JPG
(原文件名:横向跑俄罗斯方块.JPG)

jzlxue 发表于 2010-5-5 15:30:24

强帖留名

liok 发表于 2010-5-5 17:36:29

留下日后以定看!这个东西想把它弄出来!

wjw123abc 发表于 2010-6-21 19:55:16

biao ji

lffpga 发表于 2010-6-21 21:12:51

MARK

hwx123 发表于 2010-6-21 22:03:16

参考下。谢谢分享

lujiawei2010 发表于 2010-6-22 01:54:59

mark.......

guhenggao 发表于 2010-6-22 09:43:08

mark

easyou 发表于 2010-6-22 10:25:50

谢谢楼主分享!

zhuyi25762 发表于 2010-6-22 12:14:06

牛人

shwp 发表于 2010-6-26 01:12:11

hehe,攒

xzm8469105 发表于 2010-6-26 10:36:23

MARK

wkman 发表于 2010-6-26 15:28:45

强。手上有类似组合的实物,可以耍耍。。

feixue2588 发表于 2010-6-26 16:17:13

mark!!!

Digger 发表于 2010-6-26 20:28:46

学习的好文章!!!

谢谢楼主无私奉献源码

yasewang2 发表于 2010-6-26 21:05:47

标记一下

yuyan 发表于 2010-6-27 19:11:17

学习啦…刚做完贪吃蛇…最近和游戏干上了…

qtds11 发表于 2010-6-28 16:17:47

ding

sand 发表于 2010-6-28 18:53:20

真帅~~~学习了

cu_ice 发表于 2010-6-28 19:58:06

mark
good

tobe1989 发表于 2010-7-1 15:58:25

Mark

lxa0 发表于 2010-7-5 00:35:24

好玩~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

AVRnew 发表于 2010-7-8 15:43:30

学习中

438219660 发表于 2010-7-16 05:09:37

mark一下

s3c2440 发表于 2010-7-18 17:41:19

楼主真厉害

affe33 发表于 2010-7-29 05:59:49

确实能用,楼主确实很有实力啊

pish 发表于 2010-7-29 10:32:33

顶一下,让更多人知道~

heibaogame 发表于 2010-7-29 11:02:19

学习中

myqiang1990 发表于 2010-7-29 12:07:23

好。。看看。。。站在

heibaogame 发表于 2010-7-29 13:17:01

顶顶!

mcu_mouse 发表于 2010-7-30 20:48:19

mark

sdccd 发表于 2010-8-3 20:36:22

回复【楼主位】lzf713
-----------------------------------------------------------------------

佩服!

lzm8871043 发表于 2010-8-11 16:55:38

太强了楼主

cuikai12345 发表于 2010-8-11 21:19:42

mark

lx2421 发表于 2010-8-13 15:45:49

mark

zxhpl 发表于 2010-8-17 15:37:23

有注释就好了

kayhao 发表于 2010-8-17 16:11:53

racemaker 发表于 2010-9-2 09:50:17

MARK!

739797340 发表于 2010-9-7 19:31:29

mark

andrew_dj 发表于 2010-9-7 20:30:15

不错

gcdtad 发表于 2010-9-8 21:47:20

mark

packsoy 发表于 2010-9-8 22:32:55

mark

flame0510 发表于 2010-9-8 23:07:01

等有空了, 咱也弄一个玩玩

heyunqingfeng 发表于 2010-9-11 11:59:34

可惜,这个程序做的太繁琐了。。。

lzf713 发表于 2010-9-11 20:43:09

回复【54楼】heyunqingfeng
-----------------------------------------------------------------------

高人那!

也许void lcdPutPix(uchar x, uchar y,uchar flag) 这个函数比较复杂,但是这样做的目的就是想加快画点速度。这个程序仿真是可行的,但是用实物就不行了,出现画屏情况。问题就在void lcdPutPix(uchar x, uchar y,uchar flag) 这个函数,原因是画点过程是这样的:根据将要在X,Y位置所在的单元数据读取回来(要读取三个单元),然后修改,再回写。问题出现在读取单元数据,延迟不够。
原来:
lcdSetColumn(i);
   ea=EA;
   EA=0;
   EN=0;
   LCD=0xff;
   RS=1;
   RW=1;
   EN=1;
   EN=0;

   EN=1;
   dat=LCD;
   EN=0;
   if(flag==1)
       dat|=bitmask;
   else
       dat&=~bitmask;
   lcdSetColumn(i);   

   EN=0;
   RW=0;
   RS=1;
   LCD=dat;
   EN=1;
   EN=1;
   EN=0;
   EA=ea;
   }
可以改为:
lcdSetColumn(i);
   ea=EA;
   EA=0;
   EN=0;
   LCD=0xff;
   RS=1;
   RW=1;
   EN=1;
   EN=0;
   EN=0;//增加延迟

   EN=1; //增加延迟
   EN=1; //增加延迟
   EN=1;
   dat=LCD;
   EN=0;
   if(flag==1)
       dat|=bitmask;
   else
       dat&=~bitmask;
   lcdSetColumn(i);   

   EN=0;
   RW=0;
   RS=1;
   LCD=dat;
   EN=1;
   EN=1;
   EN=0;
   EA=ea;
   }


=======================================================
【54楼】heyunqingfeng 的回复,并没有错,我对他的回复没有任何讽刺意思,是称赞。原因是:我也觉得很繁琐,没有精简,就以void lcdPutPix(uchar x, uchar y,uchar flag) 这个函数来说,那些开中断,关中断等,其实可以去掉的,没有必要的。还有画边框函数void rectangle(void) 其实我有简洁的方法(Bresenham算法),但是没有用,原因是我觉得我那样画边框速度慢一些。

qq20707 发表于 2010-9-12 11:59:07

mark下

_do_while 发表于 2011-6-30 14:48:24

很好很强大

Super_C 发表于 2011-7-1 19:51:56

MARK.

513696765 发表于 2011-7-4 15:55:55

强势留名

power_check 发表于 2011-7-4 16:40:58

mark

asdxb147258 发表于 2011-7-4 19:11:53

回复【楼主位】lzf713
-----------------------------------------------------------------------

谢谢

bingshuihuo888 发表于 2011-7-4 19:53:35

学习。。

zdajun1988 发表于 2011-7-4 20:33:03

等有时间了也要实现自己的这个愿望,弄个玩玩.

xiaohaizi 发表于 2011-7-4 20:43:22

还是很强大啊!好好研究

chuchuang 发表于 2011-7-5 00:10:18

mark 下来看看

JamesErik 发表于 2011-7-5 00:26:22

电脑没电前……

mark……

zhiyinyouni 发表于 2011-7-5 22:23:39

确实很强大啊,利用c语言编程控制,结合AT89X51单片机,很轻松的做出了一个小游戏,要好好学习!

lannathan2008 发表于 2011-7-6 00:54:01

好东西,MARK!!!

dongfanghuazi 发表于 2011-7-6 09:04:10

要了标记一下

jyjmaster 发表于 2011-7-6 09:55:45

mark===楼主很强大。。。

joing2000 发表于 2011-7-6 10:49:04

mark

mitchell 发表于 2011-7-6 13:01:30

漂亮

homa 发表于 2011-7-6 13:57:46

mark

df890170 发表于 2011-7-9 13:36:33

能不能使用16*2lcd做啊

batou 发表于 2011-8-6 09:56:44

mark下先,不知到事物上会怎样

zhouping1987 发表于 2011-8-30 20:36:48

学习一下!!!

daruikl 发表于 2011-8-31 08:37:57

正想用12864玩显示
留下,学习

wzz951 发表于 2011-8-31 13:31:15

不错!!!转啦!!!

grc0709 发表于 2011-9-1 10:24:47

mark

guyan1987 发表于 2011-9-1 10:54:37

强大!

guyan1987 发表于 2011-9-1 11:04:52

那个 图形是怎么弄得? 就是掉下来的黑色方块

wwcxia 发表于 2011-9-1 11:55:37

强人,努力看齐!!!

90soso 发表于 2011-9-1 13:36:22

搞12864不玩这个,不玩贪吃蛇,不玩播动画,不玩推箱子,遗憾~

ccjoy 发表于 2011-9-1 13:44:27

真是人才啊!

fjfhss135790 发表于 2011-9-2 09:15:50

留下日后以定看

airfex 发表于 2012-4-2 19:41:59

楼主确实很有实力

yezhiyan1121 发表于 2012-4-14 17:44:22

牛!      

onlyfirehorse 发表于 2012-4-14 17:50:13

好贴,顶一下

mlt911213 发表于 2012-4-18 18:41:21

真的不错,要学习下

wpnx 发表于 2012-4-18 21:27:59

强啊,就是没有注释。

huang331857001 发表于 2012-4-20 00:27:53

厉害啊!!

yyc11235813 发表于 2013-3-4 17:04:14

学习··································{:smile:}

plhone 发表于 2013-3-4 19:48:14

不错啊                     

智波景严 发表于 2013-11-22 16:35:02

{:lol:}{:lol:}{:lol:}mark,too.

afcy003 发表于 2013-11-22 23:37:35

很有趣的样子~~

007412 发表于 2014-1-1 20:24:29

支持楼主,大爱楼主

ld476461889 发表于 2014-1-2 22:08:40

学习一下谢谢分享

闲鱼翻身 发表于 2014-1-2 23:48:16

感谢分享,不错~!

hyghyg1234 发表于 2014-2-13 15:54:56

很好,支持分享。
页: [1]
查看完整版本: 俄罗斯方块(LCD12864显示+仿真)