Switch Debounce Method (need c tutorials)

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

I was looking for some Switch Debounce info..
There are "TONS" of posts scattered around this site..

But most are "C" examples and I don't quite understand "C"
Following the "C" software code for me is a task.

Mainly because I have not yet memorized things like "&&"

I know they are logical operators.. but I like to see them as "AND"

Here is a "Video" showing a simple debounce method
using a quantity "Sampling" method.

http://www.youtube.com/watch?v=s...

Not using any "Interrupt" or "Timer" (perfect when many buttons are interfaced)

This is in "C" also.. but at least watching and hearing what
he is trying to achieve.. makes it easily ported to any other
type of code like "ASM" or "BASIC"

If like me you understand ASM better.

P.S.

I Need links to "Very BEGINNER" "C" tutorials.. for AVR

So that I can finally understand why "VOID" is used. (! ||) used.

I can see that "C" or GCC I assume is the correct term, has the greatest support.
And would like to learn it, once and for all.

"We look for things.. Things that make us go."

Last Edited: Thu. Dec 6, 2012 - 02:57 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Mainly because I have not yet memorized things like "&&"

I know they are logical operators.. but I like to see them as "AND"

The difficulty here is really not the memorization, as that is really just learning new words. It is learning that there are two ANDs. One ("&") is a bit-wise AND (the direct equivalent of AND in assembly), and the other ("&&") is a logical AND (which has no direct equivalent in assembly).
Quote:
I Need links to "Very BEGINNER" "C" tutorials.. for AVR
I say forget the AVR for the moment. Learn C first, then learn to apply it to the AVR.

Regards,
Steve A.

The Board helps those that help themselves.

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

Quote:
I say forget the AVR for the moment. Learn C first, then learn to apply it to the AVR.
Thsi is good advice I think.

You can learn to program in C on a PC where you don't have to worry about all the complexity of the uC environment.

With a few days/weeks practice with C you will become quite competent.

regards
Greg

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

gregd99 wrote:
With a few days/weeks practice with C you will become quite competent.

Thank you for your confidence.

But I'll say months. :oops:

Any good suggestions to a "Very Beginner" tutorial
for "C"

Because I don't realy understand why "VOID" is used.
So the tutorials need to be from the very start.

Such as:

int main(void)

also seen some

int main()

Are they the same ?? (or when do I use void.)

"We look for things.. Things that make us go."

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

I like this C:\iccv7avr\Help\ICCAVR\wwhelp\wwhimpl\js\html\wwhelp.htm

Imagecraft compiler user

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

Quote:
Such as:

int main(void)

also seen some

int main()

Are they the same ?? (or when do I use void.)

In C++ the two are the same.

In C there is a difference, but it is largely unused. To be technically correct, use the void form. In older versions of C, the non-void version means something different, but can (and often is) used interchangeably with the void version. Later versions of C (C99) started bringing C closer to the C++ usage.

Regards,
Steve A.

The Board helps those that help themselves.

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

You could go to a book store ( or online if you need to) and have a look into ( online not possible thus) the books they have there about C.

Over here in NL every boook tore has at least a number of books about C programming.
I personally started off with the C for dummys book and later found some other books that looked interesting.

Also there are loads and loads of websites about learning C and as you have an internet connection you could also have a look at those. I personally rather first read something then re-read it and be sure I understand ( or at least think I understand) and only then sit behind the screen and start playing with the learned. I found out the when I read something from the screen one gets to eager to try things then to first read and understand.

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

Quote:

Any good suggestions to a "Very Beginner" tutorial
for "C"

How about actually reading a book?

Also: It has been argued many times that learning C is easier if you do it on a PC - not writing for an AVR but for e.g. a console/command-line environment. I tend to agree. There are several free C IDE's for that environment available: Pelles C, Microsoft Visual Studio Express Edition, Eclipse with GCC, NetBeans with GCC, Code::Blocks with GCC...

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

Thanks Koshchi

Just wanted to clarify..

same as the instruction "LET" not
needing to be used in "Basic"

Like -- LET A = 1
all you need is : A = 1

VOID just means nothing.. just used for the old school method of code.

Well I hope to find a nice "C" tutorial(s)..

That will apply to the AVR's

I assume.. Stay away from "C+" and "C++" examples ?

Would have to say I understand 80% of code I see..

Need to find a list of what commands (Functions) are in those AVR's "Default" .h files also..

Knowing what to include can sometimes be difficult..

--- Another Stupid question..

How "Efficient" is "C"..

Does it use More Flash Ram.. than "ASM" compiled code ??

"We look for things.. Things that make us go."

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

Thanks JohanEkdahl

For the software list.. (program names) I'll check them out..

Hard to know what software is available when you
don't know what to look for..

"We look for things.. Things that make us go."

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

Two good books you can read

Let us C:
http://books.google.gr/books/abo...

The C Programming Language:
http://cm.bell-labs.com/cm/cs/cb...

Also refer to this post https://www.avrfreaks.net/index.p...

Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

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

Quote:

How "Efficient" is "C"..

Does it use More Flash Ram.. than "ASM" compiled code ??


That is (or at least was, just a few years ago) war fodder.

If you're a very good assembler programmer, then you might well outdo the compiler in a lot of cases. I would not expect the savings in code size, data size or execution time to be big though. Very sweepingly, I'd be surprised if you would do hand-coded assembler that is 10 percent better than what a good C compiler produces, and in many cases it'd be hard to reach even that. And this assumes you are a really skilled assembler programmer. If you're average or below in assembler, then you'd probably be just as well off with the code a C compiler produces.

Then again, you can abuse any language and make the generated code very efficient. You need to have reasonable knowledge of any language you use to write programs, or you're cooked..

The hard thing for many assembler programmers rtying to take on e.g. C is that they are not compfortable with loosing absolute control of generated code. You just have to do that, or you will not sleep well. C does not promise anything re the generated machine code, but adheres to the semantics promised by the C language - period. Having said that I repeat that any proven compiler will perform quite good.

The advantage is (arguably) that you code faster in C. And some code, written correcly, will be portable between platforms.

Quote:
I assume.. Stay away from "C+" and "C++" examples ?

There is no such thing as "C+". Yes, stay away from C++ examples if C is what you want to learn.

Quote:
Need to find a list of what commands (Functions) are in those AVR's "Default" .h files also..

Some of the functions are actually mandated by the C standard and should be in the knowledge any C programmer has. Some are special for the AVR and you will have to look in the documentation for the compiler you will use to know what they do.

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

Here is an online C textbook: http://publications.gbdirect.co....

Fully legitimate - you will not breach any copyright if reading it online, or if you download the PDF version that is also available.

I have not read it all, but from the parts that I have looked at I find it quite good.

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

kds12345 wrote:
Need to find a list of what commands (Functions) are in those AVR's "Default" .h files also.

You can do a lot in C without using a single library function. I suggest you start with learning the keywords and operators in C. This is essential.

Also look at your AVR's datasheet for short C code examples and their assembly equivalents.

You will need to #include but the datasheet example code will tell you a lot about how to use what's in it.

Sid

Life... is a state of mind

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

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

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

Quote:
VOID just means nothing.. just used for the old school method of code.
In the circumstance that you posted, partially yes. In C99, the "int foo()" form was deprecated, not completely removed. This means that for any particular compiler the old functionality may or may not still be there. For other places void may be found, such as "void foo()" and "ptr = void;", the void still is used.

Regards,
Steve A.

The Board helps those that help themselves.

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

Koshchi wrote:
"ptr = void;"

?

Sid

Life... is a state of mind

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

Thanks Guys to all these links
and all the other answers to my questions.

This wIll keep me busy for a bit..

Thanks JohanEkdahl for that link to the PDF..

And alexan_e (those look great) thanks.

"We look for things.. Things that make us go."