aboutsummaryrefslogtreecommitdiff
path: root/demo/src
diff options
context:
space:
mode:
Diffstat (limited to 'demo/src')
-rw-r--r--demo/src/execute.ts8
-rw-r--r--demo/src/index.css4
-rw-r--r--demo/src/index.html1
-rw-r--r--demo/src/index.ts7
4 files changed, 19 insertions, 1 deletions
diff --git a/demo/src/execute.ts b/demo/src/execute.ts
index 4568839..f2c7d82 100644
--- a/demo/src/execute.ts
+++ b/demo/src/execute.ts
@@ -4,9 +4,11 @@ import {
CPU,
timer0Config,
AVRIOPort,
+ AVRUSART,
portBConfig,
portCConfig,
- portDConfig
+ portDConfig,
+ usart0Config
} from 'avr8js';
import { loadHex } from './intelhex';
@@ -20,6 +22,8 @@ export class AVRRunner {
readonly portB: AVRIOPort;
readonly portC: AVRIOPort;
readonly portD: AVRIOPort;
+ readonly usart: AVRUSART;
+ readonly speed = 16e6; // 16 MHZ
private stopped = false;
@@ -30,6 +34,7 @@ export class AVRRunner {
this.portB = new AVRIOPort(this.cpu, portBConfig);
this.portC = new AVRIOPort(this.cpu, portCConfig);
this.portD = new AVRIOPort(this.cpu, portDConfig);
+ this.usart = new AVRUSART(this.cpu, usart0Config, this.speed);
}
async execute(callback: (cpu: CPU) => void) {
@@ -37,6 +42,7 @@ export class AVRRunner {
for (;;) {
avrInstruction(this.cpu);
this.timer.tick();
+ this.usart.tick();
if (this.cpu.cycles % 50000 === 0) {
callback(this.cpu);
await new Promise((resolve) => setTimeout(resolve, 0));
diff --git a/demo/src/index.css b/demo/src/index.css
index a3fa8b8..6801204 100644
--- a/demo/src/index.css
+++ b/demo/src/index.css
@@ -46,3 +46,7 @@ body {
margin: 0;
white-space: pre-line;
}
+
+#serial-output-text {
+ color: blue;
+}
diff --git a/demo/src/index.html b/demo/src/index.html
index 935bcff..2a8e924 100644
--- a/demo/src/index.html
+++ b/demo/src/index.html
@@ -20,6 +20,7 @@
<div class="code-editor"></div>
<div class="compiler-output">
<pre id="compiler-output-text"></pre>
+ <pre id="serial-output-text"></pre>
</div>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.18.0/min/vs/loader.js"></script>
diff --git a/demo/src/index.ts b/demo/src/index.ts
index e51cbbc..7b6f9b1 100644
--- a/demo/src/index.ts
+++ b/demo/src/index.ts
@@ -10,10 +10,12 @@ const BLINK_CODE = `
// Red LED connected to pin 12. Enjoy!
void setup() {
+ Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
+ Serial.println("Blink");
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
@@ -50,6 +52,7 @@ const stopButton = document.querySelector('#stop-button');
stopButton.addEventListener('click', stopCode);
const statusLabel = document.querySelector('#status-label');
const compilerOutputText = document.querySelector('#compiler-output-text');
+const serialOutputText = document.querySelector('#serial-output-text');
function executeProgram(hex: string) {
runner = new AVRRunner(hex);
@@ -62,6 +65,9 @@ function executeProgram(hex: string) {
led12.value = value & D12bit ? true : false;
led13.value = value & D13bit ? true : false;
});
+ runner.usart.onByteTransmit = (value) => {
+ serialOutputText.textContent += String.fromCharCode(value);
+ };
runner.execute((cpu) => {
const time = formatTime(cpu.cycles / MHZ);
statusLabel.textContent = 'Simulation time: ' + time;
@@ -73,6 +79,7 @@ async function compileAndRun() {
led13.value = false;
runButton.setAttribute('disabled', '1');
+ serialOutputText.textContent = '';
try {
statusLabel.textContent = 'Compiling...';
const result = await buildHex(editor.getModel().getValue());
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.