⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 v100.bak

📁 51下的 贪吃蛇 程序 用128864的LCD keil的开发环境
💻 BAK
📖 第 1 页 / 共 2 页
字号:
//demo board system
//designed 2002/12/25
//modify   ---------
//version	V1.00	
#include <reg51.h>
//#include <stdlib.h>
#include <LCD.h>

typedef unsigned char byte;
typedef unsigned int word;
#define XTALL           11.0592					//crystal frequency
#define DLY_10MS        (word)(10000*XTALL/12)  // 10ms counter        
#define DLY_400US       (word)(400*XTALL/12)    // 400us counter     
#define speed			30
#define  LCD_port    *(byte xdata*)(0x0000) 
#define   xram       ( byte xdata *)(0x8000)
#define  jk	P2 = 0;P2= P2+1;
#define  jk1	P2=P2+1;P2=P2 +1;

struct position{
	byte x;
	byte y;
	};  

sbit      power 	  =		0x94;	//p1.4
sbit	  lcd_power   =		0x95;   //p1.5
sbit	  DI		  =     0x92;   //p1.2
sbit	  RW		  =	    0x91;   //p1.1
sbit      E			  =		0x90;   //p1.0
sbit	  LCD1		  =		0x93;   //p1.3
sbit	  LCD2        =	    0x96;   //p1.6
//sbit	  RST		  =     0xB0;   //p3.0
//sbit	  RAM		  =		0xB1;	//P3.1
//sbit	  UP		  =		0xB5;	//P3.2
//sbit	  DOWN		  =		0xB4;	//P3.3
//sbit	  LEFT		  =		0xB3;	//P3.4
//sbit	  RIGHT		  =		0xB2;	//p3.5
sbit      C573        =     0x97;   //p1.7

