Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 17th January 2009, 07:36 AM   #1
Default PIC programming question

I downloaded a PIC programme from the internet for a PIC16F88.

PORTA 1, 2 & 3 are used as analogue inputs.

But there is an instruction in the programme that I don’t understand.

movlw (1<<ana1)|(1<<ana2)|(1<<ana3)

I’m familiar with the normal movlw instruction, eg. movlw 0x1A, but not with the one above.

In the definitions, the parameters are defined as:-

ana3 equ 3 ; analog input AN3

ana2 equ 2 ; analog input AN2

ana1 equ 1 ; analog input AN1

Any assistance will be appreciated.
__________________
Len
ljcox is offline  
Old 17th January 2009, 07:45 AM   #2
Default

Your setting the bit to 1

Last edited by be80be; 17th January 2009 at 07:46 AM.
be80be is offline  
Old 17th January 2009, 07:51 AM   #3
Default

Bitwise inclusive OR
be80be is offline  
Old 17th January 2009, 07:54 AM   #4
Default

The "<<" directive shifts the number left by the number to the right.

So,
1<<3 = 8
1<<6 = 64

and so the movlw instruction above if the same as movlw b'00001110'.

Mike.
Pommie is online now  
Old 17th January 2009, 08:23 AM   #5
Default

So it is moving a 1 right so it would put
Code:
 b'00001110'
but why the pipe | is it for stacking
Code:
movlw (1<<ana1)|(1<<ana2)|(1<<ana3)
which is the same as this
Code:
movlw b'00001110
And this set a 0
Code:
 
movlw b'11111111'-(1<<ana1)-(1<<ana2)-(1<<ana3)
which is
Code:
movlw b'11110001
be80be is offline  
Old 17th January 2009, 08:33 AM   #6
Default

Quote:
Originally Posted by be80be View Post
So it is moving a 1 right so it would put
Code:
 b'00001110'
but why the pipe | is it for stacking
The pipe means OR. I've seen people do this in C too. What it usually means is that they don't know how to convert to binary. This gets the bits in there in a roundabout way.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline  
Old 17th January 2009, 08:35 AM   #7
Default

The | is inclusive or and so,

b'00000010' or b'00000100' or b'00001000' = b'00001110'

Mike.
Pommie is online now  
Old 17th January 2009, 07:56 PM   #8
Default

Thanks for the prompt responses. Much appreciated.

I understand. eg. 1<<n means shift left n places.

| means inclusive OR.

It seems a complicated way to do something simple, but I guess he had his reasons.
__________________
Len
ljcox is offline  
Old 17th January 2009, 08:23 PM   #9
Default

Quote:
Originally Posted by ljcox View Post
Thanks for the prompt responses. Much appreciated.

I understand. eg. 1<<n means shift left n places.

| means inclusive OR.

It seems a complicated way to do something simple, but I guess he had his reasons.
Isn't it just standard C? - and I don't even do C.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 17th January 2009, 10:23 PM   #10
Default

Quote:
Arithmetic operators may be used with directives and their variables.
These operators cannot be used with program variables. They are for use with directives only.
From Mplab Assembler
be80be is offline  
Old 18th January 2009, 02:47 AM   #11
Default

The reason it is done this way is so that if sometime in the future the design was changed and instead of A2, A4 was used then it is a simple matter to change,

ana2 equ 4 ; analog input AN2

rather than trying to find all occurrences in the code.

I use to use this method to setup SFRs. EG,
Code:
	movlw	(1<<GIE|1<<PEIE|0<<TMR0IE|0<<INTE|0<<RBIE|0<<TMR0IF|0<<INTF|0<<RBIF)
	movwf	INTCON;		enable Peripheral interrupts
but it confused people and so I stopped using it.

Mike.
Pommie is online now  
Old 18th January 2009, 08:53 PM   #12
Default

Quote:
Originally Posted by Nigel Goodwin View Post
Isn't it just standard C? - and I don't even do C.
It may be, but I know nothing at all about C.
__________________
Len
ljcox is offline  
Old 18th January 2009, 08:57 PM   #13
Default

Quote:
Originally Posted by Pommie View Post
The reason it is done this way is so that if sometime in the future the design was changed and instead of A2, A4 was used then it is a simple matter to change,

ana2 equ 4 ; analog input AN2

rather than trying to find all occurrences in the code.

I use to use this method to setup SFRs. EG,
Code:
	movlw	(1<<GIE|1<<PEIE|0<<TMR0IE|0<<INTE|0<<RBIE|0<<TMR0IF|0<<INTF|0<<RBIF)
	movwf	INTCON;		enable Peripheral interrupts
but it confused people and so I stopped using it.

Mike.
Thanks Mike.
__________________
Len
ljcox is offline  
Old 18th January 2009, 11:23 PM   #14
Default

I like It. It works for me and makes a lot of sense to me.
_______________________________________
But I have never been confused
be80be is offline  
Reply

Tags
pic, programming, question

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
C programming question MrMikey83 General Electronics Chat 12 4th January 2006 10:36 PM
PIC programming question Deni Micro Controllers 1 11th May 2004 06:03 PM
PIC programming question Andy_123 Micro Controllers 4 7th March 2004 01:53 PM
Programming PIC question... udi_hakim Micro Controllers 4 17th January 2004 10:54 AM
some question about programming watson Micro Controllers 3 17th August 2003 05:59 AM



All times are GMT. The time now is 01:28 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker