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

Subversion Repositories oms8051mini

[/] [oms8051mini/] [trunk/] [verif/] [sw/] [C/] [fib.c] - Blame information for rev 7

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

Line No. Rev Author Line
1 2 dinesha
/*
2
 * Copyright (c) 1999-2001 Tony Givargis.  Permission to copy is granted
3
 * provided that this header remains intact.  This software is provided
4
 * with no warranties.
5
 *
6
 * Version : 2.9
7
 */
8
 
9
/*---------------------------------------------------------------------------*/
10
 
11
#include <8051.h>
12
 
13
char cErrCnt;
14
/*---------------------------------------------------------------------------*/
15
 
16
void fib(unsigned char* buf, unsigned char n) {
17
 
18
    unsigned char i;
19
 
20
    buf[0] = 1;
21
    buf[1] = 1;
22
    for(i=2; i<n; i++) {
23
 
24
        buf[i] = buf[i-1] + buf[i-2];
25
    }
26
}
27
 
28
/*---------------------------------------------------------------------------*/
29
 
30
void print(unsigned char* buf, unsigned char n) {
31
 
32
    unsigned char i;
33
 
34
    unsigned char exp_buf[10] = {0x1,0x1,0x2,0x3,0x5,0x8,0xd,0x15,0x22,0x37};
35
    for(i=0; i<n; i++) {
36
        P0 = buf[i];
37
        P1 = exp_buf[i];
38
        if(buf[i] != exp_buf[i]) {
39
           cErrCnt++;
40
        }
41
    }
42
    if(cErrCnt !=0) {
43
        P2 = 0x55; // Test Fail
44
        P3 = cErrCnt;
45
 
46
    } else {
47
       P2 = 0xAA; // Test PASS
48
       P3 = 0xAA; // Test PASS
49
    }
50
}
51
 
52
/*---------------------------------------------------------------------------*/
53
 
54
void main() {
55
 
56
    unsigned char buf[10];
57
    cErrCnt = 0;
58
 
59
    fib(buf, 10);
60
    print(buf, 10);
61
    while(1);
62
}

powered by: WebSVN 2.1.0

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