Home     Contact     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS     Terms of services     Privacy policy  
   
 Home      Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science   



All about PIC microcontrollers

Within these pages, you can find many useful pieces of code mostly in assembly for the Microchip PIC micro controller family. A lot of people have spend many hours trying to put the bits and bytes together. If the code is NOT written by a member of the PCB Heaven community, then a link will be added above the code with the original website that this code was found.
Because the code is copied to our servers, you should know that:

  • The responsible web master of the website that the code is taken, has been informed and he has agreed to copy the code
  • All emails from the above contact have been kept as records but due to personal privacy cannot be shown in public.
  • The author of the code is always clearly indicated above the code. In some cases the author is unknown. If you happen to be the author of the code or you know the person who wrote it, please inform us by email and it will be added ASAP.

We would personally like to send the credits to all the people that managed to write some very interesting code and publish it, and special thanx to the people that originally hosted those code snippets and gave us the permission to copy them.


View code
2 digit Decimal to Binary 8 bits
Author: Scott Dattalo - Dmitry Kiryashov
This code was originally located @ http://www.piclist.com


Follow this link to go back

;ascii1 and ascii2 are the tens and ones digit of a number we wish
;to convert to binary
;
; In C:
;
; binary = (ascii1 & 0xf) * 10 + (ascii2 & 0xf);
;
; (I'd be interested to see how a compiler would generate the asm for this.)
;

movlw 0x0f
andwf ascii2,f ;Clear the upper nibble of the one's digit

; Multiply the ones digit by 10.
rlf ascii1,w ;2*tens
;Note that the carry is also cleared because
;ascii1 is an ASCII number between 0x30-0x39
andlw 0x1e ;Clear upper nibble of tens digit
;In addition, we clear the shifted in carry
movwf ascii1 ;W = ascii1 = 2*original ascii1
rlf ascii1,f ;ascii1 = 4*original ascii1
rlf ascii1,f ;ascii1 = 8*original ascii1
addwf ascii1,w ;W = 2*original ascii1 + 8 *original ascii1
; = 10*original ascii1
addwf ascii2,w ;

; Or use this one that saves a cycle:

rlf tens,w
andlw 0x1e ;w=2*tens
movwf temp
rlf temp,f ;temp=4*tens
rlf temp,f ;temp=8*tens
addwf ones,w
addlw -'0' ;convert from ASCII to decimal
;w=tens*2 + ones
addwf temp,w ;w=10*tens + ones

;Dmitry Kiryashov [zews at AHA.RU] says:
;Destructive way to save one more clock ;-)

movfw tens ;*1
addwf tens,F ;*2
rlf tens,F ;*4
addwf tens,F ;*5
rlf tens,W ;*10
addwf ones,W
addlw low -11.*'0'

;Why so ? tens is '0' + x , ones is '0' + y , where x and y are in range
;of 0..9 So finally '0'*(10+1)=48.*11.=528.=0x210 . it is constant so we
;can subtract it back from result. Here we gone ;)

Follow this link to go back






delicious
digg
reddit this Reddit this
Faves



 HOT in heaven!