The UK Home Automation Archive

Archive Home
Group Home
Search Archive


Advanced Search

The UKHA-ARCHIVE IS CEASING OPERATIONS 31 DEC 2024


[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]

Re: [OT] Some pic asm code help



Hi Frank
when you rotate RRF DS_DATA1 the least significant bit goes into the carry
bit
+---+    +----------+
+-> C ---> Register >-+
+---+    +----------+
+-------<---------<-------+

then when you RRF DA_DATA0 this bit is rotated from the carry into the Most
sig bit of the LSB

i.e.
MSB =11110010 and LSB =00011000 from your example of F218h
first  RRF MSB =X1111001 with C=0 then RRF LSB giving 00001100 (X=is
unknown value)
second RRF MSB =1X111100 with C=1 then RRF LSB giving 10000110
third  RRF MSB =00X11110 with C=0 then RRF LSB giving 01000011
The test bit 4 of MSB it 1 so convert
COMF MSB =11100001 COMF LSB =10111100
then add 1 to give MSB = 11100001 and LSB=10111101

mask off top 4 bits of MSB to 00000001
Giving final value of 0000000110111101 = 445 (as shown by Ian D)

Does this help
Stephen

P.S. does your development system allow you to single step through the
code?
if so check registers at each step for the above values
(inserting the known starting values into DA_DATA at the start of the
debugging.)


Frank Mc Alinden wrote:
>
>
> Hi Stephen
>
> Loaded your code but still no joy ..it gave me a reading of around 3mV
> ...??/
>
> I dont understand how your code shifts the bits from the MSB byte
DS_DATA1
> into the LSB byte DS_DATA0....
>
> Thanks for your help
>
> Frank
>
> ----- Original Message -----
> From: "Stephen McGarry" <Selfbuild@xxxxxxx
> <mailto:Selfbuild%40Stocksons.co.uk>>
> To: <ukha_d@xxxxxxx <mailto:ukha_d%40yahoogroups.com>>
> Sent: Monday, September 10, 2007 5:57 AM
> Subject: Re: [ukha_d] [OT] Some pic asm code help
>
>  >I see an immediate problem in the code as you are SUBTRACING the
mask not
>  >ANDing !
>  > and you can make the rotates a lot simpler... (without firing up
my
>  > simulator and checking)
>  >
>  > HTH Stephen
>  >
>  > Try this :-
>  >
>  > CEL2760
>  > ;rotate both (don't worry about carrys into MSB as you will mask
later)
>  > rrf DS_DATA1,1 ;shift down MSB and move bit into carry
>  > rrf DS_DATA0,1 ;then move it into the LSB and move it down
>  > rrf DS_DATA1,1 ;and again
>  > rrf DS_DATA0,1
>  > rrf DS_DATA1,1 ;and again
>  > rrf DS_DATA0,1
>  >
>  > btfss DS_DATA1,4 ;check sign status
>  > goto mask_up_nib ;
>  >
>  > comf DS_DATA1,1 ;yes , 2,s compliment
>  > comf DS_DATA0,1 ;invert and
>  > incf DS_DATA0,1 ;add 1
>  >
>  > btfsc C_bit ;
>  > incf DS_DATA1,1 ;
>  >
>  > mask_up_nib
>  > movlw 0fh ;mask out rubbish
>  > andwf DS_DATA1,1
>  >
>  > cely return ;
>  >
>  > Frank Mc Alinden wrote:
>  >>
>  >>
>  >> Hi Ian
>  >>
>  >> I forgot to rotate the MSB so those values in my last post
are way
>  >> out....
>  >> try these MSB D2h .....LSB BBh................MSB
D1h.....LSB F0h
>  >>
>  >> Heres a copy of my current code which is suppose to convert
the raw dat
>  >> to
>  >> 16 bit
>  >>
>  >> Thanks agian
>  >> Frank
>  >>
>  >> CEL2760
>  >>
>  >> bcf neg ;clear negative flag
>  >> btfss DS_DATA1,7 ;negative ? if yes , skip next
>  >> goto cel2 ;no
>  >>
>  >> bsf neg ;set negative flag
>  >>
>  >> cel2 ;rotate LSB
>  >>
>  >> bcf C_bit ;clear carry flag
>  >> rrf DS_DATA0,1 ;Data0 holds LSB data (0F)
>  >>
>  >> bcf C_bit ;clear carry flag
>  >> rrf DS_DATA0,1 ;
>  >>
>  >> bcf C_bit ;clear carry flag
>  >> rrf DS_DATA0,1
>  >>
>  >> ;SHIFT AND ROTATE MSB
>  >>
>  >> chec_msb_bit0
>  >> btfss DS_DATA1,0 ;Check MSB Byte bit 0
>  >> goto set_lsb_5_lo ;
>  >> bsf DS_DATA0,5 ;set bit 5 of lsb byte
>  >> goto chec_msb_1 ;
>  >>
>  >> set_lsb_5_lo
>  >> bcf DS_DATA0,5 ;
>  >>
>  >> chec_msb_1
>  >>
>  >> btfss DS_DATA1,1 ;Check MSB Byte bit 1
>  >> goto set_lsb_6_lo ;
>  >> bsf DS_DATA0,6 ;set bit 6 of lsb byte
>  >> goto chec_msb_2 ;
>  >>
>  >> set_lsb_6_lo
>  >> bcf DS_DATA0,6 ;
>  >>
>  >> chec_msb_2
>  >> btfss DS_DATA1,2 ;Check MSB Byte bit 2
>  >> goto set_lsb_7_lo ;
>  >> bsf DS_DATA0,7 ;set bit 7 of lsb byte
>  >> goto shift_data1 ;
>  >>
>  >> set_lsb_7_lo
>  >> bcf DS_DATA0,7 ;
>  >>
>  >> shift_data1
>  >>
>  >> bcf DS_DATA1,0 ;
>  >> bcf DS_DATA1,1 ;
>  >> bcf DS_DATA1,2 ;
>  >>
>  >> bcf C_bit ;clear carry flag
>  >> rrf DS_DATA1,1 ;
>  >>
>  >> bcf C_bit ;clear carry flag
>  >> rrf DS_DATA1,1 ;
>  >>
>  >> bcf C_bit ;clear carry flag
>  >> rrf DS_DATA1,1 ;
>  >>
>  >> btfss neg ;check sign status
>  >> goto mask_up_nib ;
>  >>
>  >> comf DS_DATA1,1 ;yes , 2,s compliment
>  >>
>  >> comf DS_DATA0,1 ;yes , 2,s compliment
>  >> incf DS_DATA0,1 ;
>  >>
>  >> btfsc C_bit ;
>  >> incf DS_DATA1,1 ;
>  >>
>  >> mask_up_nib
>  >>
>  >> movlw 0fh ;mask upper nibble
>  >> subwf DS_DATA1,1 ;
>  >>
>  >> cely return ;
>  >>




UKHA_D Main Index | UKHA_D Thread Index | UKHA_D Home | Archives Home

Comments to the Webmaster are always welcomed, please use this contact form . Note that as this site is a mailing list archive, the Webmaster has no control over the contents of the messages. Comments about message content should be directed to the relevant mailing list.