#avr Logs

Jul 26 2021

#avr Calendar

09:17 AM Sponge5: Hi guys, this should be quick.. How do I store a register value into a variable? I thought it would be as easy as "uint8_t regValue = PINB" but it's not working for me...
09:24 AM qu1j0t3: Sponge5: does it compile?
09:24 AM Sponge5: yea it does
09:24 AM qu1j0t3: what steps are you doing to verify
09:24 AM qu1j0t3: that it works or not
09:29 AM Sponge5: I have a PC interrupt from 4 different pins on the PINB register and I'm looking to differentiate between them. For some reason doing only "if(PINB | ~_BV(PB4)){}else if(PINB | ~_BV(PB5)){}..." works only for the first conditional, the rest come too late (I've tested switching them out)
09:29 AM Sponge5: So I thought storing the register first and then comparing after the fact would work but it doesn't
09:32 AM qu1j0t3: are these bitwise ops correct?
09:33 AM qu1j0t3: Sponge5: apart from that, your idea should work better, yes
09:34 AM qu1j0t3: (assumign you really do have enough time to read this reg...)
09:36 AM LeoNerd: Your logic is wrong
09:37 AM LeoNerd: For bittesting you want to ^
09:37 AM LeoNerd: For bittesting you want to &
09:37 AM LeoNerd: (fscking keyboard)
09:37 AM qu1j0t3: yes
09:37 AM qu1j0t3: that's what it seemed like to me :)
09:37 AM twnqx: also no ~, right?
09:37 AM qu1j0t3: twnqx: right
09:38 AM twnqx: though pin CHANGE is even worse
09:38 AM twnqx: becuase this way you only test current state
09:38 AM twnqx: and you will catch only low->high transitions, but not high->low transitions
10:14 AM specing_ is now known as specing
12:03 PM rue_mohr: do you want code that detects either transition?
12:04 PM rue_mohr: Sponge5, if you want to know if pins are high and low
12:05 PM rue_mohr: #define IsHigh(BIT, PORT) (PORT & (1<<BIT)) != 0
12:05 PM rue_mohr: #define IsLow(BIT, PORT) (PORT & (1<<BIT)) == 0
12:05 PM rue_mohr: macros make code readable
12:05 PM rue_mohr: know how to use them so you dont screw them up
12:06 PM rue_mohr: if (IsHigh(4, PINB) && IsHigh(5, PINB) ...)
06:21 PM specing_ is now known as specing
07:23 PM specing_ is now known as specing
07:35 PM specing_ is now known as specing