please dont rip this site

microchip baudrate

#include <stdio.h>

const double BaudTable[] = {
	1200,
	2400,
	4800,
	9600,
	14400,
	19200,
	38400,
	57600,
	115200,
	230400};

int within3percent (double baud)
	{
	double	minval, maxval;
	int		retval, i;

	retval = 0;
	for (i = 0; i < 10; i++)
		{
		minval = BaudTable[i] * 0.97;
		maxval = BaudTable[i] * 1.03;

		if ((baud >= minval) && (baud <= maxval))
			retval = 1;
		}
	return (retval);
	}

void main (void)
	{
	int		SPBRG;
	double	temp1;
	int		spbrg0, spbrg1;
	double	baud0, baud1;
	float	OSCILLATOR;

	printf ("Enter the crystal speed (ex: 4 MHz = 4000000):");
	scanf ("%f", &OSCILLATOR);

	printf ("CPU Speed = %7.4f MHz\nSPBRG\t  BRGH=0\t  BRGH=1\n", OSCILLATOR / 1000000);

	for (SPBRG = 255; SPBRG != 0; SPBRG--)
		{
		temp1 = (SPBRG+1.0) * 64.0;
		baud0 = OSCILLATOR / temp1;
		spbrg0 = within3percent (baud0);
		
		temp1 = (SPBRG+1.0) * 16.0;
		baud1 = OSCILLATOR / temp1;
		spbrg1 = within3percent (baud1);

		if ((spbrg0) || (spbrg1))
			{
			printf ("%3d\t", SPBRG);

			if (spbrg0)
				printf ("%9.2f\t", baud0);
			else
				printf ("         \t");
				
			if (spbrg1)
				printf ("%9.2f\n", baud1);
			else
				printf ("\n");
				

//			printf ("%d\t%9.2f%s\t%9.2f%s\n",SPBRG,baud0,((spbrg0)?" OK":" "),baud1,((spbrg1)?" OK":" "));
			}
		}
	}




file: /techref/microchip/baudrate.c, 1KB, , updated: 2000/8/21 12:30, local time: 2009/11/22 16:15,
TOP NEW HELP FIND: 
38.107.191.104:LOG IN
©2009 PLEASE DON'T RIP! DO: LINK / DIGG! / MAKE!

 ©2009 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it!
<A HREF="http://www.piclist.com/techref/microchip/baudrate.c"> microchip baudrate</A>

Did you find what you needed?

 
Stepper motors CAN be smooth!
And stepper controllers can be strong and cheap. Roman Black's Linistep stepper controller kits:
o 18th microstep
o Linear smoothing
  o Open source
o Full kit $25!
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .