Based on STC-B experimental board, design a small game "tank war" (primary school homework)

Keywords: pygame

HUNAN UNIVERSITY

Innovative design
(large operation) report

        Course Name:       Basic training of electronic system design and innovation 
    Name of experiment project:         Tank war game         
    Professional class:         Communication engineering 1901        
    lastname        Name:         Wu Hua                 
    learn        number:         two hundred and one billion nine hundred and eight million thirty thousand one hundred and twenty-one         
    Instructor:         Luo Jian                 

Topic selection time: September 8, 2021
Project design time: September 8, 2021 to September 14, 2021
Report completion time: September 15, 2021

catalogue

1 design overview 3
1.1 design purpose 3
1.2 design task 3
1.3 design requirements 3
2 overall scheme design 4
3 experimental process and test 7
4 design summary and experience 9
4.1 design summary 9
4.1 design experience 10

Title: tank war game
------BSP based completion
1. Project overview
When I was a child, a small game machine called "little overlord" was popular. There was a game called tank war, which impressed me. I always wanted to revisit this little game. The STC-B learning board is used in this experimental project. I found that the above eight digit nixie tube seems to be able to complete my idea, that is, using the eight digit nixie tube as the display screen to complete the production of this tank war game. The design expectation is to set up two tanks on the offensive side and the defensive side, and the eight digit nixie tube can provide three ballistics as the launch track of shells. Both tanks should be able to move up and down to dodge.
In addition, since the two sides of attack and defense are set, in order to show the difference and make full use of the display space, my idea is to set one side to move up and down and back and forth, and the firing is controlled manually for the attacking side; The other side can only move up and down, but can complete automatic firing. This is the defensive side.
1.1 design purpose
While making practical use of the learning content in primary school, we completed the review of childhood memory games, hoping to design a game similar to the tank war on the small game console in that year, introduce sound effects, increase movement and dodge functions, and also record real-time scores and pause games.
1.2 design tasks
Based on the DEMO file issued in the course group, that is, based on BSP, under the original code framework, delete some functions and modules irrelevant to my experimental project, and rewrite the original functions as necessary according to my needs, such as the decoding table decode of eight digit nixie tube_ Table [], such as dealwithDisp() function for display, I need to call all keys including navigation keys, so I need to write the functions of the possible keys and delete the conflicting parts.
1.3 design requirements
1) Since the trajectory of the projectile must be visible and fired forward at a fixed speed, it needs to be recalled in time, and there can be three ballistic shells on the field at the same time, so it is necessary to classify each type of projectile;
2) Two shells on the same trajectory will detonate when they meet, which should also be discussed according to the situation;
3) The shells on different trajectories do not affect each other, and they can still move in the original direction after meeting;
4) The defensive tank Tank1 needs to complete automatic firing
5) The attacking tank Tank2 can still move forward and backward after firing
6) Tanks on both sides can "dodge" enemy shells coming from up and down, and need to show the instantaneous state of shells passing by tanks
7) Score can be scored when hitting the opponent's tank. Temporary scoring with LED diode can be viewed in real time during the game. In addition, the pause function should be set. Press a key to pause the game, and the scores of both sides can be expressed in Arabic numerals on the nixie tube. In addition, a key should be set to return to the game
8) Game sound design, shells and shells will detonate when they meet, and shells will detonate when they hit the opponent's tank. In addition, the party who gets 3 points first is set as the winner, and exclusive music will be played after the game
2. Overall scheme design
The first is about the navigation key, which is used to control the front and back up and down movement of the attacking tank Tank2, in which the enter key of the navigation key is used for the firing action of Tank2;

I set the Key3 button here to move the defensive tank Tank1 up and down, and fire a shell forward while moving;

Key1 is set to view the current score. Pressing key1 can interrupt the current game and view the score. key2 returns to the game and initializes the status of both sides, but does not change the scores of both sides;

As for the decoding table of nixie tube, I added it according to my needs, including my tank state, shell state, superposition state of shell and tank, etc;

Because my shells are written in categories and each shell does not affect each other, in theory, there can be six shells at the same time, but in fact, because the length of the nixie tube is too short, each shell needs to occupy a grid, and there must be a gap between the shells, so there can only be four shells on the display screen at the same time during operation;
The overall idea must be based on the 1S time callback function. The automatic advance, state change and ballistic difference of the shell should be discussed according to the situation. At the same time, after the shell hits the opponent's tank, the party firing the shell will get a score, which is displayed on the LED diode in binary mode. The first four bits are the score of Tank1 and the last four bits are the score of Tank2, Press key1 to interrupt the game and view the real-time score on the nixie tube;

