Simple LED remembering game with ATMEGA8515 and hapsim

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

hey anyone here can make a simple LED remember game using ATmega 8515 and hapsim?

hope u can write the code or send me the code 

im in college atm, and still learning :D

thx

 

 

edit, this is what my progress just need to know how to check the users answer is right or wrong then its done !:

;Simple Remembering LED's

;Machine : atmega8515

;

;LCD:

; EN, RS, RW : PORTA

; DB    : PORTB

;LED : PORTC

;BUTTONS : PORTD

;

;External Iterrupts:

;Timer Overflow0

;Buttons PIND 2,3

;####################################################

;Notes:

;Unstructured code organised for branch relative jump availability

.include "m8515def.inc"

.def temp = r16

.def PB = r17

.def led = r18

.def A  = r19

.def difficulty = r20

.def fallingEdge = r21

.def warna = r22

.def random = r23

.def move = r24

.def state = r25 ;state = 0 game done/not started, state = 1 player turn, state = 2 AI turn

 

.org $00

rjmp RESET

.org $01

rjmp ext_int1

.org $07

RESET:

;Init Stack Pointer

ldi XL, $60

ldi XH, $00

ldi temp, low(RAMEND)

out SPL, temp

ldi temp, high(RAMEND)

out SPH, temp

;----LED-----

ldi temp, $ff

out DDRC, temp

ldi temp, $01

out PORTC, temp

 

;----BUTTONS----

ldi temp, $f0

out DDRD, temp

 

;-----LCD-----

rcall INIT_LCD

ser temp

out DDRA, temp

out DDRB, temp

 

ldi ZH, high(2*message) ;Load early message

ldi ZL, low(2*message)

rcall WRITE_TEXT

 

inc ZL

rcall WRITE_TEXT

 

BUTTON_LISTENER:

;Early stage button listener

rcall READ_BUTTON

in led, PORTC

cpi temp, 0b00000010

breq PLUS_ONE

cpi temp, 0b00000001

breq MIN_ONE

cpi temp, 0b00000100

breq START_GAME

cpi temp, 0b00001000

breq QUIT_GAME

 

READ_BUTTON:

;Read button, will return when falling edge

in temp, PIND

cp temp, fallingEdge

breq READ_BUTTON

tst temp

breq DONE_READ_BUTTON

mov fallingEdge, temp

rjmp READ_BUTTON

 

DONE_READ_BUTTON:

;falling edge triggered return button value in temp

mov temp, fallingEdge

ldi fallingEdge, 0

ret

 

PLUS_ONE:

;move led up

cpi led, 0b00000100

breq IF_MAX

lsl led

rcall WAIT_LCD

out PORTC, led

rjmp BUTTON_LISTENER

 

MIN_ONE:

;move led down

cpi led, 0b00000001

breq IF_MAX

lsr led

rcall WAIT_LCD

out PORTC, led

rjmp BUTTON_LISTENER

 

IF_MAX:

;overflow blocking

out PORTC, led

rjmp BUTTON_LISTENER

;--QUIT--

WRITE_QUIT_MESSAGE:

;write quite message to lcd

ldi ZH, high(2*message_quit)

ldi ZL, low(2*message_quit)

rcall WRITE_TEXT

ret

QUIT_GAME:

;quitting game

rcall WRITE_QUIT_MESSAGE

rjmp forever

 

;---GAME---

 

BUTTON_LISTENER2:

;button listener for mid game

rcall READ_BUTTON

cpi temp, 1

breq UP

cpi temp, 2

breq DOWN

rjmp BUTTON_LISTENER2

 

UP:

;move led up

in temp, PORTC

cpi temp, 0b00001000

breq DONE2

lsr temp

out PORTC, temp

ret

 

DOWN:

;move led down

in temp, PORTC

cpi temp, 0b10000000

breq DONE2

lsl temp

out PORTC, temp

ret

 

DONE2:

ret

 

WIN:

;write win message to lcd

ldi ZH, high(2*message_menang)

ldi ZL, low(2*message_menang)

rcall WRITE_TEXT

rjmp forever

 

LOSE:

;write lose message to lcd

ldi ZH, high(2*message_kalah)

ldi ZL, low(2*message_kalah)

rcall WRITE_TEXT

rjmp forever

 

 

 

START_GAME:

;---INIT GAME---

;init difficulty

ldi difficulty, 0

cpi led, 0b00000001

breq INIT_LED

 

ldi difficulty, 1

cpi led, 0b00000010

breq INIT_LED

 

ldi difficulty, 2

 

INIT_LED:

ldi ZH, high(2*message_liatled)

ldi ZL, low(2*message_liatled)

rcall WRITE_TEXT

cpi difficulty, 0

breq DEC_LED_TIME_EASY

 

cpi difficulty, 1

breq DEC_LED_TIME_MEDIUM

 

