What am i doing wrong in this code? (LED Cube)

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

 

So im trying to make a small 4x4x4 led cube using assembly on atmel.

I have connected (+ve) pins for rows of my cube to Analog pins 5-2

The (-ve)column pins are connected to d0-d13  and 2 are connected to analog pins 0,1

 

In C if i want to make the all leds glow i set the rows array to 1 and columns to 0 

I want to make this happen using assembly

start:
ser    r16                     //set all pins to 1
out    DDRC, r16
out PORTC, r16             //set all analog pins to 1  



clr r16
out ddrb,r16              //set portb , portd pins to 0  as in input 
out ddrd,r16
clr r16
out portb,r16
out portd,r16>"



rjmp start

 

im aware im setting all analog pins to 1 despite when two columns are connected to it but still it should at least light up the remaining columns.

I debugged it and it is setting analog pins to 1

But no leds are lighting up?

What am i missing any help apreciated

 

 

This topic has a solution.
Last Edited: Thu. Nov 21, 2019 - 04:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Show a schematic.

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


I don't have a schematic ;i have connected the wires of cube by following a guide

This is all i have that i used as reference to connect the wires

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

A schematic (aka "circuit diagram") is a far more effective way to describe your electronics than trying to use words!

 

How have you tested your hardware to prove that it is actually working?

 

methlab wrote:
In C if i want to make the all leds glow i set the rows array to 1 and columns to 0 

So have you tried that?

 

Did it work?

 

How to properly post source code - see Tip #1.

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

methlab wrote:
I don't have a schematic

Then now is the time to draw one!

 

And how about posting a link to that "guide" ?

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: Wed. Nov 20, 2019 - 03:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

http://technoreview85.blogspot.c...

i just followed the video and  made the cube and connected all the wires, the code is in C but i want to write it in assembly i check turn everything on function and it sets all columns to 0 (input) and rows to 1(output) im doing that exactly in the code but its not working or maybe im doing something wrong 

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

Yes, i have tried the C code to see if i made the connections properly and it is working but a few LEDS died because of my bad soldering probably but yes most of the LEDS do light up

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

Again, how have you checked that your hardware is actually working?

 

have you checked that the 'C' code works?

 

Obviously, if the hardware itself is not working - your assembler code cannot work!

 

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


I ran the C code the was given with the guide and it does work

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

It sounds like you really need to start with something simpler!

 

Get the basics first - then more on to more complicated stuff.

 

Start with a simple program to blink a single LED

 

Then move on to multiple LEDs on a single port

 

Then move on to multiple LEDs on  multiple  ports

 

Then draw a proper schematic of a cube - maybe start with 3 x 3

 

Then think about how the code needs to work to drive 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...
Last Edited: Wed. Nov 20, 2019 - 03:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I figured it out i added a delay function and its now blinking my code was working fine its just that it was blinking way too fast for me to see! I will look further into it and see if i can complete this

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

awneil wrote:

It sounds like you really need to start with something simpler!

 

Get the basics first - then more on to more complicated stuff.

 

Start with a simple program to blink a single LED

 

Then move on to multiple LEDs on a single port

 

Then move on to multiple LEDs on  multiple  ports

 

Then draw a proper schematic of a cube - maybe start with 3 x 3

 

Then think about how the code needs to work to drive that ...

 

 

I actually did try making single LED blink in assembly but then i thought if i can do it in C easily i can probably do it in assembly too and I have NEVER been so wrong

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

LOL! Same story here: https://www.avrfreaks.net/commen... - when learning a new skill, it always pays to start simple!

 

Let's start at the very beginning
A very good place to start ...

https://www.youtube.com/watch?v=1RW3nDRmu6k

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

awneil wrote:

LOL! Same story here: https://www.avrfreaks.net/commen... - when learning a new skill, it always pays to start simple!

 

Let's start at the very beginning
A very good place to start ...

https://www.youtube.com/watch?v=1RW3nDRmu6k

if i were to do inline assembly bby using _asm directive  can we do that in arduino ide?

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

How on earth would that help?!

 

surprise

 

You would still need to know all about how to write AVR assembly code plus you'd be adding the extra complications of doing it inline!

 

Again, start simple; start with the basics; lay foundations first - then build the fancy stuff on top once you've got something solid as a base!

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

awneil wrote:

How on earth would that help?!

 

surprise

 

You would still need to know all about how to write AVR assembly code plus you'd be adding the extra complications of doing it inline!

 

Again, start simple; start with the basics; lay foundations first - then build the fancy stuff on top once you've got something solid as a base!

Update so i have been working on it and i managed to lite up nearly all LEDS 1by 1 for every row and column besides the ones that are connected to the analog pins 4 and 5

;
; LED Cube.asm
;
; Created: 11/20/2019 6:50:39 PM
; Author : Anas
;
.device ATmega328P
.include "./m328Pdef.inc"

; Replace with your application code
start:
sbr r16,8    //set row
out    DDRC, r16
out portc,r16

ldi r20,0B00100000    //setting column
out ddrc,r20
call delay1s        //1second delay function

rjmp turnalloff    //turning all LED off
rjmp start

turnalloff:

call delay1s
clr r16
out ddrc,r16
out ddrb,r16
out ddrd,r16
ret

delay1s:
       ldi  r18, 51
    ldi  r19, 187
    ldi  r20, 224
L1: dec  r20
    brne L1
    dec  r19
    brne L1
    dec  r18
    brne L1
    rjmp PC+1
    ret

Here is the code it should work like it did for othre pins on portb and portd 

any idea how can i run it?

Last Edited: Thu. Nov 21, 2019 - 02:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

methlab wrote:
Update so i have been working on it and i managed to lite up all LEDS 1by 1 for every row and column
methlab wrote:
any idea how can i run it?

I don't get it, if you have seen it light the LEDs then surely you already have it running ?!?

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

clawson wrote:

methlab wrote:
Update so i have been working on it and i managed to lite up all LEDS 1by 1 for every row and column
methlab wrote:
any idea how can i run it?

I don't get it, if you have seen it light the LEDs then surely you already have it running ?!?

not all i cant manage too light up the columns connected to analog pins 4 and 5 

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

 

Note that there's no need to quote the entire post - it just clogs up the thread!

 

Either just pick out enough to give context, or use the 'Reply' button - so the Forum will fill-in which post you're replying to:

 

 

 

methlab wrote:
 I can't manage to light up the columns connected to analog pins 4 and 5 

Are you sure the LEDs connected to those pins are actually working ... ?

 

EDIT

 

and, if you're using an Arduino, have you checked that there's nothing on the Arduino board to "interfere" with driving LEDs on those pins ... ?

 

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. Nov 21, 2019 - 02:50 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah LEDS are working fine it was just that i was over writeing the port value if i want to light up the columns i had to add the row value + column pin to get it to work so the respective bits are on i.e 00101000 now it is working.

 

Last Edited: Thu. Nov 21, 2019 - 03:27 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

methlab wrote:
now it is working.

Jolly good.

 

Now see Tip #5.

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

awneil wrote:
the extra complications of doing it inline!

 

See: https://www.avrfreaks.net/commen...

 

You really don't want to do that!

 

surprise

 

https://www.avrfreaks.net/commen...

 

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...