-
Notifications
You must be signed in to change notification settings - Fork 0
/
RAM.cpp
87 lines (56 loc) · 1.63 KB
/
RAM.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "RAM.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
//#include <time.h>
static int i;
static int msec;
void RAM::RAM_write( uint16_t addr, uint8_t data )
{
FILE *fp;
fp = fopen("RAM_256x8.dat", "wb+");
Data[addr-6000] = data;
//cout << "The Data of Block " << addr << " of RAM was written by " << "{ " << data << " }" << endl;
printf("The Data of Block %d of RAM was written by { 0x%02X }\r\n\r\n",addr, data);
fwrite( (uint8_t*) Data, sizeof( uint8_t ), 256, fp );
fclose( fp );
///////////////////////////////////////////////
//Delay 5ms
msec = 5;
while(msec--) {
i = 100;
while(i--);
}
////////////////////////////////////////////////
}
uint8_t RAM::RAM_read( uint16_t addr )
{
FILE *fp;
if( ( fp = fopen("RAM_256x8.dat" , "rb" ) ) == NULL )
{
//cout << "Cannot read the values of Weight" << endl;
printf("Cannot read the values of Weight.\r\n");
return ( false );
}
//cout << "The date of Block " << addr << " which was fetch is " << "{ " << Data[addr-6000] << " }" << endl;
fread( (uint8_t*) Data, sizeof(uint8_t), 256, fp );
printf("The Data of Block %d which was fetch is { 0x%02X }.\r\n\r\n", addr, Data[addr-6000]);
fclose( fp );
///////////////////////////////////////////////
//Delay 3ms
msec = 3;
while(msec--) {
i = 100;
while(i--);
}
////////////////////////////////////////////////
return Data[addr-6000];
}
RAM::RAM( uint8_t *data )
{
FILE *fp;
fp = fopen("RAM_256x8.dat", "wb+");
Data = data;
fwrite( (uint8_t*) Data, sizeof( uint8_t ), 256, fp );
fclose( fp );
}