Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //
- // after http://wormfood.net/avrbaudcalc
- // reprogrammed by Uwe Zimmermann, 2019-11-17
- //
- function bg_color($err = 0)
- {
- if (abs($err) < 0.1)
- {
- $bg = "#51ff00";
- }
- else
- {
- if (abs($err)<=1)
- {
- $bg = "#42cc02";
- }
- else
- {
- if (abs($err)<=2)
- {
- $bg = "#00990a";
- }
- else
- {
- if (abs($err)<=3)
- {
- $bg = "#fff71c";
- }
- else
- {
- if (abs($err)<=4)
- {
- $bg = "#ff9d1c";
- }
- else
- {
- $bg = "#ff1c1c";
- }
- }
- }
- }
- }
- return $bg;
- }
- function wormfood_table($F_CPU=16000000)
- {
- $i = 0;
- $baud=array(300,600,1200,2400,4800,9600,14400,19200,28800,57600,76800,115200,128000,230400,256000);
- echo "<table border=\"1px\">";
- $FCPU = number_format ( $F_CPU , 0 , '.' , ' ' );
- printf("<tr><th colspan=\"7\" style=\"text-align:center\"><i>f<sub>osc</sub></i> = %s Hz</th></tr>",$FCPU);
- echo "<tr><th colspan=\"1\" rowspan=\"2\">nominal Bit rate</th><th colspan=\"3\">U2Xn=0</th><th colspan=\"3\">U2Xn=1</th></tr>";
- echo "<tr><th>UBRR</th><th>actual Bit rate</th><th>error</th><th>UBRR</th><th>actual Bit rate</th><th>error</th></tr>";
- for ($i=0;$i<count($baud);$i++)
- {
- $UBRR = round(($F_CPU / (16 * $baud[$i])) -1);
- $UBRR2x = round(($F_CPU / (8 * $baud[$i])) -1);
- if ($UBRR < 0)
- {
- $UBRR = 0;
- }
- if ($UBRR2x < 0)
- {
- $UBRR2x = 0;
- }
- $realbaud = round(($F_CPU/16)/($UBRR+1));
- $err = 100*($realbaud-$baud[$i])/$baud[$i];
- $realbaud2x = round(($F_CPU/8)/($UBRR2x+1));
- $err2x = 100*($realbaud2x-$baud[$i])/$baud[$i];
- echo "<tr><td style=\"text-align=right;\">$baud[$i]</td>";
- if ($UBRR > 4095)
- {
- $bg = "#c7c7c7";
- }
- else
- {
- $bg = bg_color($err);
- }
- printf("<td style=\"background-color:%s;text-align=right;\">%d</td><td style=\"background-color:%s;text-align=right;\">%d</td><td style=\"background-color:%s;text-align=right;\">%.1f%%</td>",$bg,$UBRR,$bg,$realbaud,$bg,$err);
- if (($UBRR2x > 4095) or ($UBRR2x < 0))
- {
- $bg = "#c7c7c7";
- }
- else
- {
- $bg = bg_color($err2x);
- }
- printf("<td style=\"background-color:%s;text-align=right;\">%d</td><td style=\"background-color:%s;text-align=right;\">%d</td><td style=\"background-color:%s;text-align=right;\">%.1f%%</td>",$bg,$UBRR2x,$bg,$realbaud2x,$bg,$err2x);
- echo "</tr>";
- }
- echo "</table>";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement