comparison code_part1/OSTC_code_asm_part1/spbrgselect.inc @ 0:96a35aeda5f2

Initial setup
author heinrichsweikamp
date Tue, 12 Jan 2010 15:05:59 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:96a35aeda5f2
1 RoundResult SET 0 ; Rounding function. RoundResult = Round(aa/bb)
2
3 Round macro aa,bb
4
5 LOCAL rr = aa/bb
6
7 LOCAL d1 = aa - rr*bb
8
9 LOCAL d2 = (rr+1)*bb - aa
10
11 RoundResult = rr
12
13 if d1 >= d2
14
15 RoundResult++
16
17 endif
18
19 endm
20
21
22
23 AbsResult SET 0
24
25 Abs macro nr
26
27 if nr>=0
28
29 AbsResult = nr
30
31 else
32
33 AbsResult = -nr
34
35 endif
36
37 endm
38
39
40
41 Round xtal,(16*baud)
42
43 spbrg_value EQU RoundResult-1
44
45
46
47 Round xtal,(16*(spbrg_value+1))
48
49 baud_real EQU RoundResult
50
51 Abs(baud_real-baud)
52
53 errpercent EQU AbsResult*100/baud
54
55 if errpercent > 4
56
57 ERROR big error in baudrate: #v(errpercent)%
58
59 endif
60
61 if errpercent >= 2
62
63 messg baudrate not exact: #v(errpercent)%
64
65 endif