cpi difficulty,2

breq DEC_LED_TIME_HARD

 

DEC_LED_TIME_EASY:

ldi temp, 0b00000011

out PORTE, temp

rcall DELAY_01

ldi temp, 0b00000011

out PORTE, temp

rcall DELAY_02

ldi temp, 0b00000000

out PORTE, temp

rcall DELAY_01

ldi temp, 0b00001100

out PORTE, temp

rcall DELAY_02

ldi temp, 0b00001100

out PORTE, temp

rcall DELAY_01

ldi temp, 0b00000000

out PORTE, temp

rcall DELAY_02

ldi temp, 0b11000000

out PORTE, temp

rcall DELAY_01

ldi temp, 0b11000000

out PORTE, temp

rcall DELAY_02

ldi temp, 0b00000000

out PORTE, temp

rcall DELAY_01

rjmp write_jawabanya

DEC_LED_TIME_MEDIUM:

ldi temp, 0b00000011

out PORTE, temp

rcall DELAY_01

ldi temp, 0b00000000

out PORTE, temp

rcall DELAY_01

ldi temp, 0b00001100

out PORTE, temp

rcall DELAY_02

ldi temp, 0b11000000

out PORTE, temp

rcall DELAY_02

ldi temp, 0b00000000

out PORTE, temp

rcall DELAY_01

rcall write_jawabanya

 

DEC_LED_TIME_HARD:

ldi temp, 0b00000011

out PORTE, temp

rcall DELAY_01

ldi temp, 0b00001100

out PORTE, temp

rcall DELAY_01

ldi temp, 0b11000000

out PORTE, temp

rcall DELAY_01

rjmp write_jawabanya

 

DELAY_01:

    ldi  r18, 52

    ldi  r19, 242

L1: dec  r19

    brne L1

    dec  r18

    brne L1

    nop

ret

 

 

DELAY_02:

    ldi  r18, 208

    ldi  r19, 202

L2: dec  r19

    brne L2

    dec  r18

    brne L2

L3: dec  r19

    brne L3

    dec  r18

    brne L3

    nop

ret

 

 

 

write_jawabanya:

ldi ZH, high(2*message_jawabanya)

ldi ZL, low(2*message_jawabanya)

rcall WRITE_TEXT

ldi temp, 0b00001000

out PORTC, temp

ldi temp, 0b00001000

out PORTC, temp

ldi r17,0b00001010

out MCUCR,r17

ldi r17,0b11000000

out GICR,r17

 

sei

 

 

done_led:

cpi state, 2

breq PROSES

rjmp done_led

PROSES:

rcall PLAYER_MOVE

rcall BUTTON_LISTENER2

cpi move,0

breq TRUE1

rjmp FALSE

TRUE1:

ldi ZH, high(2*message_benar)

ldi ZL, low(2*message_benar)

rcall WRITE_TEXT

rcall PLAYER_MOVE

rcall BUTTON_LISTENER2

cpi move,1

breq TRUE2

rjmp false

 

TRUE2:

ldi ZH, high(2*message_benar)

ldi ZL, low(2*message_benar)

rcall WRITE_TEXT

 

rcall PLAYER_MOVE

rcall BUTTON_LISTENER2

cpi move,3

breq TRUE1

rjmp false

 

FALSE:

ldi ZH, high(2*message_salah)

ldi ZL, low(2*message_salah)

rcall WRITE_TEXT

 

ext_int0:

;ENTER button triggered, player attempt for a move

cpi state, 0

breq forever

push temp

in temp, SREG

push temp

cpi state, 1

brne INTERRUPT_DONE

;attempt is valid, will process move

;state change to 2

rjmp INTERRUPT_DONE

 

forever:

;END OF PROGRAM

ldi state, 0

rjmp forever

 

ext_int1:

ldi state, 0

rcall WRITE_QUIT_MESSAGE

reti

 

INTERRUPT_DONE:

;DONE module for enter button, retrieve states

pop temp

out SREG, temp

pop temp

ldi state, 2

reti

 

PLAYER_MOVE:

;Process Player move

in temp, PORTC

ldi move, 1

cpi temp, 0b00001000

breq DONE

 

ldi move, 2

cpi temp, 0b00010000

breq DONE

 

ldi move, 3

cpi temp, 0b00100000

breq DONE

 

ldi move, 4

cpi temp, 0b01000000

breq DONE

 

ldi move, 5

breq DONE

 

DONE:

ret

 

 

;---API---

 

WRITE_TEXT:

;Write text to lcd

rcall WAIT_LCD

rcall CLEAR_LCD

WRITING:

lpm

tst r0 ; Check if we've reached the end of the message

breq DONE_WRITING

mov A, r0

rcall WRITE_CHAR

inc ZL

rjmp WRITING

DONE_WRITING:

ret

 

DELAY:

WAIT_LCD:

