Topics Topics Edit Profile Profile Help/Instructions Help Member List Member List  
Search Last 1|3|7 Days Search Search Tree View Tree View  

PIC confusion

:: EPE Chat Zone ­:: ­Radio Bygones Message Board :: » EPE Forum Archives 2010 - » Archive through 21 February, 2011 » PIC confusion « Previous Next »

  Thread Last Poster Posts Pages Last Post
  ClosedClosed: New threads not accepted on this page        

Author Message
Top of pagePrevious messageNext messageBottom of page Link to this message

alec_t
Frequent Contributor
Username: alec_t

Post Number: 489
Registered: 03-2009

Rating: N/A
Votes: 0 (Vote!)

Posted on Monday, 31 January, 2011 - 02:33 pm:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

It doesn't take much to confuse me as the years take their toll, but is it just me, or do others too find Microchip's coding syntax confusing?
Example 1:
SUBWF means 'subtract W from F' ....which is what you'd expect. But instead of the intuitive SUBWL to mean 'subtract W from L' what do Microchip use? SUBLW !
Example 2:
Most user-code sets a flag bit when something significant occurs, but in Microchip-land the carry bit in the status register is cleared when a carry occurs. That's tripped me up on several occasions.

Alec
Top of pagePrevious messageNext messageBottom of page Link to this message

terrym
Frequent Contributor
Username: terrym

Post Number: 942
Registered: 05-2005

Rating: N/A
Votes: 0 (Vote!)

Posted on Monday, 31 January, 2011 - 11:48 pm:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

Re the carry bit. It depends on what type of operations you do as to what is in the carry bit.
A RLF or RRF will put the LSB or MSB bit into the carry register. So, yes, definitely confusing. But then, isn't most PIC code.

TM
Top of pagePrevious messageNext messageBottom of page Link to this message

alec_t
Frequent Contributor
Username: alec_t

Post Number: 491
Registered: 03-2009

Rating: N/A
Votes: 0 (Vote!)

Posted on Tuesday, 01 February, 2011 - 09:31 am:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

True. I was thinking of the adding/subtracting operations and had forgotten about the shift ops.

Alec
Top of pagePrevious messageNext messageBottom of page Link to this message

pebe
Regular Contributor
Username: pebe

Post Number: 50
Registered: 05-2005

Rating: N/A
Votes: 0 (Vote!)

Posted on Tuesday, 01 February, 2011 - 09:49 am:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

Another unexpected one is MOVF. You would expect the default would be to move the file to W, but the compiler defaults to 1, ie. move the file to itself.
Top of pagePrevious messageNext messageBottom of page Link to this message

jaybee
Regular Contributor
Username: jaybee

Post Number: 25
Registered: 11-2006

Rating: N/A
Votes: 0 (Vote!)

Posted on Tuesday, 01 February, 2011 - 12:34 pm:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

I think that the add/subtract carry action is completely logical:

When you add, if it carries over, then the carry bit is SET.

When you subtract, the carry bit is first set so that you can borrow it if needed and then it gets CLEARed.

I suppose it should really be called CARRY/BORROW

John.
Top of pagePrevious messageNext messageBottom of page Link to this message

terrym
Frequent Contributor
Username: terrym

Post Number: 945
Registered: 05-2005

Rating: N/A
Votes: 0 (Vote!)

Posted on Wednesday, 02 February, 2011 - 10:49 am:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

'I suppose it should really be called CARRY/BORROW'

I have a vague recollection of Microchip actually putting that in either an app note or datasheet in the distant past.

TM
Top of pagePrevious messageNext messageBottom of page Link to this message

epithumia
Frequent Contributor
Username: epithumia

Post Number: 836
Registered: 06-2006

Rating: N/A
Votes: 0 (Vote!)

Posted on Wednesday, 02 February, 2011 - 03:32 pm:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

Definitely confusing.

I often ADD a negative number to avoid using SUBtract.

And using the PIC18 Branch instructions removes a lot of the confusion I had with BTFSC/S. The double a triple negatives stacking up there was always a sticking point.

Epi
If you need me, Neil and me will be hanging out with the Dream King. - Tori Amos
Top of pagePrevious messageNext messageBottom of page Link to this message

terrym
Frequent Contributor
Username: terrym

Post Number: 948
Registered: 05-2005

Rating: N/A
Votes: 0 (Vote!)

Posted on Thursday, 03 February, 2011 - 01:46 am:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

Haven't programmed any 18f's yet, although I have a few sitting here waiting for me to play with.

TM
Top of pagePrevious messageNext messageBottom of page Link to this message

davejs
Regular Contributor
Username: davejs

Post Number: 22
Registered: 09-2009

Rating: N/A
Votes: 0 (Vote!)

Posted on Thursday, 03 February, 2011 - 09:48 am:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

From previous topics I know that there is a fair amount of antipathy on this forum to high level languages but if you want to cut through the confusion and develop projects quickly then you could do a lot worse than give Oshonsoft BASIC a try. Unfortunately those of us that have, do become evangelists
Dave
Top of pagePrevious messageNext messageBottom of page Link to this message

terrym
Frequent Contributor
Username: terrym

Post Number: 949
Registered: 05-2005

Rating: N/A
Votes: 0 (Vote!)

Posted on Friday, 04 February, 2011 - 12:52 am:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

I've got Oshonsoft Basic, but find I program quicker in assembler for some reason (when I actually do some these days).

Mostly use the emulator functions of the Oshonsoft gear.

TM

Administration Administration Log Out Log Out   Previous Page Previous Page Next Page Next Page