The "pass by" status of the tank dodging shells should also be added. Similarly, based on the existing 1S time callback function, the 2S refresh callback is used to display the superposition status;

With the addition of sound effect, I chose the short sound effect with frequency of 1350 and duration of 100ms as the sound of shell detonation. In addition, I also called a piece of music "old memory" written by myself in the first half of the semester as the background music for winning;

3. Experimental process and test
1) Shells meet and detonate
Because I use a global array, I will make a judgment during the process of projectile travel. If the next value in the forward direction is the same as the current value (i.e. the projectile type is the same), both shells will be detonated, set to zero and displayed as empty
2) Different ballistic shells meet
Judge when the projectile is moving. If the next value in the forward direction is different from the current value (i.e. different projectile types or front clearance)
The two values are exchanged, which completes the advance of the shell
3) Multiple shells fired from the same tank
According to my design idea, two shells fired by the same tank are not allowed on a trajectory at the same time. This design is because the display space is really limited. If the same type of shell is fired again before the current shell is detonated, the previous shell will stay in place. Of course, this feature can be used for "defense" during the game. The shell staying on the field will become a "barrier", and no matter which side's shell hits, it will detonate.
Although it is not possible to launch multiple shells in the same trajectory, it is possible to "change a position with one shot" and hit three shells in a row. It will be difficult for the other party to deal with it and it will be difficult to block or dodge all of them.
4) Dodge
The tank itself is filled with two vertical cells of the nixie tube, such as a horizontal capital letter T, but part of the body can be "hidden" by up and down displacement, which means that the enemy shells flying up and down can be dodged (that is, the shells flying in the middle can only be intercepted by firing shells).
I added four dodge states to the nixie tube decoding table, and sent a judgment value when it was judged that the Dodge phenomenon occurred, which was used to display the transient state of "passing by" between tank and shell in a nixie tube. At this time, a "2S time callback function" was needed,
Here is to use the original 1S time callback function to + 1 a variable to judge whether it can be divided by 2.
5) Scoring
Set two global variables lc and rc to record the scores of both sides respectively. Due to the use of LED display, it is divided into the first four digits and the last four digits,
Each time Tank1 hits lc, it will add 16. Each time Tank2 hits lc, it will add 1. Add lc and rc as LedPrint(lc+rc) to display the scores of both sides at the same time.
When you press key1 to view the score, call a function to display the actual score represented by lc and rc on the nixie tube.
6) Sound effect
The shelling sound effect is a short sound with a frequency of 1350 and a duration of 100ms. SetBeep(1350,10) is directly used;
After one side wins, play the background music old memory, which is a piece of music written by myself in the first half of the semester and rewritten into the song.c file of the original DEMO, so I can call it directly.
7) On the addition of "flashback" of Tank2
During the actual game, I found that the response of the keys was often not timely enough, and often Tank2 was hit before it had time to retreat, so I decided to set the right navigation key as the "flashback" key, which can be understood as a limit dodge. Press once to reach the rightmost side of the nixie tube, that is, the d7 position, to ensure the safety of the attacking Tank2 to the greatest extent, Increased the playability of the game.
4. Design summary and experience
4.1 design summary
Personally, I am optimistic that I have completed the expected goal of the experiment. This small game of tank war is completely playable. The encounter and detonation of shells, the impact effect of shells and the avoidance of tanks from shells are the original rules of the game, which are actually the most basic rules. In addition, The concept of offensive side and defensive side I set is flexible due to the length of nixie tube, so that one side can not move left and right, which can reduce the waste of space and let the offensive Tank2 have more space to play. Therefore, I add the skill of "automatic firing" to the defensive Tank1 to make the game relatively fair.
However, because Tank1's "automatic firing" can achieve extreme defense, and it is found that the navigation key is not sensitive enough after experience, the attacker Tank2 is often hit because it does not retreat in time (that is, press the navigation Right key continuously) during the game. Therefore, I came up with the idea of adding a "flash back" key to Tank2. I just need to press the Right key once to return to the initial rightmost point, The survivability of tank 2 is greatly improved.
In fact, the pause function was not set at the beginning. I used key1 to check the accurate score (although the LED is also displayed in real time, it is binary after all), but the game is interrupted when looking at the score. As soon as I want to make key2 to restore the initial state, In this way, when a large number of enemy shells cannot intercept or dodge on the scene, you can initialize by pressing key1 and key2. This is probably a cheating function, but I think it should be added for the progress of the game (and for the mood of students), so that the game can play longer and happier. I originally set to win by 15 points first, because the 4-bit binary LED can display 15 points at most, but in fact it is difficult to score 15 points, probably because I added these strange functions. Therefore, I finally changed the rules of the game to win by 3 points first.
4.2 design experience
1) I rewritten and deleted a lot based on the DEMO given to me, because my shell can display the shell track only based on the 1S time callback function, but I was not familiar with the meaning of callback at the beginning. I wrote the event of firing shell as a function and then in my1s_ The internal call of callback () led to all kinds of strange garbled code. In fact, the shell itself was already gone. I found this problem by consulting my classmates and checking the source file code, so I wrote all the information about the shell into my1s_ In callback (), I change the value of a global variable outside, and then cause my1s_ The reflection of this situation in callback () solves the problem of garbled code bug that has plagued us for many days. The discussion among students also helped me solve many problems.
2) Learning to be flexible is also a harvest of this experiment:
The length of nixie tube is limited, so Tank1 cannot move left and right;
It seems unfair that Tank1 can't move left and right, so add an "automatic firing" skill to it;
If you can't react quickly by continuously pressing the navigation Right key, the "flashback" function is added;
If you can't stop multiple shells and don't want to lose, give it a chance to "cheat".
3) Making full use of materials, I have used all the modules I can use in this game, including nixie tube, LED, 3 keys and 5 navigation keys. If the nixie tube is long enough and there are spare keys, maybe I want to add the skills of continuous firing of 2 shells or simultaneous firing of two ballistic shells. In fact, my little game is better than the "tank war" I played when I was a child Rich functions.
main.c section

