📄 v100.c
字号:
//Demo board system
//Designed 2002/12/25
//Modify ----------
//Software Version V1.0
//Hardware Version V1.0
#include <stdlib.h>
#include <LCD.h>
#include <reg51.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)
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
extern bit key_exit;
extern game(void);
extern byte REG573;
extern bit move_flag;
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
//------------------------------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;
}
}
//-----------------------------key board service program----------------------
byte key(void)
{
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
}
//-----------------------CPU initialization-----------------------------------
void init(void) {
TMOD=0x21 ; // (T1 MODE 2_send_flagME,T0 MODE 1_send_flagME)
TCON=0x51 ; //0101 0000 (TR1=1 , TR0=1
SCON=0x50 ; //0101 0000 (MODE 1 ;RECEIVE ENABLE)
IP=0x10 ; //0001 0000 (S-PORT HIGH interrupt)
IE=0x12 ; //0001 0010 (S_PORT AND TIME0 ENABLE INT)
TL1=TH1=0xfd; //9600bps
PCON=0x00; //SMOD=0
IE = 0x92;
TR1=0;
// RAM=0; //static ram be select
EA=1; // enable all interrupt
}
//-----------------------------------------------------------------------------
void main(){
word i;
power=0;
lcd_power=0;
init();
init_lcd();
while(1){
REG573 = CS_256;
C573 = 1;
P2 = CS_256;
C573 = 0;
game();
//------------------------------------------------
display();
while(1){
i=rand();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -