![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
Hi I want to add a 10 bit number 8 times & place them in two bytes. Ex:345 X 8 = 2760 Does anybody have any math routine for that I searched in piclist but I couldn't find such a one. | |
| |
| | #2 |
|
You can use the RLF instruction. Code: ;put 345 into Acc movlw low .345 movwf AccLo movlw high .345 movwf AccHi ;now multiply by 8 bcf STATUS,C ;gets shifted into bit 0 of AccLo rlf AccLo,f rlf AccHi,f ;*2 bcf STATUS,C rlf AccLo,f rlf AccHi,f ;*4 bcf STATUS,C rlf AccLo,f rlf AccHi,f ;*8 ;AccHi/AccLo now contain 2760. Mike. | |
| |
| | #3 |
|
Hi Mike Thanks for your input I'm wondering how can I use this for 16F PICs the maximum value it can hold is 255. Thanks | |
| |
| | #4 |
|
The code I posted is for 16F Pics. By combining two bytes the maximum value becomes 65535. Mike. | |
| |
| | #5 |
|
Hi thanks mike ! But i have a small question. When I multiply 345 X 2 = 690 1010110010 That is correct But when I double this 690 it will be = 1380 10101100100 Can you tell how this bit0 will be get set in the AccHi register. | |
| |
| | #6 |
|
An RFL instruction moves all bits left one place. The bottom bit gets the value that was in the carry flag and the top bit gets placed in the carry flag. Can you answer your question now? Mike. | |
| |
| | #7 |
|
I have attached the number pattern the green cell is my problem how will it be set?
| |
| |
| | #8 |
|
Via the carry bit. Mike. | |
| |
| | #9 |
|
Hi mike after reading lot of times now I got understood. I got what I was expected. What I’m doing with your routine? I’m going to sample my AD value 8 times & going to divide by 8 to get the average. Thank you very much mike | |
| |
| | #10 |
|
I just got a point. The bottom bit gets the carry bit value after the instruction completed I believe. Ex after the RLF completed the bottom bit will get sets. Now I understood thanks again mike. | |
| |
| | #11 |
|
To divide by 8 you need to use RRF. Mike. | |
| |
| | #12 | |
| Quote:
Thanks for that. | ||
| |
|
| Tags |
| 10bit, adding, number, times |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Circuit to count number of times phone is picked up | Megamox | General Electronics Chat | 22 | 4th December 2005 06:07 PM |
| Random number generator | joe_1 | Micro Controllers | 3 | 9th May 2004 11:04 AM |
| Need help with random number generator | themikestar | Electronic Projects Design/Ideas/Reviews | 0 | 30th September 2003 11:18 AM |
| need help with random number generator | themikestar | Electronic Projects Design/Ideas/Reviews | 5 | 22nd July 2003 02:31 PM |
| Pulse to binary Number | waqar | Micro Controllers | 0 | 16th May 2003 11:35 AM |