📄 v01.c
字号:
//demo board system
//designed 2002/12/25
//modify ---------
//version V1.00
#include <reg51.h>
typedef unsigned char byte;
typedef unsigned int word;
struct position{
byte x;
byte y;
};
#define point (( struct position xdata *)(0x1200))
#define xram ( byte xdata *)(0x0000)
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 latch = 0x97; //p1.7
bit game_on;
byte code chinese[500] ={ //lay model catch mod resceive
/*-- 文字: 枫 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x08,0xC8,0xFF,0x28,0xC8,0x00,0xFE,0x22,0x42,0x82,0x72,0x02,0xFE,0x00,0x00,0x00,
0x02,0x01,0xFF,0x00,0x20,0x18,0x07,0x04,0x02,0x01,0x02,0x04,0x0F,0x30,0x7C,0x00,
/*-- 文字: 叶 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xFC,0x04,0x04,0x04,0xFC,0x40,0x40,0x40,0x40,0xFF,0x40,0x40,0x40,0x40,0x40,0x00,
0x0F,0x02,0x02,0x02,0x07,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: 电 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0xF8,0x00,0x00,0x00,
0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x3F,0x44,0x44,0x44,0x44,0x4F,0x40,0x70,0x00,
/*-- 文字: 子 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x02,0x02,0x02,0x02,0x02,0xE2,0x12,0x0A,0x06,0x02,0x00,0x80,0x00,0x00,
0x01,0x01,0x01,0x01,0x01,0x41,0x81,0x7F,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,
};
//---------------------------reset the lcd controller chip---------------------
void reset_lcd(void){
word i;
RST=0;
for(i=0;i<1000;i++)
;
RST=1;
}
//-------------------------write a command to left part of lcd ---------------
void write_l_com(byte com){
byte i;
LCD2=0;
LCD1=1;
DI=0;
RW=1;
RW=1;
do{
P2=0xff;
E=1;
i=P2;
E=0;
}
while(i&0x80);
RW=0;
DI=0;
P2=com;
E=1;
E=1;
E=0;
}
//----------------------write a data to left part of lcd-----------------------
void write_l_dat(byte dat){
byte i=0x80;
LCD2=0;
LCD1=1;
DI=0;
RW=1;
RW=1;
do{
P2=0xff;
E=1;
i=P2;
E=0;
}
while((i&0x80));
RW=0;
DI=1;
P2=dat;
E=1;
E=1;
E=0;
}
//--------------------------write a command to right part of lcd --------------
void write_r_com(byte com){
byte i;
LCD2=1;
LCD1=0;
DI=0;
RW=1;
RW=1;
do{
P2=0xff;
E=1;
i=P2;
E=0;
}
while(i&0x80);
RW=0;
DI=0;
P2=com;
E=1;
E=1;
E=0;
}
//------------------------write a data to right part of lcd--------------------
void write_r_dat(byte dat){
byte i=0x80;
LCD2=1;
LCD1=0;
DI=0;
RW=1;
RW=1;
do{
P2=0xff;
E=1;
i=P2;
E=0;
}
while((i&0x80));
RW=0;
DI=1;
P2=dat;
E=1;
E=1;
E=0;
}
//----------------------initialize lcd-----------------------------------------
void init_lcd(){
byte i,j,page;
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);
}
}
}
//---------------------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 pageof 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 pageof lcd display buffer memory
write_r_com(40); //set the start pixel
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 square at the lcd-----------------------------
void write_square(byte x0,y0,x1,y1,d){
byte i;
for(i=0;i<(x1-x0);i++){
write_point((x0+i),y0);
write_point((x0+i+1),y1);
}
for(i=0;i<(y1-y0);i++){
write_point(x0,(y0+i+1));
write_point(x1,(y0+i));
}
if(d){
for(i=0;i<(x1-x0);i++){
write_point((x0+i),y0+1);
write_point((x0+i+1),y1-1);
}
for(i=0;i<(y1-y0);i++){
write_point(x0+1,(y0+i+1));
write_point(x1-1,(y0+i));
}
}
}
//--------------------put a char at lcd --------------------------------------
void put_char(byte x,y,att,chara){ //att: 0-> 16x16; 1->8x16; 2->24x24
byte i;
word scope;
switch (att){
case 0:
for(i=0;i<16;i++){
*(xram+(y/8)*128+x+i)=chinese[chara*32+i];
scope=&(xram+(y/8)*128+x+i);
*(xram+(y/8)*128+x+128+i)=chinese[chara*32+16+i];
scope=&(xram+(y/8)*128+x+128+i);
}
break;
case 1:
for(i=0;i<16;i++){
*(xram+(y/8)*128+x+i)=chinese[chara*32+i];
scope=&(xram+(y/8)*128+x+i);
*(xram+(y/8)*128+x+128+i)=chinese[chara*32+16+i];
scope=&(xram+(y/8)*128+x+128+i);
}
break;
case 2:
for(i=0;i<8;i++){
*(xram+(y/8)*128+x)=chinese[chara*32+i];
*(xram+(y/8)*128+x)=chinese[chara*32+i];
}
break;
default:break;
}
}
//----------------------the game model-----------------------------------------
game(){
byte i;
game_on=1;
while(game_on){
point->x=60;
point->y=38;
(point+1)->x=65;
(point+1)->y=38;
}
}
//-----------------------------------------------------------------------------
main()
{ word i;
power=0;
lcd_power=0;
// init_lcd();
for(i=0;i<1024;i++){
*(xram+i)=0x00;
}
while(1){
write_square(00,16,127,63,1);
for(i=0;i<4;i++)
put_char((33+16*i),21,0,'b');
game();
//------------------------------------------------
display();
while(1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -