Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/05/06 03:42
Modified:
  07/05/06 03:48

Read: times


 
#119637 - Vertically incrementing
Responding to: ???'s previous message
Suresh said:
I couldnt find how the two counters (ctrA, ctrB) are been used to achieve this.

A standard 4 step counter using two bits of a byte "knows" the following states:

1. step: XXXX XX00
2. step: XXXX XX01
3. step: XXXX XX10
4. step: XXXX XX11

You can also do it this way:

1. step: X00X XXXX
2. step: X01X XXXX
3. step: X10X XXXX
4. step: X11X XXXX

This is trivial, of course. As the two bits are within the same byte one could call it a "horizontal counter". I don't know whether this term exists. But it shall demonstrate here the difference to another type of counter, namely the "vertical counter". This one uses bits of different bytes, where the bits are at the same position within the byte. In the code example of Hans the two bits sit in the bytes CtrA and CtrB and the counting scheme looks as follows:

1. step: CtrB: XXXX XXX0
         CtrA: XXXX XXX0

2. step: CtrB: XXXX XXX1
         CtrA: XXXX XXX0

3. step: CtrB: XXXX XXX0
         CtrA: XXXX XXX1

4. step: CtrB: XXXX XXX1
         CtrA: XXXX XXX1

You can also do it this way:

1. step: CtrB: XXXX X0XX
         CtrA: XXXX X0XX

2. step: CtrB: XXXX X1XX
         CtrA: XXXX X0XX

3. step: CtrB: XXXX X0XX
         CtrA: XXXX X1XX

4. step: CtrB: XXXX X1XX
         CtrA: XXXX X1XX

or this way:

1. step: CtrB: X0XX XXXX
         CtrA: X0XX XXXX

2. step: CtrB: X1XX XXXX
         CtrA: X0XX XXXX

3. step: CtrB: X0XX XXXX
         CtrA: X1XX XXXX

4. step: CtrB: X1XX XXXX
         CtrA: X1XX XXXX

The interesting question is now: How to increment such a vertical counter?
The answer is simple: Whenever the vertical counter is incremented (by one step) the bit in byte CtrB changes its state, means was it "0" becomes it "1" and was it "1" becomes it "0". This is done by the instruction:

xrl     CtrB,#0ffh

You could also do it with the "CPL" instruction, but then the byte must sit in the accumulator.

The bit in byte CtrA, on the other hand, becomes "1", when the bit in CtrA and the bit in CtrB were of different states. Otherwise it becomes "0". So,

mov 	a,CtrB
xrl     CtrA,a

does the trick!

Hope this helps,

Kai

List of 36 messages in thread
TopicAuthorDate
4x3 keypad interfacing with At89c51            01/01/70 00:00      
   5 errors            01/01/70 00:00      
      Nice attitude!            01/01/70 00:00      
         If the approach is that anyone can get h            01/01/70 00:00      
            Do we know him?            01/01/70 00:00      
               Switch Depressed?            01/01/70 00:00      
                  continous and continous            01/01/70 00:00      
                     Thanks Erik!            01/01/70 00:00      
                  Taking samples            01/01/70 00:00      
                     debounce scheme.            01/01/70 00:00      
                        How to debounce without jumps and branch            01/01/70 00:00      
                           Thank you Kai...            01/01/70 00:00      
                           Having gone through your detailed descri            01/01/70 00:00      
                              Yes, I think so            01/01/70 00:00      
                                 Could you assist me to know that            01/01/70 00:00      
                                    Vertically incrementing            01/01/70 00:00      
                                       Thanks            01/01/70 00:00      
               Homework it is            01/01/70 00:00      
                  "Guilty"...            01/01/70 00:00      
   Post your code            01/01/70 00:00      
      2            01/01/70 00:00      
         There have been several threads            01/01/70 00:00      
         How to post code            01/01/70 00:00      
         why so complex            01/01/70 00:00      
         What Compiler ?            01/01/70 00:00      
            Compiler.KEIL            01/01/70 00:00      
         general idea            01/01/70 00:00      
            Diodes to prevent ghosting            01/01/70 00:00      
    Algorithm for Scanning 4*4 Keypad            01/01/70 00:00      
      thanks            01/01/70 00:00      
         If you'd searched, you'd have had this            01/01/70 00:00      
            Search term "4x4 keypad"            01/01/70 00:00      
   check this code.            01/01/70 00:00      
      Answers            01/01/70 00:00      
   Sorry kai.            01/01/70 00:00      
      keypad scanner in C            01/01/70 00:00      

Back to Subject List