bit		game_on,move_flag,key_exit;
struct  position xdata point[500] _at_ 0x9200;
byte 	sp_end,sp_start,spoint,orient,REG573;
static idata byte last_key;
word	key_count;
//#define k xram[2130];
byte code key_code[16]={0xff,0xe7,0xf3,0xb7,0xcf,0xff,};//1:up 2:left 3:right 4:down
byte code chinese[350] ={    //lay model catch mod  receive
/*--  文字:  贪  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x20,0x20,0x10,0x90,0xA8,0xA4,0xAA,0xB1,0xA2,0xE4,0xA8,0x88,0x10,0x30,0x10,0x00,
0x00,0x00,0x80,0x9F,0x40,0x20,0x10,0x0E,0x10,0x20,0x60,0xDF,0x00,0x00,0x00,0x00,

/*--  文字:  食  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x20,0x20,0x10,0xF0,0xA8,0xA4,0xAB,0xB2,0xA4,0xA8,0xF0,0x10,0x20,0x20,0x00,0x00,
0x00,0x00,0x00,0xFF,0x42,0x22,0x06,0x0A,0x0A,0x12,0x2B,0x64,0x00,0x00,0x00,0x00,

/*--  文字:  蛇  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0xF0,0x10,0xFF,0x10,0xF0,0x20,0x18,0xE8,0x09,0x0E,0x0A,0xA8,0x18,0x08,0x00,
0x20,0x23,0x21,0x1F,0x11,0x3B,0x10,0x00,0x3F,0x42,0x41,0x41,0x40,0x38,0x00,0x00,

/*--  文字:  V  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,0x00,0x00,

/*--  文字:  1  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,

/*--  文字:  0  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

/*--  文字:  游  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x10,0x61,0x86,0x60,0x08,0xF9,0x4E,0xC8,0x28,0x10,0x2F,0xA8,0x68,0x28,0x08,0x00,
0x04,0xFC,0x03,0x40,0x38,0x47,0x80,0x7F,0x00,0x42,0x82,0x7F,0x02,0x02,0x02,0x00,

/*--  文字:  戏  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x14,0x24,0x44,0xC4,0x34,0x0C,0x20,0x20,0xFF,0x20,0x22,0x2C,0xA0,0x20,0x00,
0x00,0x10,0x08,0x06,0x01,0x23,0x2C,0x10,0x10,0x08,0x07,0x1A,0x21,0x40,0xF0,0x00,

/*--  文字:  结  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x20,0x30,0xAC,0x63,0x10,0x00,0x08,0x48,0x48,0x48,0x7F,0x48,0x48,0x48,0x08,0x00,
0x22,0x23,0x22,0x12,0x12,0x00,0x00,0x7E,0x22,0x22,0x22,0x22,0x22,0x7E,0x00,0x00,

/*--  文字:  束  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x04,0x04,0xF4,0x94,0x94,0x94,0x94,0xFF,0x94,0x94,0x94,0x94,0xF4,0x04,0x04,0x00,
0x20,0x20,0x11,0x10,0x08,0x06,0x01,0xFF,0x02,0x04,0x08,0x08,0x11,0x30,0x10,0x00,
};  
//------------------------------10ms timer counter-----------------------------
void TIM0_isr() interrupt 1 using 1 {
	static idata word timercount;
   TR0=0;
   TL0+=-DLY_10MS&0xff;
   TH0+=-DLY_10MS>>8;
   TR0=1;
   if(timercount++ >speed){
   		timercount=0;
		move_flag=1;
   }
   if(key_count++>=10){ //press key 30ms force exit
   		key_count=0;
		key_exit=1;
   }
}
void delay(word i){
	while(i--);
}
//-----------------------------key board service program----------------------
byte key(void){
//	byte i;
/*	UP=1;
	if(!UP){
		delay(100);
		if(!UP)i=1;
		else i=0xff;
		UP=1;
		return i;
	}
	
	
	DOWN=1;
   if(!DOWN){
		delay(100);
		if(!DOWN)i=4;
		else i=0xff;
		DOWN=1;
		return i;
	}
	
	
	LEFT=1;
    if(!LEFT){
		delay(100);
		if(!LEFT)i=2;
		else i=0xff;
		LEFT=1;
		return i;
	}


	RIGHT=1;
   if(!RIGHT){
		delay(100);
		if(!RIGHT)i=3;
		else i=0xff;
		RIGHT=1;
		return i;
	}
}
/*
byte key(void){
	byte i,x,y;
	LCD1=0;
	LCD2=0;
	P2=0x55;
	if(P2==0x55){
		return 0xff;
	}
	else{
		delay(500);
		P2=0x55;
		x=P2;
		P2=0xaa;
		y=P2;
		y=y|x;
		key_count=0;
		key_exit=0;
		while(P2!=0x55){
		/*	if(key_exit){
				break;
			}*/
/*			P2=0x55;
		}
	  for(i=0;i<16;i++){
	  	if(y==key_code[i]){
			break;
		}
	 }
	if(i>=16)return 0xff;
	return i;
	}*/
	return 0xff;
}
//---------------------------reset the lcd controller chip--------------------- 
void reset_lcd(void){
	word i;
	C573 = 1;
	P2 = CS_16550;
	REG573 = CS_16550;	
	C573 = 0;

	MCR = 0X06;
    MCR = 00;	
	for(i=0;i<1000;i++);
	}
 //-------------------------write a command to left part of lcd ---------------
void write_l_com(byte com){
	byte ch;
	LCD2=0;
	LCD1=1;
	ch  = REG573;
	C573  =1;
	REG573 = CS_LCD; 
	P2  = CS_LCD;
	C573  = 0;
	
	RW=0;
	DI=0;
	LCD_port = com;
	E=1;
	E=1;
	E=0;
	C573 = 1;
	P2 = ch;
	REG573 = ch;
	C573 = 0;
	C573 = 0;
	}
//----------------------write a data to left part of lcd-----------------------
void write_l_dat(byte dat){
	byte ch;
	LCD2=0;
	LCD1=1;
	ch  = REG573;
	C573  =1;
	REG573 = CS_LCD; 
	P2  = CS_LCD;
	C573  = 0;
	RW=0;
	DI=1;
	LCD_port = dat;
	E=1;
	E=1;
	E=0;
	C573 = 1;
	P2 = ch;
	REG573 = ch;
	C573 = 0;
	C573 = 0;
	}
