??? 05/04/09 00:17 Modified: 05/04/09 00:19 Read: times |
#165028 - Give this a try... Responding to: ???'s previous message |
I have quickly coded the scheme that I have suggested earlier. The code isn't tested, but good enough to experiment with.
To avoid the use of negative and fractional numbers the original scheme was modified: In the calculation of error term all relevant numbers were multiplied by a factor of "2" and an offset equal to "STEPS" was added. Take care that "STEPS" is in the range of "1...64" and that V_INIT <= V_END. ;This code snippet generates a value "V" that runs from "V_INIT" to ;"V_END" in equal steps (V_INIT <= V_END). The number of steps is ;"STEPS" ("STEPS"=1...64). "V" appears at Port P1. ;The code isn't tested! $NOMOD51 $INCLUDE (89s52.mcu) ERR_ADD DATA 30H ERR_COMP DATA 31H ERR_SUM DATA 32H WIDTH DATA 33H STEPS DATA 34H V DATA 35H V_INIT DATA 36H V_END DATA 37H ORG 0 SJMP Start ORG 002BH Start: MOV A,STEPS MOV R7,A ;Prepare Steps_loop MOV ERR_SUM,A ;Initialize ERR_SUM RL A ;Calculate ERR_COMP MOV ERR_COMP,A MOV A,V_END ;Calculate WIDTH: CLR C ;WIDTH = (V_END-V_INIT)/STEPS SUBB A,V_INIT MOV B,STEPS DIV AB MOV WIDTH,A MOV A,B ;Calculate ERR_ADD by the help RL A ;of remainder MOV ERR_ADD,A MOV V,V_INIT ;Initialize V MOV P1,V ;Send V_INIT to P1 Steps_loop: MOV A,V ;Calculate new V: ADD A,WIDTH ;V = V + WIDTH MOV V,A MOV A,ERR_SUM ;Calculate new ERR_SUM ADD A,ERR_ADD CJNE A,ERR_COMP,Cont1 ;ERR_SUM >= ERR_COMP? Cont1: JC Cont2 ;No, so nothing to correct SUBB A,ERR_COMP ;Yes, so increment V INC V ;and correct ERR_SUM Cont2: MOV ERR_SUM,A ;Store the new ERR_SUM MOV P1,V ;Send V to P1 DJNZ R7,Steps_loop ;Do all the steps END ;End of code snippet Kai |
Topic | Author | Date |
Values interpolation | 01/01/70 00:00 | |
A possible start | 01/01/70 00:00 | |
The Brezingham Line Drawing algorithm | 01/01/70 00:00 | |
http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm ? | 01/01/70 00:00 | |
Good method | 01/01/70 00:00 | |
Integer Digital Differential Analyzer | 01/01/70 00:00 | |
Simple scheme... | 01/01/70 00:00 | |
Further optimization | 01/01/70 00:00 | |
You are absolutely right, of course,... | 01/01/70 00:00 | |
Having a hard time trying to understand :( | 01/01/70 00:00 | |
Clarification Needed | 01/01/70 00:00 | |
Even more confused now | 01/01/70 00:00 | |
Another Shot | 01/01/70 00:00 | |
code | 01/01/70 00:00 | |
Provided Code | 01/01/70 00:00 | |
Maybe this | 01/01/70 00:00 | |
Give this a try... | 01/01/70 00:00 | |
Look it up | 01/01/70 00:00 | |
Now, we have a hard time to understand... | 01/01/70 00:00 |