-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSim.ini
More file actions
135 lines (120 loc) · 3.84 KB
/
Sim.ini
File metadata and controls
135 lines (120 loc) · 3.84 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/******************************************************************************/
/* SIM.INI: Simulator Initialization File */
/******************************************************************************/
/* This file is part of the uVision/ARM development tools. */
/* Copyright (c) 2005-2007 Keil Software. All rights reserved. */
/* This software may only be used under the terms of a valid, current, */
/* end user licence from KEIL for a compatible version of KEIL software */
/* development tools. Nothing else gives you the right to use this software. */
/******************************************************************************/
/*-------------------------------------------------------------------*/
/* Analog0() simulates analog input values given to channel-0 (AD00) */
/*-------------------------------------------------------------------*/
Signal void analog0 (float limit) {
float volts;
printf ("Analog0 (%f) entered.\n", limit);
while (1) { /* forever */
volts = 0;
while (volts <= limit) {
ad00 = volts; /* analog input-0 */
twatch (500000); /* 500000 Cycles Time-Break */
volts += 0.1; /* increase voltage */
}
volts = limit;
while (volts >= 0.0) {
ad00 = volts;
twatch (500000); /* 500000 Cycles Time-Break */
volts -= 0.1; /* decrease voltage */
}
}
}
/*
* Simulate LCD Display (2 line 40 character Text LCD with 4-bit Interface)
* Pins:
* - DB4..DB7 = P1.24..P1.27
* - RS = P1.28
* - RW = P1.29
* - E = P1.31
*/
define unsigned long oldPORT1;
define unsigned char Cursor;
define unsigned char bitpos;
define unsigned char Cmd;
define unsigned long _E;
define unsigned long _RW;
define unsigned long _RS;
define unsigned long _CTRL;
define unsigned long _DATA;
MAP 0x10000000, 0x1000004F READ WRITE // LCD Memory
oldPORT1 = PORT1;
Cursor = 0;
bitpos = 0;
_E = 0x80000000;
_RW = 0x20000000;
_RS = 0x10000000;
_CTRL = 0xB0000000;
_DATA = 0x0F000000;
// Clear Display Function
Func void LCD_Clear (void) {
unsigned char i;
for (i = 0; i < 80; i++) {
_WBYTE(0x10000000 + i, 0x20);
}
Cursor = 0;
}
// LCD Display Signal Function
Signal void LCD_Display (void) {
unsigned char val;
while (1) {
wwatch(PORT1); // Wait for write to PORT1
if ((PORT1 & _RW) == 0) {
// Write to Display
if (((oldPORT1 & _E) != 0) && ((PORT1 & _E) == 0)) {
// E: 1->0
if ((PORT1 & _RS) == 0) {
// Write Command
val = ((PORT1 & _DATA) >> 24);
if (val == 3) {
bitpos = 4;
}
Cmd &= 0xF0 >> bitpos;
Cmd |= val << bitpos;
if (bitpos == 0) {
if (Cmd == 0x01) {
// Clear Display
LCD_Clear();
} else if (Cmd & 0x80) {
// Set Cursor Position
Cursor = Cmd & 0x7F;
}
}
} else {
// Write Data
val = _RBYTE(0x10000000 + Cursor);
val &= 0xF0 >> bitpos;
val |= ((PORT1 & _DATA) >> 24) << bitpos;
_WBYTE(0x10000000 + Cursor, val);
if (bitpos == 0) Cursor++;
}
bitpos ^= 4;
}
} else {
// Read from Display
if (((oldPORT1 & _E) == 0) && ((PORT1 & _E) != 0)) {
// E: 0->1
if ((PORT1 & _RS) == 0) {
// Read Status
val = (0x7F >> bitpos) & 0x0F;
} else {
// Read Pointer
val = ((Cursor & 0x7F) >> bitpos) & 0x0F;
}
PORT1 &= ~_DATA;
PORT1 |= val << 24;
bitpos ^= 4;
}
}
oldPORT1 = PORT1;
}
}
LCD_Display()