embRACE, a game developed on the embedded platform, entirely coded in assembly language. The game has been programmed on an ATMega16 micro-controller, interfaced with a 16×2 LCD display module. It is assumed that the reader has gone through the project How to get started with AVR and Interface LCD with AVR.
Fig. 1: Prototype of AVR ATMega16 based Game emBrace
The game possesses an interactive user interface and exclusive features like:
-Main Menu
-Pause Menu
-Real Time Score display
-Life Indicator LEDs
-Non-volatile High Score storage
The LCD display uses custom LCD characters to display various characters in the game whose generation timing in the game is totally randomized by the code. In the design and code phase it has particularly been taken care of that the overall game is interesting and substantially user-interactive. Moreover, the assembly language programming has majorly contributed towards the development of a more optimized, machine-friendly and effective code.
Why Assembly Language?
Assembly language is a low-level programming language for a computer or other programmable device specific to particular computer architecture in contrast to most high-level programming languages, which are generally portable across multiple systems. If you are new to assembly language and earlier programmed in some other high-level language, the first advice for you is to temporarily forget the language as assembly is a lot different. However, assembly language is machine specific (specific for different micro-controller families) and might at times be tedious jobs to deal with. But it’s not a thing to worry about as the sacrifice of switching to assembly from a high-level language pays off well for certain projects. Assembly language comes with a number of advantages over other languages, some of them being:
– Strong correspondence to machine architecture
– Substantially simplifies the complexity of applications,
– Suited for applications where time criticallity is an importrant factor,
– Occupies lesser memory (in most cases),
– Easier to understand,
– Easier to correct errors and modify
Also, because only necessary code steps are executed, assembly programs are as fast as possible and the duration of every step is known. Most importantly, unlike other languages there is never a situation when an assembly program executes different than designed and expected,
The two main components of the project are the ATmega16 micro-controller and the JHD162A16x2 LCD module. Here is a brief introduction to the two of them.
ATmega16 Microcontroller & LCD Module
ATmega16 micro-controller
ATmega16 is an 8-bit high performance microcontroller of Atmel’s Mega AVR family with low power consumption. Atmega16 is based on enhanced RISC (Reduced Instruction Set Computing) architecture with 131 powerful instructions. Most of the instructions execute in one machine cycle. Atmega16 can work on a maximum frequency of 16MHz.
ATmega16 has 16 KB programmable flash memory, static RAM of 1 KB and EEPROM of 512 Bytes. The endurance cycle of flash memory and EEPROM is 10,000 and 100,000, respectively.
ATmega16 is a 40 pin microcontroller. There are 32 I/O (input/output) lines which are divided into four 8-bit ports designated as PORTA, PORTB, PORTC and PORTD.
JHD162A LCD module
JHD162A, a 16×2 LCD display, is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments and other multi segment LEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on.
A 16×2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5×7 pixel matrix. This LCD has two registers, namely, Command and Data. The salient features of the JHD162A module are as follows:
– 16 Characters x 2 Lines
– Built-in HD44780 Equivalent LCD Controller
– Works directly with ATMEGA, ARDUINO, PIC amd many other microcontroller/kits.
– 4 or 8 bit data I/O interface
– Low power consumption
Different Attributes of the Game
embRACE
The programming of the game was the toughest part of the story. The testing and debugging phase of the game took quite a lot of time but the result was worth it. The programming of the micro-controller was done using an ISP (In-System Programming) programmer.
Fig. 2: Image of AVR ATMega16 based Game emBrace
The game uses custom LCD characters for the gameplay which give an idiocratic look to the game. JHD162A LCD module allows the user to define a total of eight custom LCD characters in its 8×5 display arrays. Along with a code optimized gameplay and simple controls the game also provides different menus justifying its user friendly setup.
The different attributes of the game are explained as follows:
Home-Screen / Main Menu – The home-screen is a continuous animation giving a vibrant introduction to the game. The home-screen also has the Main Menu which contains the options of Help, Play and High-Score.
Help – It contains description of different symbols and characters used in the game and the number of levels and lives available in the game.
Play – This option starts the game.
High-Score – It contains the highest score made by a player on the machine. At the end of every game the score of the player is compared with the present high score and the higher score is updated in the High-Score. It also has an option to reset the High-Score.
Life Indicating LEDs – These are three LEDs connected to PORTC-0 to PORTC-2 of the micro-controller. The number of glowing LEDs represents the number of lives left with the player.
Selection / Navigation Controls – These are three switches to facilitate the user with selection of the respective options in the menus and for navigation during game play. The switches are wired to PORTC-3 to PORTC-5 of the micro-controller.
Real Time Score – This is the real time score displayed at the top-right corner of the screen during gameplay. It is subject to the amount of time for which the user has sustained in the game. Every 100 unit increment in the score is accompanied with a level upgradation.
Levels – There are a total of 10 levels in embRACE. Getting upgraded to a level also speeds up the game play making the game more challenging.
Lives – A total of three lives are bestowed upon the player at the start. Hitting an enemy ship makes the player lose a life while the player can gain a life by acquiring a heart.
Pause Menu – Pressing the centre switch during the gameplay pauses the game and directs the player to the Pause Menu. The Pause Menu has three options of Quit, Resume and Restart.
Quit – This terminates the game play and displays the player’s current score as the final score.
Resume – This redirects the user to the game continuing from the point at which the game was paused.
Restart – This starts the game from the beginning refreshing the score, the number of lives and the level.
The Game Plot
The player on his vehicle, the ‘Cruiser’ has taken the burden to free his civilization from the portentous situation developing in his home territory due to growing atrocities from the enemy side. The player’s mission is to reach to the capital of the enemy territory located at the center of the territory and destroy it. However, on entering the enemy territory the player has to confront the ‘Enemy Fleet’ coming from the opposite direction. On colliding with an enemy ship, the player loses a life. Still, the player can steal ‘Hearts’ from the enemy territory to gain a life. The further the player gets inside the enemy territory, the level increases and the enemy fleet also speeds up making it more formidable. The capital is located at Level-10 and on reaching it the player is victorious.
Project Source Code
###
//----------------------------------------------------------------------------//--------------------------embRACE - asm Code--------------------------------//-----------------------Programmed by Mrigank Kumar--------------------------//---------For further queries please contact @ [email protected]//----------------------------------------------------------------------------NAME mainPUBLIC mainORG $0RJMP mainRSEG CODEmain NOP//---------------------------INITIALISATIONS----------------------------------//stack initialiseldi r16,$04 //initialise stack(SPH & SPL) at RAMENDout $3e,r16ldi r16,$5fout $3d,r16//port initialiseldi r16,$ffout $1a,r16 //set PA0-PA7 as outputldi r16,$07out $17,r16 //set PB0-PB2 as outputclr r16out $1b,r16 //clear PORTA(PA0-PA7)out $18,r16 //clear PORTB(PB0-PB2)//for switchesldi r16,$07out $14,r16 //set DDRC=07//lcd initialisecall d100ldi r17,$38 //8 data linescall wrtcldi r17,$06 //cursor settingcall wrtcldi r17,$0f //display oncall wrtcldi r17,$01 //clear LCD memorycall wrtccall d10//---------------------Special characters' initialisations---------------------//life 00char ldi r17,$40call wrtcldi r18,00call wrtdinc r17call wrtcldi r18,08call wrtdinc r17call wrtcldi r18,28call wrtdcall d1inc r17call wrtcldi r18,30call wrtdcall d1inc r17call wrtcldi r18,15call wrtdcall d1inc r17call wrtcldi r18,30call wrtdcall d1inc r17call wrtcldi r18,28call wrtdcall d1inc r17call wrtcldi r18,08call wrtdcall d1//-----------------------------------------------------------------------------//car 01inc r17call wrtcldi r18,31call wrtdcall d1inc r17call wrtcldi r18,03call wrtdcall d1inc r17call wrtcldi r18,05call wrtdinc r17call wrtcldi r18,15call wrtdcall d1inc r17call wrtcldi r18,15call wrtdcall d1inc r17call wrtcldi r18,05call wrtdcall d1inc r17call wrtcldi r18,03call wrtdcall d1inc r17call wrtcldi r18,31call wrtdcall d1//-----------------------------------------------------------------------------//car 02inc r17call wrtcldi r18,31call wrtdcall d1inc r17call wrtcldi r18,04call wrtdcall d1inc r17call wrtcldi r18,13call wrtdinc r17call wrtcldi r18,31call wrtdcall d1inc r17call wrtcldi r18,31call wrtdcall d1inc r17call wrtcldi r18,13call wrtdcall d1inc r17call wrtcldi r18,04call wrtdcall d1inc r17call wrtcldi r18,31call wrtdcall d1//-----------------------------------------------------------------------------//car 03inc r17call wrtcldi r18,15call wrtdcall d1inc r17call wrtcldi r18,07call wrtdcall d1inc r17call wrtcldi r18,04call wrtdinc r17call wrtcldi r18,30call wrtdcall d1inc r17call wrtcldi r18,30call wrtdcall d1inc r17call wrtcldi r18,04call wrtdcall d1inc r17call wrtcldi r18,07call wrtdcall d1inc r17call wrtcldi r18,15call wrtdcall d1//-----------------------------------------------------------------------------//car 04inc r17call wrtcldi r18,15call wrtdcall d1inc r17call wrtcldi r18,07call wrtdcall d1inc r17call wrtcldi r18,29call wrtdinc r17call wrtcldi r18,22call wrtdcall d1inc r17call wrtcldi r18,22call wrtdcall d1inc r17call wrtcldi r18,29call wrtdcall d1inc r17call wrtcldi r18,07call wrtdcall d1inc r17call wrtcldi r18,15call wrtdcall d1//-----------------------------------------------------------------------------//my car 05inc r17call wrtcldi r18,15call wrtdcall d1inc r17call wrtcldi r18,04call wrtdcall d1inc r17call wrtcldi r18,12call wrtdinc r17call wrtcldi r18,28call wrtdcall d1inc r17call wrtcldi r18,28call wrtdcall d1inc r17call wrtcldi r18,12call wrtdcall d1inc r17call wrtcldi r18,04call wrtdcall d1inc r17call wrtcldi r18,15call wrtdcall d1//----------------------------------START-------------------------------------//----------------------------------------------------------------------------//----------------------------LCD initialisation------------------------------linit ldi r17,112call wrtcldi r18,31call wrtdcall d1inc r17call wrtcldi r18,12call wrtdcall d1inc r17call wrtcldi r18,06call wrtdinc r17call wrtcldi r18,13call wrtdcall d1inc r17call wrtcldi r18,13call wrtdcall d1inc r17call wrtcldi r18,06call wrtdcall d1inc r17call wrtcldi r18,12call wrtdcall d1inc r17call wrtcldi r18,31call wrtdcall d1ldi r17,$01call wrtcldi r16,1ldi r17,1ldi r18,' 'call displldi r23,02//----------To set intitial loop start positions of enemy ships----------------lstrt ldi r19,00sts $03fe,r19sts $03ff,r19ldi r19,18sts $0400,r19sts $0401,r19sts $0402,r19sts $0403,r19sts $0404,r19sts $0405,r19sts $0406,r19sts $0407,r19ldi r20,$02sts $042f,r20ldi r20,$04sts $0430,r20sts $0431,r20sts $0432,r20sts $0433,r20sts $0434,r20sts $0435,r20sts $0436,r20sts $0437,r20ldi r21,$00//--------------------To display moving enemy fleets---------------------------strt ldi r16,1 //changeldi r17,17 //changeldi r18,$06 //changelds r19,$03ff //change 0lds r20,$042f //change 0sbrs r20,1jmp ppd1 //change acp r19,r17brsh pd1 //change acpi r21,$03 //speedbrlo ppd1 //change ainc r19ldi r21,$00ppd1 mov r17,r19 //change ajmp ds1 //change apd1 ldi r20,$01 //change asts $042f,r20 //change 0lds r20,$0430 //change 1ldi r20,$02sts $0430,r20 //change 1ds1 call dspl //change asts $03ff,r19 //change 0ldi r16,1 //changeldi r17,6 //changeldi r18,'e' //changelds r19,$0400 //change 0lds r20,$0430 //change 0sbrs r20,1jmp ppda //change acp r17,r19brsh pda //change acpi r21,$01 //speedbrlo ppda //change adec r19ldi r21,$00ppda mov r17,r19 //change ajmp dsa //change apda ldi r20,$01sts $0430,r20 //change 0lds r20,$0431 //change 1ldi r20,$02sts $0431,r20 //change 1dsa call dpl //change asts $0400,r19 //change 0ldi r16,1 //changeldi r17,7 //changeldi r18,'m' //changelds r19,$0401 //change 0lds r20,$0431 //change 0sbrs r20,1jmp ppdb //change acp r17,r19brsh pdb //change acpi r21,$01 //speedbrlo ppdb //change adec r19ldi r21,$00ppdb mov r17,r19 //change ajmp dsb //change apdb ldi r20,$01sts $0431,r20 //change 0lds r20,$0432 //change 1ldi r20,$02sts $0432,r20 //change 1dsb call dpl //change asts $0401,r19 //change 0ldi r16,1 //changeldi r17,8 //changeldi r18,'b' //changelds r19,$0402 //change 0lds r20,$0432 //change 0sbrs r20,1jmp ppdc //change acp r17,r19brsh pdc //change acpi r21,$01 //speedbrlo ppdc //change adec r19ldi r21,$00ppdc mov r17,r19 //change ajmp dsc //change apdc ldi r20,$01sts $0432,r20 //change 0lds r20,$0433 //change 1ldi r20,$02sts $0433,r20 //change 1dsc call dpl //change asts $0402,r19 //change 0ldi r16,1 //changeldi r17,9 //changeldi r18,'R' //changelds r19,$0403 //change 0lds r20,$0433 //change 0sbrs r20,1jmp ppdd //change acp r17,r19brsh pdd //change acpi r21,$01 //speedbrlo ppdd //change adec r19ldi r21,$00ppdd mov r17,r19 //change ajmp dsd //change apdd ldi r20,$02sts $0433,r20 //change 0lds r20,$0434 //change 1ldi r20,$02sts $0434,r20 //change 1dsd call dpl //change asts $0403,r19 //change 0ldi r16,1 //changeldi r17,10 //changeldi r18,'A' //changelds r19,$0404 //change 0lds r20,$0434 //change 0sbrs r20,1jmp ppde //change acp r17,r19brsh pde //change acpi r21,$02 //speedbrlo ppde //change adec r19ldi r21,$00ppde mov r17,r19 //change ajmp dse //change apde ldi r20,$01 //change asts $0434,r20 //change 0lds r20,$0435 //change 1ldi r20,$02sts $0435,r20 //change 1dse call dpl //change asts $0404,r19 //change 0ldi r16,1 //changeldi r17,11 //changeldi r18,'C' //changelds r19,$0405 //change 0lds r20,$0435 //change 0sbrs r20,1jmp ppdf //change acp r17,r19brsh pdf //change acpi r21,$02 //speedbrlo ppdf //change adec r19ldi r21,$00ppdf mov r17,r19 //change ajmp dsf //change apdf ldi r20,$01 //change asts $0435,r20 //change 0lds r20,$0436 //change 1ldi r20,$02sts $0436,r20 //change 1dsf call dpl //change asts $0405,r19 //change 0ldi r16,1 //changeldi r17,12 //changeldi r18,'E' //changelds r19,$0406 //change 0lds r20,$0436 //change 0sbrs r20,1jmp ppdg //change acp r17,r19brsh pdg //change acpi r21,$02 //speedbrlo ppdg //change adec r19ldi r21,$00ppdg mov r17,r19 //change ajmp dsg //change apdg ldi r20,$01 //change asts $0436,r20 //change 0lds r20,$0437 //change 1ldi r20,$02sts $0437,r20 //change 1dsg call dpl //change asts $0406,r19 //change 0ldi r16,1 //changeldi r17,14 //changeldi r18,' ' //changelds r19,$0407 //change 0lds r20,$0437 //change 0sbrs r20,1jmp ppdh //change acp r17,r19brsh pdh //change acpi r21,$0a //speedbrlo ppdh //change adec r19ldi r21,$00ppdh mov r17,r19 //change ajmp dsh //change apdh ldi r20,$01 //change asts $0437,r20 //change 0lds r20,$0438 //change 1ldi r20,$02sts $0438,r20 //change 1jmp lstrtdsh call dpl //change asts $0407,r19 //change 0ldi r16,2ldi r17,1ldi r18,'h'call displldi r16,2ldi r17,2ldi r18,'e'call displldi r16,2ldi r17,3ldi r18,'l'call displldi r16,2ldi r17,4ldi r18,'p'call displldi r16,2ldi r17,6ldi r18,'p'call displldi r16,2ldi r17,7ldi r18,'l'call displldi r16,2ldi r17,8ldi r18,'a'call displldi r16,2ldi r17,9ldi r18,'y'call displldi r16,2ldi r17,11ldi r18,'h'call displldi r16,2ldi r17,12ldi r18,'s'call displldi r16,2ldi r17,13ldi r18,'c'call displldi r16,2ldi r17,14ldi r18,'o'call displldi r16,2ldi r17,15ldi r18,'r'call displldi r16,2ldi r17,16ldi r18,'e'call displinc r21in r22,$13ori r22,$38out $15,r22 //set PC3, PC4, PC5 as pull-upssbis $13,3call d100sbis $13,3jmp hscoresbis $13,5call d100sbis $13,5jmp helpsbic $13,4 //check for switch 3 press*/jmp loopdec r23tst r23brne loopjmp gameloop jmp strt//----------------------------------HELP--------------------------------------help in r22,$13ori r22,$38out $15,r22 //set PC3, PC4, PC5 as pull-upsldi r17,$01call wrtc //clear screenldi r16,1ldi r17,1ldi r18,' 'call displhelp11 ldi r16,1ldi r17,2ldi r18,$00call displldi r16,1ldi r17,3ldi r18,':'call displldi r16,1ldi r17,4ldi r18,'L'call displldi r16,1ldi r17,5ldi r18,'i'call displldi r16,1ldi r17,6ldi r18,'f'call displldi r16,1ldi r17,7ldi r18,'e'call displldi r16,2ldi r17,2ldi r18,$01call displldi r16,2ldi r17,3ldi r18,':'call displldi r16,2ldi r17,4ldi r18,'C'call displldi r16,2ldi r17,5ldi r18,'r'call displldi r16,2ldi r17,6ldi r18,'u'call displldi r16,2ldi r17,7ldi r18,'i'call displldi r16,2ldi r17,8ldi r18,'s'call displldi r16,2ldi r17,9ldi r18,'e'call displldi r16,2ldi r17,10ldi r18,'r'call displldi r16,2ldi r17,16ldi r18,$7ecall displin r22,$13ori r22,$38out $15,r22 //set PC3, PC4, PC5 as pull-upssbis $13,4call d100sbis $13,4jmp linitsbis $13,3call d100sbic $13,3jmp help11help20 in r22,$13ori r22,$38out $15,r22 //set PC3, PC4, PC5 as pull-upsldi r17,$01call wrtcldi r16,1ldi r17,1ldi r18,' 'call displhelp21 ldi r16,2ldi r17,1ldi r18,$7fcall displldi r16,1ldi r17,2ldi r18,$02call displldi r16,1ldi r17,4ldi r18,$03call displldi r16,2ldi r17,2ldi r18,$04call displldi r16,2ldi r17,4ldi r18,$05call displldi r16,1ldi r17,5ldi r18,':'call displldi r16,1ldi r17,6ldi r18,'E'call displldi r16,1ldi r17,7ldi r18,'n'call displldi r16,1ldi r17,8ldi r18,'e'call displldi r16,1ldi r17,9ldi r18,'m'call displldi r16,1ldi r17,10ldi r18,'y'call displldi r16,2ldi r17,6ldi r18,'F'call displldi r16,2ldi r17,7ldi r18,'l'call displldi r16,2ldi r17,8ldi r18,'e'call displldi r16,2ldi r17,9ldi r18,'e'call displldi r16,2ldi r17,10ldi r18,'t'call displldi r16,2ldi r17,16ldi r18,$7ecall displsbis $13,4call d100sbis $13,4jmp linitsbis $13,5call d100sbis $13,5jmp helpsbis $13,3call d100sbic $13,3jmp help21help30 in r22,$13ori r22,$38out $15,r22 //set PC3, PC4, PC5 as pull-upsldi r17,$01call wrtcldi r16,1ldi r17,1ldi r18,' 'call displhelp31 ldi r16,2ldi r17,1ldi r18,$7fcall displldi r16,1ldi r17,2ldi r18,'L'call displldi r16,1ldi r17,3ldi r18,'i'call displldi r16,1ldi r17,4ldi r18,'v'call displldi r16,1ldi r17,5ldi r18,'e'call displldi r16,1ldi r17,6ldi r18,'s'call displldi r16,1ldi r17,7ldi r18,'='call displldi r16,1ldi r17,8ldi r18,'3'call displldi r16,2ldi r17,2ldi r18,'L'call displldi r16,2ldi r17,3ldi r18,'e'call displldi r16,2ldi r17,4ldi r18,'v'call displldi r16,2ldi r17,5ldi r18,'e'call displldi r16,2ldi r17,6ldi r18,'l'call displldi r16,2ldi r17,7ldi r18,'s'call displldi r16,2ldi r17,8ldi r18,'='call displldi r16,2ldi r17,9ldi r18,'1'call displldi r16,2ldi r17,10ldi r18,'0'call displsbis $13,4call d100sbis $13,4jmp linitsbis $13,5call d100sbic $13,5jmp help31jmp help20//----------------------------------HIGH SCORE-------------------------------------hscore in r22,$13ori r22,$38out $15,r22 //set PC3, PC4, PC5 as pull-upsldi r17,$01call wrtcldi r16,1ldi r17,1ldi r18,' 'call displhscore1 ldi r16,1ldi r17,4ldi r18,'H'call displldi r16,1ldi r17,5ldi r18,'I'call displldi r16,1ldi r17,6ldi r18,'G'call displldi r16,1ldi r17,7ldi r18,'H'call displldi r16,1ldi r17,9ldi r18,'S'call displldi r16,1ldi r17,10ldi r18,'C'call displldi r16,1ldi r17,11ldi r18,'O'call displldi r16,1ldi r17,12ldi r18,'R'call displldi r16,1ldi r17,13ldi r18,'E'call displldi r16,1ldi r17,14ldi r18,':'call displldi r16,0ldi r17,1call rdandi r25,$0fori r25,$30ldi r16,2ldi r17,7mov r18,r25call displldi r16,0ldi r17,2call rdandi r25,$0fori r25,$30ldi r16,2ldi r17,8mov r18,r25call displldi r16,0ldi r17,3call rdandi r25,$0fori r25,$30ldi r16,2ldi r17,9mov r18,r25call displldi r16,2ldi r17,14ldi r18,'r'call displldi r16,2ldi r17,15ldi r18,'s'call displldi r16,2ldi r17,16ldi r18,'t'call displsbis $13,3call d100sbis $13,3call clrhsbis $13,4call d100sbis $13,4jmp linitjmp hscore1//----------------------------------GAME--------------------------------------game ldi r25,$00ldi r22,$07ldi r20,1ldi r17,$01call wrtcldi r17,$ffsts $0400,r17ldi r17,$fasts $0401,r17ldi r17,$f2sts $0402,r17ldi r17,$fcsts $0403,r17ldi r17,$f8sts $0404,r17ldi r17,$f5sts $0405,r17ldi r17,1sts $0406,r17ldi r19,00sts $0407,r19sts $0408,r19sts $0409,r19sts $0410,r19ldi r17,$0asts $0411,r17lcd ldi r18,$02 //load obstacleldi r16,1 //load column 1lds r17,$0400 //load row from indexcpi r19,$00 //check for timer endbrne p10 //andinc r17 //increase indexp10 call dspl //display element at the locationcpi r17,16brne q10call checkq10 cpi r17,17 //ffbrne o10 //check if user is in the same columnldi r17,$ffcpi r22,07breq o10ldi r17,$f9cpi r22,03breq o10ldi r17,$f3o10 sts $0400,r17ldi r18,$00lds r16,$0406lds r17,$0401mov r23,r16mov r24,r16cpi r19,$00 //speedbrne p11inc r17p11 call dsplcpi r17,16brne q11call check1q11 cpi r17,18 //f8brne o11ldi r17,$fdcpi r22,07breq s11ldi r17,$f5cpi r22,03breq s11ldi r17,$f2s11 ldi r24,1cpi r23,1brne o11ldi r24,2o11 sts $0406,r24sts $0401,r17ldi r18,$03ldi r16,1lds r17,$0402cpi r19,$00 //speedbrne p12inc r17p12 call dsplcpi r17,16brne q12call checkq12 cpi r17,17 //f1brne o12ldi r17,$fccpi r22,07breq o12ldi r17,$f6cpi r22,03breq o12ldi r17,$f0o12 sts $0402,r17ldi r18,$04ldi r16,2lds r17,$0403cpi r19,$00 //speedbrne p20inc r17p20 call dsplcpi r17,16brne q20call checkq20 cpi r17,17brne o20ldi r17,$fecpi r22,07breq o20ldi r17,$f8cpi r22,03breq o20ldi r17,$f4 //fao20 sts $0403,r17ldi r18,$05ldi r16,2lds r17,$0405cpi r19,$00 //speedbrne p22inc r17p22 call dsplcpi r17,16brne q22call checkq22 cpi r17,17brne o22ldi r17,$facpi r22,07breq o22ldi r17,$f7cpi r22,03breq o22ldi r17,$f1o22 sts $0405,r17//-----------------------------------------------------------------------------//show player carldi r18,$01ldi r17,16//switch operationspush r21in r21,$13ori r21,$38out $15,r21 //set PC3, PC4, PC5 as pull-upssbic $13,3 //check for switch 3 pressjmp b1ldi r20,1ldi r16,2ldi r17,16call clerb1 sbic $13,5 //check for switch 5 pressjmp b2ldi r20,2ldi r16,1ldi r17,16call clerb2 mov r16,r20call displsbis $13,4call d100sbis $13,4call psestr//display lives left on ledsin r21,$13andi r21,$f8or r21,r22out $15,r21pop r21//set speed of moving obstaclesinc r19lds r17,$0411cp r19,r17brne lldi r19,$00lds r24,$0407inc r24sts $0407,r24lds r17,$0410cpi r17,$04brlo hspeedcpi r24,$02brne ljmp espeedhspeed cpi r24,$01brne lespeed ldi r24,$00sts $0407,r24lds r25,$0408inc r25sts $0408,r25cpi r25,$0abrne lldi r25,$00sts $0408,r25lds r25,$0409inc r25sts $0409,r25cpi r25,$0abrne lldi r25,$00sts $0409,r25lds r25,$0410inc r25sts $0410,r25call levell lds r25,$0410andi r25,$0fori r25,$30ldi r16,2ldi r17,1mov r18,r25call displlds r25,$0409andi r25,$0fori r25,$30ldi r16,2ldi r17,2mov r18,r25call displlds r25,$0408andi r25,$0fori r25,$30ldi r16,2ldi r17,3mov r18,r25call displjmp lcd//----------------------------------Level--------------------------------------level ldi r17,$01call wrtcldi r16,1ldi r17,1ldi r18,' 'call displlds r17,$0411dec r17sts $0411,r17level1 ldi r16,2ldi r17,5ldi r18,'L'call displldi r16,2ldi r17,6ldi r18,'E'call displldi r16,2ldi r17,7ldi r18,'V'call displldi r16,2ldi r17,8ldi r18,'E'call displldi r16,2ldi r17,9ldi r18,'L'call displldi r16,2ldi r17,10ldi r18,':'call displlds r25,$0410andi r25,$0fori r25,$30ldi r16,2ldi r17,11mov r18,r25call displldi r16,2ldi r17,12ldi r18,'/'call displldi r16,2ldi r17,13ldi r18,'1'call displldi r16,2ldi r17,14ldi r18,'0'call displldi r16,1ldi r17,5ldi r18,'S'call displldi r16,1ldi r17,6ldi r18,'C'call displldi r16,1ldi r17,7ldi r18,'O'call displldi r16,1ldi r17,8ldi r18,'R'call displldi r16,1ldi r17,9ldi r18,'E'call displldi r16,1ldi r17,10ldi r18,':'call displlds r25,$0410andi r25,$0fori r25,$30ldi r16,1ldi r17,11mov r18,r25call displldi r16,1ldi r17,12ldi r18,'0'call displldi r16,1ldi r17,13ldi r18,'0'call displsbis $13,4call d100sbic $13,4jmp level1level2 ldi r17,$01call wrtcldi r16,1ldi r17,1ldi r18,' 'call displret//----------------------------------Pause--------------------------------------psestr ldi r17,$01call wrtcldi r16,1ldi r17,1ldi r18,' 'call displpush r22in r22,$13ori r22,$38out $15,r22 //set PC3, PC4, PC5 as pull-upspop r22pause ldi r16,1ldi r17,4ldi r18,'G'call displldi r16,1ldi r17,5ldi r18,'A'call displldi r16,1ldi r17,6ldi r18,'M'call displldi r16,1ldi r17,7ldi r18,'E'call displldi r16,1ldi r17,9ldi r18,'P'call displldi r16,1ldi r17,10ldi r18,'A'call displldi r16,1ldi r17,11ldi r18,'U'call displldi r16,1ldi r17,12ldi r18,'S'call displldi r16,1ldi r17,13ldi r18,'E'call displldi r16,1ldi r17,14ldi r18,'D'call displldi r16,2ldi r17,1ldi r18,'q'call displldi r16,2ldi r17,2ldi r18,'u'call displldi r16,2ldi r17,3ldi r18,'i'call displldi r16,2ldi r17,4ldi r18,'t'call displldi r16,2ldi r17,6ldi r18,'r'call displldi r16,2ldi r17,7ldi r18,'s'call displldi r16,2ldi r17,8ldi r18,'u'call displldi r16,2ldi r17,9ldi r18,'m'call displldi r16,2ldi r17,10ldi r18,'e'call displldi r16,2ldi r17,12ldi r18,'r'call displldi r16,2ldi r17,13ldi r18,'s'call displldi r16,2ldi r17,14ldi r18,'t'call displldi r16,2ldi r17,15ldi r18,'r'call displldi r16,2ldi r17,16ldi r18,'t'call displepause sbis $13,3jmp gamesbis $13,5jmp ggsbis $13,4call d100sbic $13,4jmp epseldi r17,$01call wrtcldi r16,1ldi r17,1ldi r18,' 'call displretepse jmp pause//-----------------------------------------------------------------------------check cp r20,r16brne crlsr r22tst r22breq ggldi r17,$facr ret//--------------------------display GAME OVER----------------------------------gg ldi r21,$00out $15,r21ldi r17,$01call wrtcldi r16,1ldi r17,1ldi r18,' 'call displpush r22in r22,$13ori r22,$38out $15,r22 //set PC3, PC4, PC5 as pull-upspop r22gg1 ldi r16,1ldi r17,7ldi r18,'G'call displldi r16,1ldi r17,8ldi r18,'A'call displldi r16,1ldi r17,9ldi r18,'M'call displldi r16,1ldi r17,10ldi r18,'E'call displldi r16,2ldi r17,7ldi r18,'O'call displldi r16,2ldi r17,8ldi r18,'V'call displldi r16,2ldi r17,9ldi r18,'E'call displldi r16,2ldi r17,10ldi r18,'R'call displsbis $13,4call d100sbic $13,4jmp gg1ldi r17,$01call wrtcldi r16,1ldi r17,1ldi r18,' 'call displ//-----------------------------------------------Score-------------------------------------------------scrs ldi r16,0ldi r17,1call rdlds r24,$0410cp r25,r24breq scrs1brge scrcall storescrs1 ldi r16,0ldi r17,2call rdlds r24,$0409cp r25,r24breq scrs2brge scrcall store1scrs2 ldi r16,0ldi r17,3call rdlds r24,$0408cp r25,r24brge scrmov r25,r24ldi r16,0ldi r17,3call wrtscr ldi r16,1ldi r17,5ldi r18,'S'call displldi r16,1ldi r17,6ldi r18,'C'call displldi r16,1ldi r17,7ldi r18,'O'call displldi r16,1ldi r17,8ldi r18,'R'call displldi r16,1ldi r17,9ldi r18,'E'call displldi r16,1ldi r17,10ldi r18,':'call displlds r25,$0410andi r25,$0fori r25,$30ldi r16,1ldi r17,11mov r18,r25call displlds r25,$0409andi r25,$0fori r25,$30ldi r16,1ldi r17,12mov r18,r25call displlds r25,$0408andi r25,$0fori r25,$30ldi r16,1ldi r17,13mov r18,r25call displldi r16,2ldi r17,2ldi r18,'H'call displldi r16,2ldi r17,3ldi r18,'I'call displldi r16,2ldi r17,4ldi r18,'G'call displldi r16,2ldi r17,5ldi r18,'H'call displldi r16,2ldi r17,7ldi r18,'S'call displldi r16,2ldi r17,8ldi r18,'C'call displldi r16,2ldi r17,9ldi r18,'O'call displldi r16,2ldi r17,10ldi r18,'R'call displldi r16,2ldi r17,11ldi r18,'E'call displldi r16,2ldi r17,12ldi r18,':'call displldi r16,0ldi r17,1call rdandi r25,$0fori r25,$30ldi r16,2ldi r17,13mov r18,r25call displldi r16,0ldi r17,2call rdandi r25,$0fori r25,$30ldi r16,2ldi r17,14mov r18,r25call displldi r16,0ldi r17,3call rdandi r25,$0fori r25,$30ldi r16,2ldi r17,15mov r18,r25call displsbis $13,4call d100sbic $13,4jmp scrldi r17,$01call wrtcldi r16,1ldi r17,1ldi r18,' 'call displjmp linit//-----------------------------------------------------------------------------//-------------------------------FUNCTIONS-------------------------------------store lds r25,$0410ldi r16,0ldi r17,1call wrtstore1 lds r25,$0409ldi r16,0ldi r17,2call wrtlds r25,$0408ldi r16,0ldi r17,3call wrtjmp scrclrh ldi r25,0ldi r16,0ldi r17,1call wrtldi r16,0ldi r17,2call wrtldi r16,0ldi r17,3call wrtretwrt sbic $1c,1jmp wrtout $1f, r16out $1e, r17out $1d,r25sbi $1c,2sbi $1c,1retrd sbic $1c,1jmp rdout $1f, r16out $1e, r17out $1d,r25sbi $1c,0in r25,$1dretcheck1 cp r20,r16brne cr1cpi r22,04brge cr1lsl r22inc r22ldi r17,$facr1 ret//--------------------------code for displays----------------------------------//lcd display//(input:r16-row,r17-column,r18-character,output:0,uses:r17,r19,r20)dspl push r17push r19push r20cpi r17,18brge dsplecpi r17,01brlo dspledec r17 //position cursorldi r19,$80 //set command for row 1cpi r16,1 //check for row 1breq dspl1cpi r17,03brlo dspleldi r19,$c0 //set command for row 2dspl1 add r17,r19 //combine row and column commandcall wrtc //send commandsbi $18,2 //Set LCD in data mode (PB2 HIGH)out $1b,r18 //Load data to PORTAsbi $18,0 //Enable LCD (PB0 HIGH)cbi $18,0 //Disable LCD (PB0 LOW)call d1cpi r17,01brlo dspledspl2 dec r17call wrtc //send commandldi r18,' 'sbi $18,2 //Set LCD in data mode (PB2 HIGH)out $1b,r18 //Load data to PORTAsbi $18,0 //Enable LCD (PB0 HIGH)cbi $18,0 //Disable LCD (PB0 LOW)dsple pop r20pop r19pop r17call d1 //delay 1 secretdpl push r17push r19push r20dec r17 //position cursorldi r19,$80 //set command for row 1ldi r20,1cpse r16,r20 //check for row 1ldi r19,$c0 //set command for row 2add r17,r19 //combine row and column commandcall wrtc //send commandsbi $18,2 //Set LCD in data mode (PB2 HIGH)out $1b,r18 //Load data to PORTAsbi $18,0 //Enable LCD (PB0 HIGH)cbi $18,0 //Disable LCD (PB0 LOW)inc r17call wrtc //send commandldi r18,' 'sbi $18,2 //Set LCD in data mode (PB2 HIGH)out $1b,r18 //Load data to PORTAsbi $18,0 //Enable LCD (PB0 HIGH)cbi $18,0 //Disable LCD (PB0 LOW)pop r20pop r19pop r17call d1 //delay 1 secretcler push r17push r19push r20ldi r18,' 'ldi r17,16dec r17 //position cursorldi r19,$80 //set command for row 1ldi r20,1cpse r16,r20 //check for row 1ldi r19,$c0 //set command for row 2add r17,r19 //combine row and column commandcall wrtc //send commandsbi $18,2 //Set LCD in data mode (PB2 HIGH)out $1b,r18 //Load data to PORTAsbi $18,0 //Enable LCD (PB0 HIGH)cbi $18,0 //Disable LCD (PB0 LOW)pop r20pop r19pop r17call d1 //delay 1 secretdispl push r17push r19push r20dec r17 //position cursorldi r19,$80 //set command for row 1ldi r20,1cpse r16,r20 //check for row 1ldi r19,$c0 //set command for row 2add r17,r19 //combine row and column commandcall wrtc //send commandsbi $18,2 //Set LCD in data mode (PB2 HIGH)out $1b,r18 //Load data to PORTAsbi $18,0 //Enable LCD (PB0 HIGH)cbi $18,0 //Disable LCD (PB0 LOW)pop r20pop r19pop r17call d1 //delay 1 secret//-------------------------write command block---------------------------------//(input:r17,output:0,uses:0)wrtc cbi $18,2 // Set LCD in command mode (PB2 LOW)out $1b,r17 // Load data to PORTAsbi $18,0 //Enable LCD (PB0 HIGH)cbi $18,0 //Disable LCD (PB0 LOW)call d1ret//---------------------------write data block----------------------------------wrtd sbi $18,2 //Set LCD in data mode (PB2 HIGH)out $1b,r18 //Load data to PORTAsbi $18,0 //Enable LCD (PB0 HIGH)cbi $18,0 //Disable LCD (PB0 LOW)ret//-------------------------------delays----------------------------------------//delay cycle 1ms//(input:0,output:0,uses:r24,r25)d1 push r24push r25ldi r25,$0d //initialise r25 for outer loopolpo ser r24 //initialise r24 for inner loopolpi dec r24breq oextijmp olpioexti dec r25 //exit inner loopbreq oextojmp olpooexto pop r25 //exit outer looppop r24ret//delay cycle 10ms//(input:0,output:0,uses:r24,r25)d10 push r24push r25ldi r25,$7e //initialise r25 for outer looptlpo ser r24 //initialise r24 for inner looptlpi dec r24breq textijmp tlpitexti dec r25 //exit inner loopbreq textojmp tlpotexto pop r25 //exit outer looppop r24ret//delay cycle 100ms//(input:0,output:0,uses:r23,r24,r25)d100 push r23push r24push r25ldi r23,$05 //initialose r23 for outer loophlpo ldi r25,$fc //initialise r25 for penultimate loophlpp ldi r24,$fe //initialise r24 for inner loophlpi dec r24breq hextijmp hlpihexti dec r25 //exit inner loopbreq hextpjmp hlpphextp dec r23 //exit penultimate loopbreq hextojmp hlpohexto pop r25 //exit outer looppop r24pop r23retEND main###
Circuit Diagrams
Project Video
Filed Under: Electronic Projects
Filed Under: Electronic Projects
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.