1. Circuit Design
This circuit consists of AT89C51 minimum system, 12864 display module and independent buttons.
It can realize games similar to Tetris.
2. Operation Effect
3. Partial Code
/*Want more projects private wo!!!*/
#include #include "pic.c" #include #define LCD_DATA P2 #define button_delay 150 //Button delay #define button_acceleration 65 //Button acceleration threshold #define GAME_LOCATION 30 sbit button_a = P3^4; //deformation sbit button_b = P3^5; //Start sbit up = P3^2; //Pause start sbit down = P3^0; sbit left = P3^1; sbit right = P3^3; sbit speaker=P3^6; sbit LCD_RS=P1^0; sbit LCD_RW=P1^1; sbit LCD_E=P1^2; sbit LCD_CS2=P1^4; //right screen selection (left and right screens are sometimes opposite) sbit LCD_CS1=P1^3; //Left screen selection sbit LCD_RST=P3^7; unsigned int up_reg=button_delay; //button up accumulator unsigned int down_reg=button_delay; //button down accumulator unsigned int left_reg=button_delay; //button left accumulator unsigned int right_reg=button_delay; //button right accumulator unsigned int button_a_reg=button_delay; //button_a accumulator unsigned int button_b_reg=button_delay; //button_b accumulator unsigned int right_acceleration=0; //button right acceleration register unsigned int left_acceleration=0; //Key left acceleration register unsigned int idata Box_Ram[19]; //define game dot cache 10*16 unsigned char box_down_reg; //Define the box down accumulation register unsigned char time0_reg; //define timer 0 accumulation register unsigned char next_mode; //Define the type of the next block unsigned char next_shape; //define the shape of the next block unsigned int destroy_row_num=0; //Define the number of rows to be destroyed unsigned char speed_num=0; //Define the game speed level unsigned char level_num; //Define the game difficulty level bit game_over_flag; //Game over flag position 0 means the game is not over bit pause_game_flag; //Game pause flag position 0 means the game is not paused struct { unsigned char mode; //type unsigned char shape; // shape unsigned char x; //x coordinate unsigned char y; //y coordinate unsigned int box; //define the block cache }s_box; //Define the box structure //LCD detects busy status function void LCD_check_busy() { unsigned char temp; LCD_RS=0; LCD_RW=1; do { LCD_DATA=0xff; LCD_E=1; temp=LCD_DATA; LCD_E=0; }while((temp&0x80)==0x80); } //Write instruction code (cs is 0 to select the left screen, cs is 1 to select the right screen) void LCD_W_code(unsigned char tpcode,bit cs) { LCD_RS=0; LCD_RW=0; LCD_CS2=~cs; LCD_CS1=cs; LCD_DATA=tpcode; LCD_E=1; _nop_(); LCD_E=0; } //Write display data (cs is 0 to select the left screen, cs is 1 to select the right screen) void LCD_W_data(unsigned char tpdata,bit cs) { LCD_check_busy(); LCD_RS=1; LCD_RW=0; LCD_CS2=~cs; LCD_CS1=cs; LCD_DATA=tpdata; LCD_E=1; _nop_(); LCD_E=0; } //LCD initialization function void LCD_initialize() { LCD_RST=0; _nop_(); _nop_(); LCD_RST=1; LCD_W_code(0x3f,0); //Open display settings LCD_W_code(0xc0,0); //Set the display start line to the first line LCD_W_code(0xb8,0); //page address setting LCD_W_code(0x40,0); //Set the column address to 0 LCD_W_code(0x3f,1); LCD_W_code(0xc0,1); LCD_W_code(0xb8,1); LCD_W_code(0x40,1); } //LCD clear screen function void LCD_clear() { unsigned char i,j; for(j=0;j<8;j++) { LCD_W_code(0xb8+j,0); LCD_W_code(0x40,0); LCD_W_code(0xb8+j,1); LCD_W_code(0x40,1); for(i=0;i<64;i++) { LCD_W_data(0x00,0); LCD_W_data(0x00,1); } } } //LCD display string function (word represents the string to be displayed, //length indicates the width of the string to be displayed, //x represents the line number of the first character, //y represents the column number of the first character) void LCD_display_word(unsigned char word[], unsigned int length, unsigned char x, unsigned char y) { unsigned char i; for(i=0;i LCD_W_code(0xb8+x,0); LCD_W_code(0xb8+x,1); if(y+i<64) { LCD_W_code(0x40+y+i,0); LCD_W_data(word[i],0); } else { LCD_W_code(y+i,1); LCD_W_data(word[i],1); } } } //LCD full screen drawing function void LCD_full_draw(unsigned char word[]) { unsigned char i,j; for(i=0;i<8;i++) { LCD_W_code(0xb8+i,0); LCD_W_code(0x40,0); for(j=0;j<64;j++) { LCD_W_data(word[i*128+j],0); } LCD_W_code(0xb8+i,1); LCD_W_code(0x40,1); for(j=0;j<64;j++) { LCD_W_data(word[i*128+64+j],1); } } } //LCD displays a byte function ( //x represents the x coordinate, //y represents the y coordinate, //tpdata indicates the data to be displayed) void LCD_display_byte(unsigned char x, unsigned char y, unsigned char tpdata) { if(x<64) { LCD_W_code(0xb8+y,0); LCD_W_code(0x40+x,0); LCD_W_data(tpdata,0); } else { LCD_W_code(0xb8+y,1); LCD_W_code(x,1); LCD_W_data(tpdata,1); } } void LCD_draw(unsigned char word[]) { unsigned char i,j; for(i=0;i<8;i++) { LCD_W_code(0xb8+i,1); LCD_W_code(0x40+20,1); for(j=0;j<44;j++) { LCD_W_data(word[i*44+j],1); } } } //Basic interface display function void display_basic() { unsigned char i; for(i=0;i<8;i++) { LCD_display_byte(GAME_LOCATION,i,0xff); LCD_display_byte(GAME_LOCATION+41,i,0xff); } } // Refresh the game area function void refurbish_display() { unsigned char i,j,tpdata; for(i=0;i<8;i++) { for(j=0;j<10;j++) { tpdata=0x00; if( (Box_Ram[2*i]>>(12-j))&0x0001==1 ) { tpdata=0x0f; } if( (Box_Ram[2*i+1]>>(12-j))&0x0001==1 ) { tpdata|=0xf0; } LCD_display_byte(GAME_LOCATION+1+j*4,i,tpdata); LCD_display_byte(GAME_LOCATION+2+j*4,i,0xbb&tpdata); LCD_display_byte(GAME_LOCATION+3+j*4,i,0xdd&tpdata); LCD_display_byte(GAME_LOCATION+4+j*4,i,tpdata); } } }
Previous article:51 single-chip multi-channel temperature measurement alarm system (AT89C51, multiple DS18B20, LCD1602)
Next article:51 single chip game (pushing box)
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- Infineon Technologies Launches ModusToolbox™ Motor Kit to Simplify Motor Control Development
- Infineon Technologies Launches ModusToolbox™ Motor Kit to Simplify Motor Control Development
- STMicroelectronics IO-Link Actuator Board Brings Turnkey Reference Design to Industrial Monitoring and Equipment Manufacturers
- Melexis uses coreless technology to reduce the size of current sensing devices
- Melexis uses coreless technology to reduce the size of current sensing devices
- Vicor high-performance power modules enable the development of low-altitude avionics and EVTOL
- Chuangshi Technology's first appearance at electronica 2024: accelerating the overseas expansion of domestic distributors
- Chuangshi Technology's first appearance at electronica 2024: accelerating the overseas expansion of domestic distributors
- "Cross-chip" quantum entanglement helps build more powerful quantum computing capabilities
- Ultrasound patch can continuously and noninvasively monitor blood pressure
- Several circuits used by telephone for remote monitoring
- Allegro reports an error when drilling files
- Design of Intelligent Vehicle Safety System Based on DSP
- Digital clock design based on FPGA (video source code)
- The relationship between wavelength and frequency and conversion tools
- RISC-V Processor Design Course Series——CPU Basics
- Qorvo's 802.11AX 5 GHZ FEM Dramatically Improves Wi-Fi Performance
- Unstable waveform
- Industrial Equipment Edge Intelligence Solutions
- Characteristics and Applications of Wireless Data Transceiver Chip TR3001