PDA

View Full Version : Normal programming question



stevenlkz
- 12th June 2005, 05:46
I got two questions about the programming of PIC16F877.
1. Normally, when we rotate 8 time with 8 bit data, we will get back the same data right? But if I rotate one time, then call a subroutine or goto other place, the carry flag already change. Then back to here and rotate again. This loop will go on for 8 time, is it finally still can get back the same data?
2. If I add 8 bit data with another 8 bit data and the result is is overload to 9 or 10 bit, then how a result will store?

Melanie
- 12th June 2005, 09:32
If you are talking about PICBasic, then a rotation will push bits out the end and lose them... they are replaced with zero's being pushed back in...


' example 1...

a var byte

a=%11111111
a=a >> 1

' a now contains %01111111

' example 2...

a var byte

a=%11111111
a=a << 3

' a now contains %11111000
The result of an addition of two numbers will remain within the variable size you have decalred, and only the bottom eight bits (in a byte) or the bottom 16 bits (in a word) will remain.


' example 3...

a var byte
b var byte
c var byte

b=255
c=1

a=b+c

' Result in a = 0 (zero)

' example 4...

a var word
b var byte
c var byte

b=255
c=1

a=b+c

' Result in a = 256
If you need to check for an overflow, then you will need an additional line of code...


' example 5...

a var byte
b var byte
c var byte
overflow var byte

b=255
c=1

a=b+c
if a < b then overflow=1 else overflow=0

stevenlkz
- 13th June 2005, 07:13
Thanks for your help, Melanie. But I am using MPlab compiler.
I have another 6 question with MPlab assembler programming.
1. Is the PIC can use to check the value whether it is a positive or negative value?
2. Is the IF/ELSE statement available in MPlab?
3. How to compare and get the smallest number between three number?
4. After I use the fixed point division of the application note, AN617 in microchip, but the output is in floating point, then how to read the result?
5. If the maximum number of floating point is 0.125 in decimal number, then how many bits should I use for math operation?
6. In application note, AN575 in microchip, it said that floating point 0X823C5198, but how to read it? What decimal value is it?

Melanie
- 13th June 2005, 07:59
This is a PICBASIC forum for the MeLabs product, and my answers assumed you were using that compiler. Really for in-depth Assembler, try one of the Microchip forums - eg...

http://forum.microchip.com/

stevenlkz
- 13th June 2005, 14:59
Ok, thanks for helping.