//--------------------------write a command to right part of lcd --------------
void write_r_com(byte com){
	byte ch;
	LCD2=1;
	LCD1=0;
	ch  = REG573;
	C573  =1;
	REG573 = CS_LCD; 
	P2  = CS_LCD;
	C573  = 0;
	RW=0;
	DI=0;
	LCD_port = com;
	E=1;
	E=1;
	E=0;
	C573 = 1;
	P2 = ch;
	REG573 = ch;
	C573 = 0;
	C573 = 0;
	}
//------------------------write a data to right part of lcd--------------------
void write_r_dat(byte dat){
	byte ch;
	LCD2=1;
	LCD1=0;
	ch  = REG573;
	C573  =1;
	REG573 = CS_LCD; 
	P2  = CS_LCD;
	C573  = 0;
	RW=0;
	DI=1;
	LCD_port = dat;
	E=1;
	E=1;
	E=0;
	C573 = 1;
	P2 = ch;
	REG573 = ch;
	C573 = 0;
	C573 = 0;
	}
//----------------------initialize lcd-----------------------------------------
 void init_lcd(){
 	byte i,j,page;
	word offset;
 	reset_lcd();
	write_l_com(0x3f);
	write_l_com(0xc0);
	write_r_com(0x3f);
	write_r_com(0xc0);
	page=0;
	for(i=0;i<8;i++){
		page=i|0xb8;
		write_l_com(page);
		write_l_com(0x40);
		write_r_com(page);
		write_r_com(0x40);
		for(j=0;j<64;j++){
			write_l_dat(0x00);
			write_r_dat(0x00);

		}
	}
	C573 = 1;
	P2 = CS_256;
	C573 = 0;
 	for(offset=0;offset<1024;offset++){
		*(xram+offset)=0x00;
	}
 }
 //---------------------display the data from the xdata buffer-----------------
 void display(){  //the display buffer is from 0x0000 to 0x0400 total 1024 byte
 	byte i,j,page=0;
	for(i=0;i<8;i++){
		page=i|0xb8;
		write_l_com(page);			//write the page of lcd display buffer memory
		write_l_com(40);			//set the start pixel
		for(j=0;j<64;j++){
			write_l_dat(*(xram+(128*i)+j));
		}
	}  //write the data to left part of lcd

	for(i=0;i<8;i++){
		page=i|0xb8;
		write_r_com(page);			//write the page of lcd display buffer memory
		write_r_com(40);			//set the start pixel
 		REG573 = CS_256;
		C573 = 1;
		P2 = CS_256;
		C573 = 0;
		for(j=0;j<64;j++){
			write_r_dat(*(xram+(128*i)+64+j));
		}
	}  //write the data to right part of lcd
}
//-------------------------write a point at the lcd----------------------------
byte write_point(byte x,byte y){
	byte  idata temp,buffer;
	if(x>128)return 0x00;
	if(y>64) return 0x01;
	temp=*(xram+(y/8)*128+x);
	buffer=0x01;
	buffer<<=(y%8);
	temp=temp|buffer;
	*(xram+(y/8)*128+x)=temp;	
	}
//---------------------------write a big point to lcd--------------------------
void write_big_point(byte x,byte y){
	byte x_t,y_t;
	x_t=x*2;
	y_t=y*2+17;
	write_point(x_t,y_t);
	write_point(x_t+1,y_t);
	write_point(x_t,y_t+1);
	write_point(x_t+1,y_t+1);
}
//-------------------------clear a point at the lcd----------------------------
byte clear_point(byte x,byte y){
	byte  idata temp,buffer;
	if(x>128)return 0x00;
	if(y>64) return 0x01;
	temp=*(xram+(y/8)*128+x);
	buffer=0x01;
	buffer<<=(y%8);
	buffer=~buffer;
	temp=temp&buffer;
	*(xram+(y/8)*128+x)=temp;	
	}
//----------------------clear a big point at the lcd---------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -