annotate code_part1/OSTC_code_asm_part1/spbrgselect.inc @ 379:cf1023a53d0c 64kByte Logbook

clean up
author heinrichsweikamp
date Tue, 14 Jun 2011 19:25:09 +0200
parents 96a35aeda5f2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
1 RoundResult SET 0 ; Rounding function. RoundResult = Round(aa/bb)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
2 Round macro aa,bb
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
3 LOCAL rr = aa/bb
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
4 LOCAL d1 = aa - rr*bb
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
5 LOCAL d2 = (rr+1)*bb - aa
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
6 RoundResult = rr
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
7 if d1 >= d2
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
8 RoundResult++
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
9 endif
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
10 endm
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
11
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
12 AbsResult SET 0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
13 Abs macro nr
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
14 if nr>=0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
15 AbsResult = nr
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
16 else
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
17 AbsResult = -nr
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
18 endif
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
19 endm
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
20
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
21 Round xtal,(16*baud)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
22 spbrg_value EQU RoundResult-1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
23
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
24 Round xtal,(16*(spbrg_value+1))
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
25 baud_real EQU RoundResult
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
26 Abs(baud_real-baud)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
27 errpercent EQU AbsResult*100/baud
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
28 if errpercent > 4
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
29 ERROR big error in baudrate: #v(errpercent)%
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
30 endif
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
31 if errpercent >= 2
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
32 messg baudrate not exact: #v(errpercent)%
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
33 endif