NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Understanding Array Code

December 27, 2009
by Electromech
Electromech's Avatar

Hey Guys..I have a quick question on the Array testing code.."ledarray.c". When we are initially setting the ledarray_set_columndriver why are we flipping the states of DDRB & C & D instead of "just" PORT B, C or D to turn the LED off.

The kit has been great. Ive dabbled in C but not to this extent and it has a definite learning curve dealing with the MCU. For alot of the newbies out there like me there are alot of great tuts on YouTube to get a decent explanation of C and C++.

I will have a ton more questions trying to understand these arrays as we move forward o thanks in advance for the help.

One last thing, after reading the chip manual, it came clear of the relationship of DDRB, PORTB, PINB || DDRC, PORTC, PINC etc.. just to help anyone out who looks at the code for the code for the first time.

Electromech

December 27, 2009
by mcai8sh4
mcai8sh4's Avatar

Hi Electromech - whist it seems like a very steep learning curve initially, suddenly the basics just 'seem to make sense'.

Regarding the DDRx and PORTx in the ledarray thing - the code actually makes use of THREE states that a pin can be in, high/low (controlled by PORTx) and ouput/input (controlled by DDRx). If you set a pin to input, it acts as high impedence (ie neither high or low) and therefor 'off'.... I think. I'm sure someone who knows properly will be able to explain, I'm just learning myself.

Have fun, any further questions, shout out!

Regards,

Steve

December 28, 2009
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Electromech,

mcai8sh4 is right. We need to use the PORTX register to turn the pin into an input pin so it is in high impedance mode and does not let any current through. This comes from the fact that we have both a forward and a backward LED on each column. If were to merely turn the pin "low" or "high" to turn the LED off the other LED which is wired in the opposite direction on the same wire would turn on. In order to make sure both LEDs stay off, we need to use the high impedance mode on the pin. Hope that makes sense.

Humberto

December 29, 2009
by Electromech
Electromech's Avatar

Question Two::

Before I start thanks for the previous answers guys. The more you start looking at the code and seeing other examples across the net, everything starts to make sense. Not quite there but getting closer than last week.

So far to this point I have everything tested and working. I got the inital LED Test to work. I got the static test message to work, even changed the static message a couple of times. The problem I am having now is the scrolling text. Once I initialte the serial-comm.py I immediatley get an "N" on the marquee and thats it. Where is the problem?

The other problem I have as well, and this could very well be a step Im missing; but when I initiated the Putty program to type directly to the marquee it only recoginized numbers propery and returned ? for any letters. Any suggestions on this would be helpful.

Thanks in advance

patrick

December 30, 2009
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Electromech,

Were you typing capital letters? The font drivers as written only recognize capital letters.

Humberto

December 30, 2009
by Farmerjoecoledge
Farmerjoecoledge's Avatar

Hi Humberto,

Can I clear that up for you? You said? Why is he typing lowercase letters and not CAPITAL UPPERCASE LETTERS. ;)

December 30, 2009
by Electromech
Electromech's Avatar

Thanks AGAIN Humberto. I could have swore I tried caps the last time..but anyhow thats what it was for both issues. So definitely make sure you are typing in caps when you try do_simple and do_scrolling.

On the do_simple function how can we make the text shift to the left once the marquee is filled. Or alteast send a command to clear the screen?

Patrick

December 30, 2009
by Rick_S
Rick_S's Avatar

I believe sending a lowercase a will clear the screen.

Rick

December 30, 2009
by Electromech
Electromech's Avatar

Actually its a lowercase z. Thanks for the quick response. Just messing with the code and going to see if I can get it to scroll the letters as I type. Let you know in a couple of months on how it turns out...lol.

Post a Reply

Please log in to post a reply.

Did you know that essentially all power supplies' voltages drop when current is drawn from them? Learn more...