#include "main.H"                              //±ØÐë¡£±àдӦÓóÌÐòʱ£¬½öÐè¸Äд main.h ºÍ main.cÎļþ 
#include "song.c"                              //¾ÙÀý¡£song.cÖбàдÁËÒôÀÖ£¨Í¬Ò»Ê׸裩±àÂë
#include "music.h"
struct_ADC        ADCresult;                   //¾ÙÀý¡£ ÈÈÃô¡¢¹âÃô²âÁ¿ADÖµ           
unsigned char Music_tone,Music_PM;             //¾ÙÀý¡£ ÒôÀÖ²¥·ÅÒôµ÷¡¢½Ú´Õ£¨Ã¿·ÖÖÓ½ÚÅÄÊý£©
unsigned char rxd[8];                          //¾ÙÀý¡£Í¨ÐÅ£¨´®¿Ú1¡¢´®¿Ú2¡¢ºìÍâ¹²Óã©»º³åÇø8×Ö½Ú
unsigned char rxdhead[2]={0xAA,0x55};          //¾ÙÀý¡£Í¨ÐÅ£¨´®¿Ú1¡¢´®¿Ú2£©½ÓÊÕ°üÍ·Æ¥Åä×Ö·û2×Ö½Ú£º£¨0xzu[3]£¬0x55£©    
unsigned char Tank1=0;
unsigned char Tank2=3;

int q,ll;int w=1;
unsigned char plm=0;
unsigned char pl[6]={0,0,0,0,0,0};
unsigned char	key[6]={0,0,0,0,0,0};
unsigned char	paodan[6]={9,9,9,9,9,9};//ÅÚµ¯µÄϱê
unsigned char zu[6]={0,0,0,0,0,0};		//ϱê´úÊý
unsigned char flag[6]={1,1,1,1,1,1};	//6¸öÅжÏÖµ
unsigned char t[8]={0,16,16,16,16,16,16,3};
unsigned char lc=0,rc=0;
/*
unsigned char funcmode;                  //¾ÙÀý¡£¶¨ÒåÏÔʾ¡¢°´¼ü¹¦ÄÜģʽ
enum funcname {
							 Tank_Battle=1,
               Rt_Rop,                         //                    ÈÈÃô¹âÃô²âÁ¿
               Music,                          //                    ÒôÀÖ²¥·Å
               FMradio,                        //                    FMÊÕÒô»ú
               UltroSonic,                     //                    ³¬Éù²¨²â¾à
               Weight};                        //                    µç×Ó³Ó
unsigned char tempadj;                   //¾ÙÀý¡£³ÌÐò±äÁ¿¡£µ÷ÕûʱÖÓʱÓãº=1 µ÷Äê»òʱ£»=2 µ÷Ô»ò·Ö =3 µ÷ÈÕ »òÃë
*/
//******* Óû§³ÌÐò¶Î4£ºÓû§×Ô¶¨Ò庯ÊýÔ­ÐÍ *************//
#include "function.c" 

void myUart1Rxd_callback()                    //¾ÙÀý¡£´®¿Ú1ÊÕµ½ºÏ·¨Êý¾Ý°ü»Øµ÷º¯Êý¡££¨ºÏ·¨Êý¾Ý°ü£ºzu[3]£¬55£¬......¡£¹²8×Ö½Ú£©
{ if ( GetUart2TxStatus() == enumUart2TxFree )                  
	  {	(*(rxd+6)) += 1;                                          //µÚ7×Ö½Ú¼Ó1
	     Uart2Print(&rxd, sizeof(rxd));                           //½«Êý¾Ý°ü´Ó´®¿Ú2(485¡¢»òEXTÀ©Õ¹½Ó¿ÚÉÏ)·¢ËͳöÈ¥
    }			
}

void myUart2Rxd_callback()                    //¾ÙÀý¡£´®¿Ú2ÊÕµ½ºÏ·¨Êý¾Ý°ü»Øµ÷º¯Êý¡££¨ºÏ·¨Êý¾Ý°ü£ºzu[3]£¬55£¬......¡£¹²8×Ö½Ú£©
{ if ( GetIrStatus() == enumIrFree ) 
	 { (*(rxd+6)) += 2;                                             //µÚ7×Ö½Ú¼Ó2
	   IrPrint(&rxd, sizeof(rxd));                                  //½«Êý¾Ý°ü´ÓºìÍâ·¢ËͳöÈ¥
	 }
}

void my1mS_callback()			                  //¾ÙÀý¡£1mSʼþ»Øµ÷º¯Êý
{  
}
	
void my10mS_callback()			                //¾ÙÀý¡£10mSʼþ»Øµ÷º¯Êý
{ dealwithDisp();   
}

void my100mS_callback()			                //¾ÙÀý¡£100mSʼþ»Øµ÷º¯Êý
{                        
}			 
							 
