please dont rip this site

Microchip Baudrate.c

#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 13:30, local time: 2024/4/26 05:10,
TOP NEW HELP FIND: 
3.22.171.136:LOG IN

 ©2024 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! / MAKE!

<A HREF="http://www.piclist.com/techref/microchip/baudrate.c"> microchip baudrate</A>

Did you find what you needed?

  PICList 2024 contributors:
o List host: MIT, Site host massmind.org, Top posters @none found
- Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
 

Welcome to www.piclist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .