Mercurial > public > mk2
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/code_part1/OSTC_code_asm_part1/spbrgselect.inc Tue Jan 12 15:05:59 2010 +0100 @@ -0,0 +1,33 @@ +RoundResult SET 0 ; Rounding function. RoundResult = Round(aa/bb) +Round macro aa,bb + LOCAL rr = aa/bb + LOCAL d1 = aa - rr*bb + LOCAL d2 = (rr+1)*bb - aa +RoundResult = rr + if d1 >= d2 +RoundResult++ + endif + endm + +AbsResult SET 0 +Abs macro nr + if nr>=0 +AbsResult = nr + else +AbsResult = -nr + endif + endm + + Round xtal,(16*baud) +spbrg_value EQU RoundResult-1 + + Round xtal,(16*(spbrg_value+1)) +baud_real EQU RoundResult + Abs(baud_real-baud) +errpercent EQU AbsResult*100/baud + if errpercent > 4 + ERROR big error in baudrate: #v(errpercent)% + endif + if errpercent >= 2 + messg baudrate not exact: #v(errpercent)% + endif \ No newline at end of file