void my1S_callback()				               //¾ÙÀý¡£1Sʼþ»Øµ÷º¯Êý
{ 
		LedPrint(lc+rc);						//LED¼Ç¼µÃ·Ö
		if(flag[0]==0){//×óÖз¢Éä
		zu[0]=paodan[0];paodan[0]++;
		if(t[zu[0]+1]==Tank2){Tank2=14;t[zu[0]+1]=14;t[zu[0]]=16;flag[0]=1;lc=lc+16;SetBeep(1350,10);}//ÃüÖÐ ÓÒ±ß̹¿Ë
		else if(t[zu[0]+1]==t[zu[0]]) {t[zu[0]]=16;t[zu[0]+1]=16; flag[0]=1;}	//ÅÚµ¯ÏàÓö	
		else if(t[zu[0]+1]==16){pl[0]=t[zu[0]+1];t[zu[0]+1]=t[zu[0]];t[zu[0]]=pl[0]; flag[0]=0;}//ÅÚµ¯Î´ÏàÓö»òÅÚµ¯ÀàÐͲ»Í¬	
}
		if(flag[1]==0){//×óÉÏ·¢Éä
		zu[1]=paodan[1];paodan[1]++;
		if(t[zu[1]+1]==Tank2&&Tank2==5){Tank2=25;t[zu[1]+1]=25;key[1]=zu[1]+1;t[zu[1]]=16;flag[1]=1;}// ÓÒ±ß̹¿Ë¶ã±ÜÅÚµ¯
		else if(t[zu[1]+1]==Tank2){Tank2=14;t[zu[1]+1]=14;t[zu[1]]=16;flag[1]=1;lc=lc+16;SetBeep(1350,10);}//ÃüÖÐ ÓÒ±ß̹¿Ë
		else if(t[zu[1]+1]==t[zu[1]]) {t[zu[1]]=16;t[zu[1]+1]=16; flag[1]=1;}					//ÅÚµ¯ÏàÓö	
		else if(zu[1]+1>=8){t[zu[1]]=16;}
		else if(t[zu[1]+1]==16){pl[1]=t[zu[1]+1];t[zu[1]+1]=t[zu[1]];t[zu[1]]=pl[1]; flag[1]=0;}//ÅÚµ¯Î´ÏàÓö»òÅÚµ¯ÀàÐͲ»Í¬	
}

		if(flag[2]==0){//×óÏ·¢Éä
		zu[2]=paodan[2];paodan[2]++;
		if(t[zu[2]+1]==Tank2&&Tank2==4){Tank2=26;t[zu[2]+1]=26;key[2]=zu[2]+1;t[zu[2]]=16;flag[2]=1;}// ÓÒ±ß̹¿Ë¶ã±ÜÅÚµ¯
		else if(t[zu[2]+1]==Tank2){Tank2=14;t[zu[2]+1]=14;t[zu[2]]=16;flag[2]=1;lc=lc+16;SetBeep(1350,10);}//ÃüÖÐ ÓÒ±ß̹¿Ë
		else if(t[zu[2]+1]==t[zu[2]]) {t[zu[2]]=16;t[zu[2]+1]=16; flag[2]=1;}					//ÅÚµ¯ÏàÓö
		else if(zu[2]+1>=8){t[zu[2]]=16;}
		else if(t[zu[2]+1]==16){pl[2]=t[zu[2]+1];t[zu[2]+1]=t[zu[2]];t[zu[2]]=pl[2]; flag[2]=0;}//ÅÚµ¯Î´ÏàÓö»òÅÚµ¯ÀàÐͲ»Í¬	
}

		if(flag[3]==0){//ÓÒÏ·¢Éä
		zu[3]=paodan[3];paodan[3]--;
		if(t[zu[3]-1]==Tank1&&Tank1==1){Tank1=24;t[0]=24;t[1]=16;key[3]=1;flag[3]=1;}//×ó±ß̹¿Ë¶ã±ÜÅÚµ¯
		else if(t[zu[3]-1]==Tank1){Tank1=14;t[zu[3]-1]=14;t[zu[3]]=16;flag[3]=1;rc=rc+1;SetBeep(1350,10);}//ÃüÖÐ ×ó±ß̹¿Ë
		else if(t[zu[3]-1]==t[zu[3]]){t[zu[3]-1]=16;t[zu[3]]=16;flag[3]=1;SetBeep(1350,10);}//Á½·¢ÅÚµ¯ÏàÓöÒý±¬£¬·µ»ØÒ»¸öÅжÏÖµ
		else if(t[zu[3]-1]!=t[zu[3]]){pl[3]=t[zu[3]-1];t[zu[3]-1]=t[zu[3]];t[zu[3]]=pl[3];flag[3]=0;}//ÅÚµ¯Î´ÏàÓö
}
		if(flag[4]==0){//ÓÒÉÏ·¢Éä
		zu[4]=paodan[4];paodan[4]--;
		if(t[zu[4]-1]==Tank1&&Tank1==2){Tank1=23;t[zu[4]-1]=23;t[zu[4]]=16;key[4]=1;flag[4]=1;}//×ó±ß̹¿Ë¶ã±ÜÅÚµ¯
		else if(t[zu[4]-1]==Tank1){Tank1=14;t[zu[4]-1]=14;t[zu[4]]=16;flag[4]=1;rc=rc+1;SetBeep(1350,10);}//ÃüÖÐ ×ó±ß̹¿Ë
		else if(t[zu[4]-1]==t[zu[4]]){t[zu[4]-1]=16;t[zu[4]]=16;flag[4]=1;SetBeep(1350,10);}//Á½·¢ÅÚµ¯ÏàÓöÒý±¬£¬·µ»ØÒ»¸öÅжÏÖµ	
		else if(t[zu[4]-1]!=t[zu[4]]){pl[4]=t[zu[4]-1];t[zu[4]-1]=t[zu[4]];t[zu[4]]=pl[4];flag[4]=0;}//ÅÚµ¯Î´ÏàÓö
}
		if(flag[5]==0){//ÓÒÖз¢Éä				//ÏÂ17 ÖÐ18 ÉÏ19            ÉÏÖÐ20   ÉÏÏÂ21   ÖÐÏÂ22			
		zu[5]=paodan[5];paodan[5]--;
		if(t[zu[5]-1]==Tank1){Tank1=14;t[0]=14;t[zu[5]]=16;flag[5]=1;rc=rc+1;	SetBeep(1350,10);}		//ÃüÖÐ ×ó±ß̹¿Ë
		else if(t[zu[5]-1]==t[zu[5]]){t[zu[5]-1]=16;t[zu[5]]=16;flag[5]=1;SetBeep(1350,10);}//Á½·¢ÅÚµ¯ÏàÓöÒý±¬£¬·µ»ØÒ»¸öÅжÏÖµ	
		else if(t[zu[5]-1]!=t[zu[5]]){pl[5]=t[zu[5]-1];t[zu[5]-1]=t[zu[5]];t[zu[5]]=pl[5];flag[5]=0;}//ÅÚµ¯Î´ÏàÓö
}	
		plm++;
		if(plm%2==0)//Tank¶ã±ÜÅÚµ¯µÄ״̬ÏÔʾ
		{	if(key[4]!=0){Tank1=2;t[0]=2;key[4]=0;}
			if(key[3]!=0){Tank1=1;t[0]=1;key[3]=0;}
			if(key[2]!=0){Tank2=4;t[key[2]]=4;paodan[2]=key[2]+1;t[key[2]+1]=17;flag[2]=0;key[2]=0;}
			if(key[1]!=0){Tank2=5;t[key[1]]=5;paodan[1]=key[1]+1;t[key[1]+1]=19;flag[1]=0;key[1]=0;}}
}
void myADC_callback()                      //¾ÙÀý¡£ADCʼþ»Øµ÷º¯Êý
{ 
}

void myKN_callback()			               	 //¾ÙÀý¡£µ¼º½°´¼üʼþ»Øµ÷º¯Êý
{ dealwithmyKN();		
}

void myhall_callback()		                 //ʾÀý¡£ÓÐhallʼþ»Øµ÷º¯Êý£º·¢Éù±¨¾¯
{	if(GetHallAct() == enumHallGetClose) SetBeep(1350,100);		
}

void mykey_callback()		                   // °´¼ü£¨Key1¡¢Key2£©Ê¼þ»Øµ÷º¯Êý
{	dealwithmykey();	  
}

void mySV_callback()		                   //ʾÀý: Õñ¶¯Ê¼þ»Øµ÷º¯Êý£º¿ØÖÆÒôÀÖ²¥·Å/ÔÝÍ£
{	if(GetVibAct())
	if (GetPlayerMode() == enumModePause) SetPlayerMode(enumModePlay); 
			else  SetPlayerMode(enumModePause);			
}

//******* main()º¯Êý *************//	
void main() {         //Ö÷º¯Êý main() ¿ªÊ¼         //´ËÐбØÐ룡£¡£¡ 
    Key_Init();                                      //¾ÙÀý£¬ÐèÒªÓõ½µÄÄ£¿é¼°Æ亯Êý¡¢·½·¨£¬±ØÐë¶ÔÆä³õʼ»¯£¨ÈÃÆä×¼±¸¡¢¾ÍÐ÷ºÍÏìÓ¦×öºǫ́·þÎñ£©
	  HallInit();                                      //¾ÙÀý
	  VibInit();                                       //¾ÙÀý
	  DisplayerInit();                                 //¾ÙÀý
	  BeepInit();	                                     //¾ÙÀý
    MusicPlayerInit();	                             //¾ÙÀý
	  AdcInit(ADCexpEXT);                              //¾ÙÀý£¬ADCÄ£¿é³õʼ»¯£¬ÓвÎÊý£¬Ñ¡ÔñÀ©Õ¹½Ó¿ÚEXTÉÏP1.0¡¢P1.1ÊÇ·ñÒ²×öADC¹¦ÄÜ
		IrInit(NEC_R05d);                                //¾ÙÀý£¬ºìÍâ½Ó¿ÚÉèÖÃ
	  Uart1Init(1200);                                 //¾ÙÀý£¬´®¿Ú1³õʼ»¯£¬ÓвÎÊý£¬ÉèÖÃUart1ͨÐŲ¨ÌØÂÊ
    /******* ÒÔÏ¿É2Ñ¡1£º¼ÓÔØ´®¿Ú2 ********/    
    Uart2Init(2400,Uart2Usedfor485);                 //¾ÙÀý£¬´®¿Ú2³õʼ»¯µ½485½Ó¿Ú£¨RS485¹¤ÒµÏÖ³¡×ÜÏߣ¬°ëË«¹¤£©		
//2,ÉèÖÃʼþ»Øµ÷º¯Êý(ÓÉsysÌṩÉèÖú¯ÊýSetEventCallBack())	
		SetEventCallBack(enumEventKey, mykey_callback);            //¾ÙÀý
		SetEventCallBack(enumEventSys1mS, my1mS_callback);         //¾ÙÀý
		SetEventCallBack(enumEventSys10mS, my10mS_callback);       //¾ÙÀý
		SetEventCallBack(enumEventSys100mS, my100mS_callback);     //¾ÙÀý
		SetEventCallBack(enumEventSys1S, my1S_callback);           //¾ÙÀý
		SetEventCallBack(enumEventHall, myhall_callback);          //¾ÙÀý
		SetEventCallBack(enumEventVib, mySV_callback);             //¾ÙÀý
		SetEventCallBack(enumEventNav, myKN_callback);             //¾ÙÀý£¬ÉèÖõ¼º½°´¼ü»Øµ÷º¯Êý
    SetEventCallBack(enumEventUart1Rxd, myUart1Rxd_callback);  //¾ÙÀý£¬ÉèÖô®¿Ú1½ÓÊջص÷º¯Êý
		SetEventCallBack(enumEventUart2Rxd, myUart2Rxd_callback);  //¾ÙÀý£¬ÉèÖô®¿Ú2½ÓÊջص÷º¯Êý
		SetEventCallBack(enumEventXADC,myADC_callback);            //À©Õ¹½Ó¿ÚÉÏеÄADֵʼþ
//3,Óû§³ÌÐò״̬³õʼ»¯ 	
		SetDisplayerArea(0,7);                           //¾ÙÀý
	  SetUart1Rxd(&rxd, sizeof(rxd), rxdhead, sizeof(rxdhead));   //ÉèÖô®¿Ú½ÓÊÕ·½Ê½£ºÊý¾Ý°üÌõ¼þ£º½ÓÊÕÊý¾Ý°ü·ÅÖÃÔÚrxdÖУ¬Êý¾Ý°ü´óСrxd´óС£¬Êý¾Ý°üÍ·ÐèÒªÓërxdheadÆ¥Å䣬ƥÅäÊýÁ¿rxdhead´óС
	  SetUart2Rxd(&rxd, sizeof(rxd), rxdhead, sizeof(rxdhead)); 
		SetIrRxd(&rxd);                                     //¾ÙÀý                          
    LedPrint(0);	
		
/*****************  MySTC_OS ³õʼ»¯Óë¼ÓÔØ¿ªÊ¼  ********************************/   
	  MySTC_Init();	    // MySTC_OS ³õʼ»¯         //´ËÐбØÐ룡£¡£¡   
	while(1)            // ϵͳÖ÷Ñ­»·              //´ËÐбØÐ룡£¡£¡   	
		{ MySTC_OS();     // MySTC_OS ¼ÓÔØ           //´ËÐбØÐ룡£¡£¡
			if(lc==48||rc==3){SetMusic(Music_PM, Music_tone, &song, sizeof(song), enumMscNull); 
							        SetPlayerMode(enumModePlay);}
			if(lc==48||rc==3){lost();}
		}	              //Ö÷Ñ­»·while(1)½áÊø         //´ËÐбØÐ룡£¡£¡ 
}                   //Ö÷º¯Êý main() ½áÊø         //´ËÐбØÐ룡£¡£¡ 

