![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
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 | |
| |
| | #2 |
|
Your setting the bit to 1
Last edited by be80be; 17th January 2009 at 07:46 AM. | |
| |
| | #3 |
|
Bitwise inclusive OR
| |
| |
| | #4 |
|
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. | |
| |
| | #5 |
|
So it is moving a 1 right so it would put Code: b'00001110' Code: movlw (1<<ana1)|(1<<ana2)|(1<<ana3) Code: movlw b'00001110 Code: movlw b'11111111'-(1<<ana1)-(1<<ana2)-(1<<ana3) Code: movlw b'11110001 | |
| |
| | #6 |
| 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 ========================= | |
| |
| | #7 |
|
The | is inclusive or and so, b'00000010' or b'00000100' or b'00001000' = b'00001110' Mike. | |
| |
| | #8 |
|
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 | |
| |
| | #9 |
| Isn't it just standard C? - and I don't even do C.
| |
| |
| | #10 | |
| Quote:
| ||
| |
| | #11 |
|
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 ![]() Mike. | |
| |
| | #12 |
| It may be, but I know nothing at all about C.
__________________ Len | |
| |
| | #13 | |
| Quote:
__________________ Len | ||
| |
| | #14 |
|
I like It. It works for me and makes a lot of sense to me. _______________________________________ But I have never been confused ![]() | |
| |
|
| 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 |