Hi Leonardo
>Question one:
>
>For easily the example I have change the TMR0 in Count
>I do not have fully understand the meaning of the instructions
>
>SUBWF COUNT,W
>BTFSC STATUS,0
>
>first assumption:
>assuming that the current value of Count is 200
>subtract from Count the value of 196
>The result is 4 and is stored back to Count
>the carry should be on (is correct?)
Yes CARRY is on.
It is only CLEARED when there is a BORROW.
The result 4 is stored in W,not in COUNT.
To store in COUNT if the command is:
SUBWF COUNT,F ;note the F at the end, meaning result is
;stored in the File register or COUNT.
>Second assumption:
>assuming that the current value of Count is 196
>subtract from Count the value of 196
>The result is 0 and is stored back to Count
>the carry should be on (is correct?)
As before, result is stored in W and CARRY on.
>Third assumption:
>assuming that the current value of Count is 190
>subtract from Count the value of 196
>The result is 249 (is correct?) and is stored back to Count
>the carry should be off (is correct?)
The result is 250 or 0xFA and stored in W not if COUNT.
CARRY is OFF (correct).
Subtraction works like this:
190 - 196 = 190 + 2'scomplement (196)
190 + 60 = 250 ; Note no overflow/carry
2's complement is done by negating and then add 1.
196 = 0xC4 = 0b11000100
negating: 0b11000100 -> 0b00111011 = 0x3B = 59
add 1 : 59 + 1 = 60
>Looking at the manual DS30430B on page 15 fig. 4-5, bit 0 is set ADDWF and
>ADDLW and for me is not clear (probably for my bad english).
>Could you please explain.
Sorry I don't have the manual at this moment, but what register for bit 0
are you refering?
{Quote hidden}>Question two:
>Referring to the RPM pulse meter, I would like build a LED BAR METER like
>"copy in progress".
>This means, having ten LED to set on each LED at 1.000 RPM increase with
>accuracy of 1.000 RPM (I know it is not a good instrument, but only
>appearance light)
>
>I have build a grossolabe table like the following:
>
>Count =20 RPM=10.000 bit set on RB1, RB2, RB3 ,RB4, RB5, RB6, RB7, RA0,
>RA1, RA2
>Count =28 RPM=9.000 bit set on RB1, RB2, RB3 ,RB4, RB5, RB6, RB7, RA0,
>RA1
>Count =36 RPM=8.000 bit set on RB1, RB2, RB3 ,RB4, RB5, RB6, RB7, RA0
>Count =44 RPM=7000 bit set on RB1, RB2, RB3 ,RB4, RB5, RB6, RB7
>Count =54 RPM=6000 bit set on RB1, RB2, RB3 ,RB4, RB5, RB6
>Count =66 RPM=5000 bit set on RB1, RB2, RB3 ,RB4, RB5
>Count =72 RPM=4000 bit set on RB1, RB2, RB3 ,RB4
>Count =105 RPM=3000 bit set on RB1, RB2, RB3
>Count =144 RPM=2.000 bit set on RB1, RB2
>Count =240 RPM=1.000 bit set on RB1
>
>I would like build a series of IF to test il the value of Count meet right
>range.
I'll try (untested):
COUNT < 240, RB1
COUNT <144, RB1,RB2
.
.
.
COUNT <20, ....
-----
START:
CLRF LIGHTS1
CLRF LIGHTS2
MOVLW 240
SUBWF COUNT,W
BTFSC STATUS,0
GOTO LAST
BSF STATUS,0
RLC LIGHTS1
MOVLW 144
SUBWF COUNT,W
BTFSC STATUS,0
GOTO LAST
BSF STATUS,0
RLC LIGHTS1
MOVLW 105
SUBWF COUNT,W
BTFSC STATUS,0
GOTO LAST
BSF STATUS,0
RLC LIGHTS1
.
.
.
MOVLW 36
SUBWF COUNT,W
BTFSC STATUS,0
GOTO LAST
BSF STATUS,0
RLC LIGHTS1
MOVLW 28
SUBWF COUNT,W
BTFSC STATUS,0
GOTO LAST
BSF STATUS,0
RLC LIGHTS1
RLC LIGHTS2
MOVLW 20
SUBWF COUNT,W
BTFSC STATUS,0
GOTO LAST
BSF STATUS,0
RLC LIGHTS1
RLC LIGHTS2
LAST:
RLC LIGHTS1
RLC LIGHTS2
MOVF LIGHTS1,W
MOVWF PORTB
MOVF LIGHTS2,W
MOVWF PORTA
Reggie