Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

AND, OR and shift operations in ARM

Status
Not open for further replies.

ps_arunkumar

Member level 1
Joined
Nov 24, 2011
Messages
36
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,545
Hi all,

I know AND, OR and shift function but when it comes into programming, I dont know how to apply them and also where to apply them. I know them in the digital electronics view only and till date I find it hard to understand those concepts. I read that LSL is used for two complement and LSR is used for divide operation. Is my understanding correct? Do we need to manually calculate the value using these function before implementing?

Could anyone explain how to use these functions and also where to use it. Also any easy way to make use of it?

thanks,
Arun
 

Any special reason for not using C?
 

I am sorry i should have mentioned it. I am talking about C only. Please look at the following C code.

Code:
#define BUZZER_DIR IO1DIR
#define BUZZER_SET IO1SET
#define BUZZER_CLR IO1CLR

int main()
{
BUZZER_DIR |= BUZZER;
BUZZER_SET |= BUZZER;
BUZZER_CLR |= BUZZER;	
}

This code will set Buzzer and then clear it.I simulated in KEIL and i am able
to see that but I am not clear how this works. Also, I replaced 'OR' with 'AND',
'NOT' but it doesn't make any changes to the pin.

Could any one please explain how this 'OR' works and also why 'AND','NOT' doesn't
make any difference?


PINSEL0 = (PINSEL0 & ~(3 << 30)) | (1 << 31);

This line select P0.15

PINSEL0 |= (1 << 31);

This line also the same thing. What makes the difference between them?
 

I don't know what ARM you are using but for STM32 you should do (after setting the direction):
BUZZER_SET = BUZZER;
BUZZER_CLR = BUZZER;
That is, writing the bit to the set and clear registers. Not ORing it. I think this is true for most ARM versions.

Sorry, but if I don't know which processor you use I can't help you with the PINSEL stuff.
 

I am using LPC2148 and compiler is KEIL uVision 4.
 

I would expect the followong line to set PINSEL0 bits 31:30 to 1:0 and therefore select SCK0 for P0[15].
PINSEL0 = (PINSEL0 & ~(3 << 30)) | (1 << 31);

The following line set PINSEL0 bit 31 to 1 and therefore select either SCK or SCK0 for P0[15] depending on PINSEL0 bit 30.
PINSEL0 |= (1 << 31);
 

PINSEL0 = (PINSEL0 & ~(3 << 30)) | (1 << 31);

Could you explain this function. I am little confused how this works. As i told in the thread that i am clear about AND, OR and shift operations. Could you explain this three things or if you give me any references, it is appreciated.
 

Code:
[FONT=Courier New]If we take the constants first:
 (3 << 30) in binary: 1100.0000.0000.0000.0000.0000.0000.0000
~(3 << 30) in binary: 0011.1111.1111.1111.1111.1111.1111.1111
 (1 << 31) in binary: 1000.0000.0000.0000.0000.0000.0000.0000

PINSEL0 at start           xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx
after PINSEL0 & ~(3 << 30) 00xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx
after PINSEL | (1 << 31)   10xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx[/FONT]
The result is to set bit 30 to 0 and bit 31 to 1.
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top