;delaying module

;Preserve register values

push r20

push r21

push r22

 

ldi r20, 1

ldi r21, 50

ldi r22, 50

CONT: dec r22

brne CONT

dec r21

brne CONT

dec r20

brne CONT

 

pop r22

pop r21

pop r20

 

ret

 

INIT_LCD:

//Setting 1

cbi PORTA,1 ; CLR RS

ldi PB,0x38 ; MOV DATA,0x38 --> 8bit, 2line, 5x8

out PORTB,PB

sbi PORTA,0 ; SETB EN

cbi PORTA,0 ; CLR EN

rcall WAIT_LCD

 

//Setting 2

cbi PORTA,1 ; CLR RS

ldi PB,$0E ; MOV DATA,0x0E --> disp ON, cursor ON, blink OFF

out PORTB,PB

 

sbi PORTA,0 ; SETB EN

cbi PORTA,0 ; CLR EN

rcall WAIT_LCD

 

rcall CLEAR_LCD ; CLEAR LCD

 

// Setting 3

cbi PORTA,1 ; CLR RS

ldi PB,$06; MOV DATA,0x06 --> increase cursor, display sroll OFF

out PORTB,PB

 

sbi PORTA,0 ; SETB EN

cbi PORTA,0 ; CLR EN

rcall WAIT_LCD

ret

 

CLEAR_LCD:

cbi PORTA,1 ; CLR RS

ldi PB,$01 ; MOV DATA,0x01

out PORTB,PB

 

sbi PORTA,0 ; SETB EN

cbi PORTA,0 ; CLR EN

rcall WAIT_LCD

ret

 

 

WRITE_CHAR:

sbi PORTA,1 ; SETB RS

out PORTB, A

 

sbi PORTA,0 ; SETB EN

cbi PORTA,0 ; CLR EN

rcall WAIT_LCD

ret

 

message:

.db "This is remember me aye!"

.db 0,"Choose dificulty!"

.db 0

 

 

message_benar:

.db "right,next?"

.db 0

 

message_salah:

.db "you lose, thx for playing"

.db 0

 

message_menang:

.db "WIN"

.db 0

 

message_kalah:

.db "LOSE"

.db 0

 

message_liatled:

.db "LOOK AND REMEBER THE LED!"

.db 0

 

message_jawabanya:

.db "ANSWER:"

.db 0

 

message_quit:

.db "THANK YOU"

.db 0

Last Edited: Thu. Dec 28, 2017 - 09:18 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, people are not going to do your homework for you!

 

You wouldn't learn much from that!

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Some simple googling came up with this complete project.

 

https://create.arduino.cc/projec...

 

 

Mission: Improving the readiness of hams world wide : flinthillsradioinc.com

Interests: Ham Radio, Solar power, futures & currency trading - whats yours?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

iskarimrezki wrote:
simple LED remember game

You mean something like this:

 

The game is a circular disc divided into four quarter circle buttons each with a different color. In the center are the game mode controls

https://en.wikipedia.org/wiki/Simon_(game)

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

Some simple googling came up with this complete project.

 

https://create.arduino.cc/projec...

 

 

 

Great. That way the OP even saved the enormous hassle of googling for a solution...

Einstein was right: "Two things are unlimited: the universe and the human stupidity. But i'm not quite sure about the former..."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

iskarimrezki wrote:
simple LED remember game

You mean something like this:

 

The game is a circular disc divided into four quarter circle buttons each with a different color. In the center are the game mode controls

https://en.wikipedia.org/wiki/Simon_(game)

 

That's what I thought of!

 

277,232,917 -1 The largest known Mersenne Prime

Measure twice, cry, go back to the hardware store

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

iskarimrezki wrote:
hope u can write the code or send me the code  im in college atm, and still learning

Sure. 

 

Hope you can send me the money for it first

I'm still in reality and need to bring home the bacon.

 

Seriously: No, you're not "still learning". Learning is done mainly by doing stuff yourself. The one learning you seem to have learned so far is how to cheat.

 


 

Not the first time we've seen this approach, so something is terribly wrong with humanity, one way or the other:

 

Either this approach to problem solving does not work, but there are a lot of idiots out there that think it will.

 

Or this approach actually works.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

this is not a homework, just some random project to learning something, and yes thanks for the reply have a good day sir

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thx for the advice, have a good day sir :D

and now im close to my simple game and stuck in how i check the users answers :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

iskarimrezki wrote:
im close to my simple game

Excellect - well done.

 

iskarimrezki wrote:
stuck in how i check the users answers :)

If you want help with that, you're going to have to give more details of what you've done, and where you're stuck.

 

EDIT

 

Oh - you've now edited the original post to add your code.

 

Please don't do that: it makes a nonsense of the flow of the thread - especially as replies relate specifically to the original post!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. Dec 28, 2017 - 02:04 PM