OpenCores
URL https://opencores.org/ocsvn/uart2bus_testbench/uart2bus_testbench/trunk

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [buad_rate_calculation/] [buad_rate_calculations/] [main.cpp] - Blame information for rev 18

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 HanySalah
#include <iostream>
2
 
3
using namespace std;
4
 
5
int gcd_calc (int x, int y);
6
 
7
int main()
8
{
9
    unsigned int gcd_result;
10
    unsigned int buad_rate,buad_freq,global_clock;
11
    cout << "enter buad rate" << endl;
12
    cin >> buad_rate ;
13
    cout << "enter global clock" << endl;
14
    cin >> global_clock ;
15
    gcd_result = gcd_calc(global_clock,(16*buad_rate));
16
    buad_freq = (16*buad_rate)/gcd_result;
17
    cout << "buad_freq = "  << buad_freq << endl;
18
 
19
    return 0;
20
}
21
 
22
int gcd_calc(int x, int y)
23
{
24
    int result =1;
25
    bool break_loop = false;
26
    int div;
27
    div =2;
28
    while (break_loop == false)
29
    {
30
        if ((x%div == 0) && (y%div ==0))
31
        {
32
        result = result*div;
33
        x=x/div;
34
        y=y/div;
35
        }
36
        else
37
        {
38
        div++;
39
        }
40
        if((div > x)|| (div > y))
41
        {
42
            break_loop = true;
43
        }
44
    }
45
    return result;
46
}
47
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.