function.c Part

void dealwithDisp(){ Seg7Print(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7]);}	
void lost(){t[0]=(lc/16)/10+6;t[1]=(lc/16)%10+6;//¼ÆËãË«·½µÃ·Ö
	t[2]=18;t[3]=18;t[4]=18;t[5]=18;t[6]=rc/10+6;t[7]=rc%10+6;}
void dealwithmyKN()			               	                      
{                    	
				if(GetAdcNavAct(enumAdcNavKey3) == enumKeyPress) //°´¼ü3¿ØÖÆ×ó±ß£¬Í¬Ê±×Ô¶¯·¢ÅÚ
		{ 	
				if((Tank1++)>=2)Tank1=0;t[0]=Tank1;

				if(t[0]==0){paodan[0]=1;t[1]=18;flag[0]=0;
		}
				if(t[0]==1){paodan[1]=1;t[1]=19;flag[1]=0;
		}
				if(t[0]==2){paodan[2]=1;t[1]=17;flag[2]=0;
		}
		}

											if(GetAdcNavAct(enumAdcNavKeyUp)== enumKeyPress)     { 		
												//µ¼º½¼üÉÏÏ¿ØÖÆTank2ÉÏÏÂλÒÆ 
												for(q=0;q<8;q++){	if(Tank2==t[q]){
																					if((Tank2++) >=5) Tank2 =3;
																					t[q]=Tank2;dealwithDisp();}}}
											if(GetAdcNavAct(enumAdcNavKeyDown)== enumKeyPress)     { 													 
												for(q=0;q<8;q++){	if(Tank2==t[q]){
																					if((Tank2--) <=3) Tank2 =5;
																					t[q]=Tank2;dealwithDisp();}}}	
											if(GetAdcNavAct(enumAdcNavKeyRight) == enumKeyPress){
												//µ¼º½¼ü×óÓÒ¿ØÖÆÇ°ºóλÒÆ£¬ÉèÖÃRightΪÉÁ»Ø¼ü£¬¿ÉÒÔÒ»¼ü»Øµ½×îÓÒλÖÃ
												 for(q=0;q<8;q++){	 ll=q; if(Tank2==t[q]&&(q>=2&&q<=7)){
												if((ll++) >=7) ll =7;
												t[ll]=Tank2;if(ll!=q)t[q]=16;dealwithDisp();}}}												
											if(GetAdcNavAct(enumAdcNavKeyLeft) == enumKeyPress){
												 q=0;for(;q<8;q++){	 ll=q; if(Tank2==t[q]&&(q>=2&&q<=7)){
												if((ll--)<=2) ll =2;
												t[ll]=Tank2;if(ll!=q)t[q]=16;dealwithDisp();}}}
			
		
			if(GetAdcNavAct(enumAdcNavKeyCenter)== enumKeyPress)//µ¼º½ÖÐÐÄ°´¼ü¿ØÖÆÓұ߷¢ÅÚ                                 
		{	w=1;
			if(Tank2==3)
					for(;w<8;w++)
					if(t[w]==Tank2){t[w-1]=18;paodan[5]=w-1;flag[5]=0;}	
			if(Tank2==4)
					for(;w<8;w++)
					if(t[w]==Tank2){t[w-1]=19;paodan[4]=w-1;flag[4]=0;}
					
			if(Tank2==5)
					for(;w<8;w++)
					if(t[w]==Tank2){t[w-1]=17;paodan[3]=w-1;flag[3]=0;}
					
		}	
		
}

void dealwithmykey()		                  
{	
		if (GetKeyAct(enumKey1)== enumKeyPress) //²é¿´µÃ·Ö	                                      
			{	 
					lost();
			}
	  if (GetKeyAct(enumKey2)== enumKeyPress)   //»Ö¸´ÓÎÏ· 		                             
			{ 
						Tank1=0;Tank2=3; plm=0;
						pl[0]=0;pl[1]=0;pl[2]=0;pl[3]=0;pl[4]=0;pl[5]=0;
						key[0]=0;key[1]=0;key[2]=0;key[3]=0;key[4]=0;key[5]=0;
						paodan[0]=9;paodan[1]=9;paodan[2]=9;
						paodan[3]=9;paodan[4]=9;paodan[5]=9;
						zu[0]=0;zu[1]=0;zu[2]=0;zu[3]=0;zu[4]=0;zu[5]=0;
						flag[0]=1;flag[1]=1;flag[2]=1;flag[3]=1;flag[4]=1;flag[5]=1;
						t[0]=0;t[1]=16;t[2]=16;t[3]=16;t[4]=16;t[5]=16;t[6]=16;t[7]=3;
						paodan[0]=1;t[1]=18;flag[0]=0;
			}
			
	 

}

Add link description

Posted by patch2112 on Fri, 08 Oct 2021 10:30:08 -0700