Thanks for the info, that clean few things up!!!
Steven
-----Original
Message-----
From: David VanHorn
[mailto:dvanhorn@cedar.net]
Sent: Tuesday, 13 January 2004
8:47 AM
To: avrclub@yahoogroups.com;
'AVR-GCC'; 'AVR-Chat'; 'AVRCLUB'
Subject: [AVR-Chat] Re: [AVR club]
STK button detection
>
>
>Can someone explain to me why the keys is
compared by using 2, 4, 8, 0x10,
>0x20, 0x40, 0x80!!! And is there other
way of detecting it?
>
>
If you look at the port bits as hex numbers, they
are
0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01
So if I wanted to look for bits 0 and 7, I would
read the port, and and it with 0x81
The anding operation causes all "1"; bits
in the input except those that are 1 in the mask, to become zeroes.
So if the PIN read in 0xA0: 10100000
in R16,PINB
(R16 now contains 0xA0h)
and we and with 0x80, we get 10000000
andi R16,0x80
(R16 now contains 0x80)
Now if bit 7 was zero, then the result of this
operation would have set the zero flag, otherwise zero is cleared, so the next
bit of code might be:
brne Button_Pressed ;(Branch Non Equal (or
non zero))
Clear as mud? :)
The other way, is to do
sbic PINB,7 ;(Skip if bit in I/O is clear)
rjmp Button_Pressed ;Assuming the button gives a
high when pressed.
Note: Make sure to always read the pin states on
the PIN register, and make sure that the bits in the corresponding DDR register
are zero to make those pins inputs.
Yahoo! Groups Links
· ;
To visit your group on the
web, go to:
http://groups.yahoo.com/group/AVR-Chat/
· ;
To unsubscribe from this
group, send an email to:
AVR-Chat-unsubscribe@yahoogroups.com
· ; Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.560 / Virus Database: 352 - Release Date: 8/01/2004
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.560 / Virus Database: 352 - Release Date: 8/01/2004