finished lab7 and homeworks

This commit is contained in:
Ziad Arafat committed 2020-05-01 13:26:46 -06:00
1 parent 18c00bb1bd
commit da1dba3941
16 files changed
+1560

No files matched your search

+97
View File
@@ -0,0 +1,97 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>HW 10 CS 273 Ziad Arafat</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/markdown.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/highlight.css">
<style>
.task-list-item { list-style-type: none; } .task-list-item-checkbox { margin-left: -20px; vertical-align: middle; }
</style>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe WPC', 'Segoe UI', 'Ubuntu', 'Droid Sans', sans-serif;
font-size: 14px;
line-height: 1.6;
}
</style>
</head>
<body class="vscode-light">
<h1 id="hw-10-cs-273-ziad-arafat">HW 10 CS 273 Ziad Arafat</h1>
<ol>
<li>
<p>If the input clock source operates at 16 MHz, what is the TCNT1 value needed to generate a time delay of 0.5 millisecond in normal mode?</p>
<ul>
<li>16, 000, 000 clk/sec * 0.0005sec = 8000clk</li>
<li>2^16 - 8000 = 0xE0C0</li>
</ul>
</li>
<li>
<p>If the clock operates at 10 MHz, what is the OCR0 value needed to generate time delay of 4 microseconds in CTC mode without any prescaler.</p>
<ul>
<li>10 million clocks/sec 0.000004 seconds</li>
<li>40 clocks</li>
<li>Value of 39</li>
</ul>
</li>
<li>
<p>Write an assembly program for Timer1 to generate a square wave of 16000 Hz to output on PB3 using a clock frequency of 16 MHz.</p>
</li>
</ol>
<pre><code><code><div>16 million clk/sec = 16000 clks/sec * n
n = 1000
1000/2 = 500
500 off
500 on
</div></code></code></pre>
<pre><code><code><div>sbi ddrb, 5 // pb5 as an output
start:
sbi portb, 3 // pb3 = 1
rcall 500delay
cbi portb, 3 // pb3 = 0
rcall 500delay
jmp start
500delay:
ldi r20, 0x01
out tcnt1h, r20 // temp = 0xd8
ldi r20, 0xf8
out tcnt1l, r20 // tcnt1l = 0xf0, tcnt1h = temp
ldi r20, 0x0
out tccr1a, r20 // wgm11:10=00
ldi r20, 0x1
out tccr1b, r20 // wgm13:12=00, cs=clk
loop:
in r20, tifr1 // read tifr1
sbrs r20, tov1 // if tov1 is set skip next instruction
jmp loop
ldi r20, 1&lt;&lt;tov1
out tifr1, r20 // clear tov1 flag
ldi r19, 0
out tccr1b, r19 // stop timer
out tccr1a, r19 //
ret
</div></code></code></pre>
<ol start="4">
<li>
<p>What is the advantage of using falling/rising edges instead of high/low voltages to detect events?</p>
<ul>
<li>So we can catch an event we are listening for. If we only look at 2 values we might not catch it.</li>
</ul>
</li>
<li>
<p>What is the signal the following code generates at PORTB pin 5? If it is a periodical signal, what is its period? The clock frequency is 16MHz.</p>
</li>
</ol>
<pre><code><code><div>0x100 - 3B = 256 - 59 = 197 = 210 clks off and 210 clks on
420 clks ;; nice
</div></code></code></pre>
</body>
</html>
+63
View File
@@ -0,0 +1,63 @@
# HW 10 CS 273 Ziad Arafat
1. If the input clock source operates at 16 MHz, what is the TCNT1 value needed to generate a time delay of 0.5 millisecond in normal mode?
- 16, 000, 000 clk/sec * 0.0005sec = 8000clk
- 2^16 - 8000 = 0xE0C0
2. If the clock operates at 10 MHz, what is the OCR0 value needed to generate time delay of 4 microseconds in CTC mode without any prescaler.
- 10 million clocks/sec 0.000004 seconds
- 40 clocks
- Value of 39
3. Write an assembly program for Timer1 to generate a square wave of 16000 Hz to output on PB3 using a clock frequency of 16 MHz.
```
16 million clk/sec = 16000 clks/sec * n
n = 1000
1000/2 = 500
500 off
500 on
```
```
sbi ddrb, 5 // pb5 as an output
start:
sbi portb, 3 // pb3 = 1
rcall 500delay
cbi portb, 3 // pb3 = 0
rcall 500delay
jmp start
500delay:
ldi r20, 0x01
out tcnt1h, r20 // temp = 0xd8
ldi r20, 0xf8
out tcnt1l, r20 // tcnt1l = 0xf0, tcnt1h = temp
ldi r20, 0x0
out tccr1a, r20 // wgm11:10=00
ldi r20, 0x1
out tccr1b, r20 // wgm13:12=00, cs=clk
loop:
in r20, tifr1 // read tifr1
sbrs r20, tov1 // if tov1 is set skip next instruction
jmp loop
ldi r20, 1<<tov1
out tifr1, r20 // clear tov1 flag
ldi r19, 0
out tccr1b, r19 // stop timer
out tccr1a, r19 //
ret
```
4. What is the advantage of using falling/rising edges instead of high/low voltages to detect events?
- So we can catch an event we are listening for. If we only look at 2 values we might not catch it.
5. What is the signal the following code generates at PORTB pin 5? If it is a periodical signal, what is its period? The clock frequency is 16MHz.
```
0x100 - 3B = 256 - 59 = 197 = 210 clks off and 210 clks on
420 clks ;; nice
```
+101
View File
@@ -0,0 +1,101 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CS 273 HW 11 - Ziad Arafat</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/markdown.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/highlight.css">
<style>
.task-list-item { list-style-type: none; } .task-list-item-checkbox { margin-left: -20px; vertical-align: middle; }
</style>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe WPC', 'Segoe UI', 'Ubuntu', 'Droid Sans', sans-serif;
font-size: 14px;
line-height: 1.6;
}
</style>
</head>
<body class="vscode-light">
<h1 id="cs-273-hw-11---ziad-arafat">CS 273 HW 11 - Ziad Arafat</h1>
<ol>
<li>
<p><strong>The addresses are.</strong></p>
<ul>
<li>TCNT0 = 0x26 (0x46)</li>
<li>TCCR0A = 0x24 (0x44)</li>
<li>TCCR0B = 0x25 (0x45)</li>
<li>OCR0A = 0x27 (0x47)</li>
<li>OCR0B = 0x28 (0x48)</li>
<li>TIMSK0 = (0x6E)</li>
<li>TCNT1H = (0x85)</li>
<li>TCNT1L = (0x84)</li>
<li>TCCR1A = (0x80)</li>
<li>TCCR1B = (0x81)</li>
<li>TCCR1C = (0x82)</li>
<li>OCR1AH = (0x89)</li>
<li>OCR1AL = (0x88)</li>
<li>OCR1BH = (0x8B)</li>
<li>OCR1BL = (0x8A)</li>
<li>TIMSK1 = (0x6F)</li>
<li>TCNT2 = (0xB2)</li>
<li>TCCR2A = (0xB0)</li>
<li>TCCR2B = (0xB1)</li>
<li>OCR2A = (0xB3)</li>
<li>OCR2B = (0xB4)</li>
<li>TIMSK2 = (0x70)</li>
</ul>
</li>
<li>
<p><strong>Read Section 14 Interrupts and Timers of the booklet and answer the following questions.</strong></p>
<ol>
<li>We can utilize resources more efficiently so our CPU doesn't have to constantly listen for a signal. Instead we offload it to a dedicated device.</li>
<li>An array of addresses indicating the address of the code that should be executed corresponding to an interrupt signal.</li>
<li>Because we need to ensure that none of the registers have changed in the meantime.</li>
<li>CODE:</li>
</ol>
</li>
</ol>
<p><strong>C Code</strong></p>
<pre><code class="language-c"><div><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">"avr/io.h"</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">"avr/interrupt.h"</span></span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">isr</span><span class="hljs-params">(<span class="hljs-built_in">vector</span>)</span> </span>{
byte *a = <span class="hljs-number">0x200</span>;
byte *b = <span class="hljs-number">0x201</span>;
<span class="hljs-keyword">if</span> (*a == <span class="hljs-number">255</span>) {
*a = <span class="hljs-number">0</span>;
*b++;
} <span class="hljs-keyword">else</span>{
*a++;
}
}
</div></code></pre>
<p><strong>ASM code</strong></p>
<pre><code class="language-avrasm"><div><span class="hljs-symbol">timer2b:</span>
<span class="hljs-keyword">push</span> <span class="hljs-built_in">r20</span>
<span class="hljs-keyword">in</span> <span class="hljs-built_in">r20</span>, <span class="hljs-built_in">sreg</span>
<span class="hljs-keyword">push</span> <span class="hljs-built_in">r20</span>
<span class="hljs-keyword">push</span> <span class="hljs-built_in">r21</span>
<span class="hljs-keyword">clr</span> <span class="hljs-built_in">r21</span>
<span class="hljs-keyword">lds</span> <span class="hljs-built_in">r20</span>, <span class="hljs-number">0x200</span>
<span class="hljs-keyword">inc</span> <span class="hljs-built_in">r20</span>
<span class="hljs-keyword">sts</span> <span class="hljs-number">0x200</span>, <span class="hljs-built_in">r20</span>
<span class="hljs-keyword">lds</span> <span class="hljs-built_in">r20</span>, <span class="hljs-number">0x201</span>
<span class="hljs-keyword">adc</span> <span class="hljs-built_in">r20</span>, <span class="hljs-built_in">r21</span>
<span class="hljs-keyword">sts</span> <span class="hljs-number">0x201</span>, <span class="hljs-built_in">r20</span>
<span class="hljs-keyword">pop</span> <span class="hljs-built_in">r21</span>
<span class="hljs-keyword">pop</span> <span class="hljs-built_in">r20</span>
<span class="hljs-keyword">out</span> <span class="hljs-built_in">sreg</span>, <span class="hljs-built_in">r20</span>
<span class="hljs-keyword">pop</span> <span class="hljs-built_in">r20</span>
</div></code></pre>
</body>
</html>
+72
View File
@@ -0,0 +1,72 @@
# CS 273 HW 11 - Ziad Arafat
1. **The addresses are.**
- TCNT0 = 0x26 (0x46)
- TCCR0A = 0x24 (0x44)
- TCCR0B = 0x25 (0x45)
- OCR0A = 0x27 (0x47)
- OCR0B = 0x28 (0x48)
- TIMSK0 = (0x6E)
- TCNT1H = (0x85)
- TCNT1L = (0x84)
- TCCR1A = (0x80)
- TCCR1B = (0x81)
- TCCR1C = (0x82)
- OCR1AH = (0x89)
- OCR1AL = (0x88)
- OCR1BH = (0x8B)
- OCR1BL = (0x8A)
- TIMSK1 = (0x6F)
- TCNT2 = (0xB2)
- TCCR2A = (0xB0)
- TCCR2B = (0xB1)
- OCR2A = (0xB3)
- OCR2B = (0xB4)
- TIMSK2 = (0x70)
2. **Read Section 14 Interrupts and Timers of the booklet and answer the following questions.**
1. We can utilize resources more efficiently so our CPU doesn't have to constantly listen for a signal. Instead we offload it to a dedicated device.
2. An array of addresses indicating the address of the code that should be executed corresponding to an interrupt signal.
3. Because we need to ensure that none of the registers have changed in the meantime.
4. CODE:
**C Code**
```c
#include "avr/io.h"
#include "avr/interrupt.h"
void isr(vector) {
byte *a = 0x200;
byte *b = 0x201;
if (*a == 255) {
*a = 0;
*b++;
} else{
*a++;
}
}
```
**ASM code**
```avrasm
timer2b:
push r20
in r20, sreg
push r20
push r21
clr r21
lds r20, 0x200
inc r20
sts 0x200, r20
lds r20, 0x201
adc r20, r21
sts 0x201, r20
pop r21
pop r20
out sreg, r20
pop r20
```
+166
View File
@@ -0,0 +1,166 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/markdown.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/highlight.css">
<style>
.task-list-item { list-style-type: none; } .task-list-item-checkbox { margin-left: -20px; vertical-align: middle; }
</style>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe WPC', 'Segoe UI', 'Ubuntu', 'Droid Sans', sans-serif;
font-size: 14px;
line-height: 1.6;
}
</style>
</head>
<body class="vscode-light">
<ol>
<li>Convert to binary</li>
</ol>
<pre><code><code><div>LDI 1110-KKKK-dddd-KKKK
INC 1001-010d-dddd-0011
BRNE 1111-01kk-kkkk-k001
DEC 1001-010d-dddd-1010
ST,Y 1000-001r-rrrr-1000
0. LDI R19, 0x5
1110-0000-0011-0101 = 0xE035
1. LDI R16, 0x55
1110-0101-0000-0101 = 0xE505
2. LDI YL, 0x40
1110-0100-1100-0000 = 0xE4C0
3. LDI YH, 0x1
1110-0000-1101-0001 = 0xE0D1
4. L1: ST Y, R16
1000-0011-0000-1000 = 0x8308
5. INC YL
1001-0101-1100-0011 = 0x95C3
6. DEC R20
1001-0101-0011-1010 = 0x953A
7. BRNE L1
1111-01kk-kkkk-k001
1111-0111-1110-0001 = 0xF7E1
We need -4
0000100 = 4
1111011 = 1’s comp of 4
1111100 = 2’s comp of 4
0. 35
E0
1. 05
E5
2. C0
E4
3. D1
E0
4. 08
83
5. C3
95
6. 3A
95
7. E1
F7
</div></code></code></pre>
<ol start="2">
<li>Convert to binary.</li>
</ol>
<pre><code><code><div>LDI 1110-KKKK-dddd-KKKK
LPMZ+ 1001-000d-dddd-0101
CPI 0011-KKKK-dddd-KKKK
BREQ 1111-00kk-kkkk-k001
ST,X+ 1001-001r-rrrr-1101
RJMP 1100-kkkk-kkkk-kkkk
LDI ZL, lo8(MYDATA) ;R30 = 00 low-byte address
1110-0000-1110-0000 = E0E0
LDI ZH, hi8(MYDATA) ;R31 = 05, high-byte address
1110-0000-1111-0101 = E0F5
LDI XL, lo8(0x140) ;R26 = 40, low-byte RAM address
1110-0100-1010-0000 E4A0
LDI XH, hi8(0x140) ;R27 = 1, high-byte RAM address
1110-0000-1011-0001 E0B1
AGAIN:
LPM R16, Z+ ;read the table, then increment Z
LPMZ+ 1001-000d-dddd-0101
1001-0001-0000-0101 9105
CPI R16,0 ;compare R16 with 0
CPI 0011-KKKK-dddd-KKKK
0011-0000-0000-0000 3000
1. BREQ END ;exit if end of string
BREQ 1111-00kk-kkkk-k001
1111-0000-0001-0001 F011
2. ST X+, R16 ;store R16 in RAM and inc X
ST,X+ 1001-001r-rrrr-1101
1001-0011-0000-1101 930D
END:
8. RJMP AGAIN
RJMP 1100-kkkk-kkkk-kkkk
1100-1111-1111-1011 CFFB
Convert -5
0000101
1111010
1111011 = -5
-5 in 16 bit
1111-1111-1111-1011
0000-0000-0000-0100 1s comp
0000-0000-0000-0101 = 5
9. END: RJMP END
RJMP 1100-kkkk-kkkk-kkkk
1100-1111-1111-1111
CFFF
1. E0
E0
2. F5
E0
3. A0
E4
4. B1
E0
5. 05
91
6. 00
30
7. 11
F0
8. 0D
93
9. FB
CF
10.FF
CF
</div></code></code></pre>
</body>
</html>
+167
View File
@@ -0,0 +1,167 @@
1. Convert to binary
```
LDI 1110-KKKK-dddd-KKKK
INC 1001-010d-dddd-0011
BRNE 1111-01kk-kkkk-k001
DEC 1001-010d-dddd-1010
ST,Y 1000-001r-rrrr-1000
0. LDI R19, 0x5
1110-0000-0011-0101 = 0xE035
1. LDI R16, 0x55
1110-0101-0000-0101 = 0xE505
2. LDI YL, 0x40
1110-0100-1100-0000 = 0xE4C0
3. LDI YH, 0x1
1110-0000-1101-0001 = 0xE0D1
4. L1: ST Y, R16
1000-0011-0000-1000 = 0x8308
5. INC YL
1001-0101-1100-0011 = 0x95C3
6. DEC R20
1001-0101-0011-1010 = 0x953A
7. BRNE L1
1111-01kk-kkkk-k001
1111-0111-1110-0001 = 0xF7E1
We need -4
0000100 = 4
1111011 = 1’s comp of 4
1111100 = 2’s comp of 4
0. 35
E0
1. 05
E5
2. C0
E4
3. D1
E0
4. 08
83
5. C3
95
6. 3A
95
7. E1
F7
```
2. Convert to binary.
```
LDI 1110-KKKK-dddd-KKKK
LPMZ+ 1001-000d-dddd-0101
CPI 0011-KKKK-dddd-KKKK
BREQ 1111-00kk-kkkk-k001
ST,X+ 1001-001r-rrrr-1101
RJMP 1100-kkkk-kkkk-kkkk
LDI ZL, lo8(MYDATA) ;R30 = 00 low-byte address
1110-0000-1110-0000 = E0E0
LDI ZH, hi8(MYDATA) ;R31 = 05, high-byte address
1110-0000-1111-0101 = E0F5
LDI XL, lo8(0x140) ;R26 = 40, low-byte RAM address
1110-0100-1010-0000 E4A0
LDI XH, hi8(0x140) ;R27 = 1, high-byte RAM address
1110-0000-1011-0001 E0B1
AGAIN:
LPM R16, Z+ ;read the table, then increment Z
LPMZ+ 1001-000d-dddd-0101
1001-0001-0000-0101 9105
CPI R16,0 ;compare R16 with 0
CPI 0011-KKKK-dddd-KKKK
0011-0000-0000-0000 3000
1. BREQ END ;exit if end of string
BREQ 1111-00kk-kkkk-k001
1111-0000-0001-0001 F011
2. ST X+, R16 ;store R16 in RAM and inc X
ST,X+ 1001-001r-rrrr-1101
1001-0011-0000-1101 930D
END:
8. RJMP AGAIN
RJMP 1100-kkkk-kkkk-kkkk
1100-1111-1111-1011 CFFB
Convert -5
0000101
1111010
1111011 = -5
-5 in 16 bit
1111-1111-1111-1011
0000-0000-0000-0100 1s comp
0000-0000-0000-0101 = 5
9. END: RJMP END
RJMP 1100-kkkk-kkkk-kkkk
1100-1111-1111-1111
CFFF
1. E0
E0
2. F5
E0
3. A0
E4
4. B1
E0
5. 05
91
6. 00
30
7. 11
F0
8. 0D
93
9. FB
CF
10.FF
CF
500.0x54
0x68
0x65
0x20
0x50
0x72
0x6f
0x6d
0x69
0x73
0x65
0x20
0x6f
0x66
0x20
0x57
0x6f
0x72
0x6c
0x64
0x20
0x50
0x65
0x61
0x63
0x65
```
Do you view esports as a potential asset? How do you personally think esports could benefit the university's image?
+159
View File
@@ -0,0 +1,159 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.2/dist/katex.min.css" integrity="sha384-yFRtMMDnQtDRO8rLpMIKrtPCD5jdktao2TV19YiZYWMDkUR5GQZR/NOVTdquEx1j" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/markdown.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/highlight.css">
<link href="https://cdn.jsdelivr.net/npm/katex-copytex@latest/dist/katex-copytex.min.css" rel="stylesheet" type="text/css">
<style>
.task-list-item { list-style-type: none; } .task-list-item-checkbox { margin-left: -20px; vertical-align: middle; }
</style>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe WPC', 'Segoe UI', 'Ubuntu', 'Droid Sans', sans-serif;
font-size: 14px;
line-height: 1.6;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/katex-copytex@latest/dist/katex-copytex.min.js"></script>
</head>
<body class="vscode-light">
<ol>
<li>as follows</li>
</ol>
<pre><code><code><div>0x0100: 0010-0001-1110-0000 1110-kkkk-dddd-kkkk
1110-0000-0010-0001 =&gt; ldi r18, 0x01
0x0101: 0011-0001-1110-0000
1110-0000-0011-0001 =&gt; ldi r19, 0x01
0x0102: 0100-1000-1110-0000
1110-0000-0100-1000 =&gt; ldi r20, 0x08
0x0103: 0011-0010-0000-1111 0000-11rd-dddd-rrrr
l1: 0000-1111-0011-0010 =&gt; add r19, r18
0x0104: 0010-0011-0010-1111 0010-11rd-dddd-rrrr
0010-1111-0010-0011 =&gt; mov r18, r19
0x0105: 0100-1010-1001-0101 1001-010d-dddd-1010
1001-0101-0100-1010 =&gt; dec r20
0x0106: 1110-0001-1111-0111 1111-01kk-kkkk-k001
1111-0111-1110-0001 =&gt; brne l1 (111100)
000011 =&gt; 000100
</div></code></code></pre>
<ol start="2">
<li>indicate the value loaded into r30, r31, and r20 in the following program:</li>
</ol>
<pre><code><code><div>.org 0x0
ldi r30, lo8(our_data )
ldi r31, hi8(our_data)
lpm r20, z
.org 0x0524
our_data: .byte 20, ‘$’, ‘5’
</div></code></code></pre>
<pre><code><code><div>r30 = 0x24
r31 = 0x05
r20 = 0x14
</div></code></code></pre>
<ol start="3">
<li>write a program to read the following message from program rom and place it in data ram starting at 0x200:</li>
</ol>
<pre><code><code><div>.org 0x0500
mydata: .asciz “will artificial intelligence rule human?”
.text
entry:
ldi r31, hi8(mydata)
ldi r30, lo8(mydata)
ldi r29, hi8(0x200)
ldi r28, lo8(0x200)
loop:
lpm r16, z+
st y+, r16
cpi r16, 0
brne loop
ret
.org 0x500
mydata: .asciz “will artificial intelligence rule human?”
</div></code></code></pre>
<ol start="4">
<li>write a program that calculates the checksum of the values at location 0x00d5 to 0x0300 of eeprom.</li>
</ol>
<pre><code><code><div>ldi r18, hi8(0x00d5) // load hi bit
ldi r17, lo8(0x00d5) // load low bit
clr r19 // clear two registers.
clr r20
loop:
sbic eecr, eewe // is the eeprom available?
rjmp loop // repeat if it's not ready yet.
out eearh, r18
out eearl, r17
sbi eecr, eere // open eeprom
in r16, eedr
add r19, r16
inc r17
adc r18, r20
cpi r18, 0x03 // we know that r18 will be 0x03 once after we covered all the num
brne loop
// r19 contains the sum of the data
neg r19 // r19 should now make it zero if it's not corrupted
</div></code></code></pre>
<ol start="5">
<li>Checksums</li>
</ol>
<pre><code><code><div>(a) Data=$62, $F3, and $15; checksum=$72
$62
$F3
$15
$72
$1 DC
CORRUPTED
</div></code></code></pre>
<pre><code><code><div>(b) Data=$50, $88, $3C, and $8E; checksum=$6D
$50
$88
$3C
$8E
$6D
= 2 OF
NOT CORRUPTED
</div></code></code></pre>
<pre><code><code><div>(c) Data=0, 0, 0, 0, 0, 0; checksum=0
0
0
NOT CORRUPTED
</div></code></code></pre>
<pre><code><code><div>(d) Data=1,-1,1,-1,1,-1; checksum=1
1
-1
1
-1
1
-1
1
= 1
CORRUPTED DATA
</div></code></code></pre>
</body>
</html>
+140
View File
@@ -0,0 +1,140 @@
1. as follows
```
0x0100: 0010-0001-1110-0000 1110-kkkk-dddd-kkkk
1110-0000-0010-0001 => ldi r18, 0x01
0x0101: 0011-0001-1110-0000
1110-0000-0011-0001 => ldi r19, 0x01
0x0102: 0100-1000-1110-0000
1110-0000-0100-1000 => ldi r20, 0x08
0x0103: 0011-0010-0000-1111 0000-11rd-dddd-rrrr
l1: 0000-1111-0011-0010 => add r19, r18
0x0104: 0010-0011-0010-1111 0010-11rd-dddd-rrrr
0010-1111-0010-0011 => mov r18, r19
0x0105: 0100-1010-1001-0101 1001-010d-dddd-1010
1001-0101-0100-1010 => dec r20
0x0106: 1110-0001-1111-0111 1111-01kk-kkkk-k001
1111-0111-1110-0001 => brne l1 (111100)
000011 => 000100
```
2. indicate the value loaded into r30, r31, and r20 in the following program:
```
.org 0x0
ldi r30, lo8(our_data )
ldi r31, hi8(our_data)
lpm r20, z
.org 0x0524
our_data: .byte 20, ‘$’, ‘5’
```
```
r30 = 0x24
r31 = 0x05
r20 = 0x14
```
3. write a program to read the following message from program rom and place it in data ram starting at 0x200:
```
.org 0x0500
mydata: .asciz “will artificial intelligence rule human?”
.text
entry:
ldi r31, hi8(mydata)
ldi r30, lo8(mydata)
ldi r29, hi8(0x200)
ldi r28, lo8(0x200)
loop:
lpm r16, z+
st y+, r16
cpi r16, 0
brne loop
ret
.org 0x500
mydata: .asciz “will artificial intelligence rule human?”
```
4. write a program that calculates the checksum of the values at location 0x00d5 to 0x0300 of eeprom.
```
ldi r18, hi8(0x00d5) // load hi bit
ldi r17, lo8(0x00d5) // load low bit
clr r19 // clear two registers.
clr r20
loop:
sbic eecr, eewe // is the eeprom available?
rjmp loop // repeat if it's not ready yet.
out eearh, r18
out eearl, r17
sbi eecr, eere // open eeprom
in r16, eedr
add r19, r16
inc r17
adc r18, r20
cpi r18, 0x03 // we know that r18 will be 0x03 once after we covered all the num
brne loop
// r19 contains the sum of the data
neg r19 // r19 should now make it zero if it's not corrupted
```
5. Checksums
```
(a) Data=$62, $F3, and $15; checksum=$72
$62
$F3
$15
$72
$1 DC
CORRUPTED
```
```
(b) Data=$50, $88, $3C, and $8E; checksum=$6D
$50
$88
$3C
$8E
$6D
= 2 OF
NOT CORRUPTED
```
```
(c) Data=0, 0, 0, 0, 0, 0; checksum=0
0
0
NOT CORRUPTED
```
```
(d) Data=1,-1,1,-1,1,-1; checksum=1
1
-1
1
-1
1
-1
1
= 1
CORRUPTED DATA
```
+1
View File
@@ -0,0 +1 @@
out 0x04, 0x20
+8
View File
@@ -0,0 +1,8 @@
[A, G, B, I, F, C, H, D, E]
[A, G, B, I, F, H, C, D, E]
[A, G, I, B, F, C, H, D, E]
[A, G, I, B, F, H, C, D, E]
[A, I, G, B, F, C, H, D, E]
[A, I, G, B, F, H, C, D, E]
[I, A, G, B, F, C, H, D, E]
[I, A, G, B, F, H, C, D, E]
+14
View File
@@ -0,0 +1,14 @@
#include "avr/io.h"
#include "avr/interrupt.h"
ISR(TIMER2_COMPB_vect) //ISR for Timer2 compar B {
byte *a = 0x200;
byte *b = 0x201;
if (*B1 == 255) {
*B1 = 0;
*B2++;
} else{
*B1++;
}
}
View File
Whitespace-only changes.
Binary file not shown.
+502
View File
@@ -0,0 +1,502 @@
# SPDX-License-Identifier: GPL-2.0
#
# clang-format configuration file. Intended for clang-format >= 4.
#
# For more information, see:
#
# Documentation/process/clang-format.rst
# https://clang.llvm.org/docs/ClangFormat.html
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
#
---
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
#AlignEscapedNewlines: Left # Unknown to clang-format-4.0
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
#AfterExternBlock: false # Unknown to clang-format-5.0
BeforeCatch: false
BeforeElse: false
IndentBraces: false
#SplitEmptyFunction: true # Unknown to clang-format-4.0
#SplitEmptyRecord: true # Unknown to clang-format-4.0
#SplitEmptyNamespace: true # Unknown to clang-format-4.0
BreakBeforeBinaryOperators: None
#BreakBeforeInheritanceComma: false # Unknown to clang-format-4.0
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
#BreakConstructorInitializers: BeforeComma # Unknown to clang-format-4.0
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
#CompactNamespaces: false # Unknown to clang-format-4.0
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 5
ContinuationIndentWidth: 5
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
#FixNamespaceComments: false # Unknown to clang-format-4.0
# Taken from:
# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' include/ \
# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
# | sort | uniq
ForEachMacros:
- 'apei_estatus_for_each_section'
- 'ata_for_each_dev'
- 'ata_for_each_link'
- '__ata_qc_for_each'
- 'ata_qc_for_each'
- 'ata_qc_for_each_raw'
- 'ata_qc_for_each_with_internal'
- 'ax25_for_each'
- 'ax25_uid_for_each'
- '__bio_for_each_bvec'
- 'bio_for_each_bvec'
- 'bio_for_each_integrity_vec'
- '__bio_for_each_segment'
- 'bio_for_each_segment'
- 'bio_for_each_segment_all'
- 'bio_list_for_each'
- 'bip_for_each_vec'
- 'blkg_for_each_descendant_post'
- 'blkg_for_each_descendant_pre'
- 'blk_queue_for_each_rl'
- 'bond_for_each_slave'
- 'bond_for_each_slave_rcu'
- 'bpf_for_each_spilled_reg'
- 'btree_for_each_safe128'
- 'btree_for_each_safe32'
- 'btree_for_each_safe64'
- 'btree_for_each_safel'
- 'card_for_each_dev'
- 'cgroup_taskset_for_each'
- 'cgroup_taskset_for_each_leader'
- 'cpufreq_for_each_entry'
- 'cpufreq_for_each_entry_idx'
- 'cpufreq_for_each_valid_entry'
- 'cpufreq_for_each_valid_entry_idx'
- 'css_for_each_child'
- 'css_for_each_descendant_post'
- 'css_for_each_descendant_pre'
- 'device_for_each_child_node'
- 'dma_fence_chain_for_each'
- 'drm_atomic_crtc_for_each_plane'
- 'drm_atomic_crtc_state_for_each_plane'
- 'drm_atomic_crtc_state_for_each_plane_state'
- 'drm_atomic_for_each_plane_damage'
- 'drm_client_for_each_connector_iter'
- 'drm_client_for_each_modeset'
- 'drm_connector_for_each_possible_encoder'
- 'drm_for_each_connector_iter'
- 'drm_for_each_crtc'
- 'drm_for_each_encoder'
- 'drm_for_each_encoder_mask'
- 'drm_for_each_fb'
- 'drm_for_each_legacy_plane'
- 'drm_for_each_plane'
- 'drm_for_each_plane_mask'
- 'drm_for_each_privobj'
- 'drm_mm_for_each_hole'
- 'drm_mm_for_each_node'
- 'drm_mm_for_each_node_in_range'
- 'drm_mm_for_each_node_safe'
- 'flow_action_for_each'
- 'for_each_active_dev_scope'
- 'for_each_active_drhd_unit'
- 'for_each_active_iommu'
- 'for_each_available_child_of_node'
- 'for_each_bio'
- 'for_each_board_func_rsrc'
- 'for_each_bvec'
- 'for_each_card_components'
- 'for_each_card_links'
- 'for_each_card_links_safe'
- 'for_each_card_prelinks'
- 'for_each_card_rtds'
- 'for_each_card_rtds_safe'
- 'for_each_cgroup_storage_type'
- 'for_each_child_of_node'
- 'for_each_clear_bit'
- 'for_each_clear_bit_from'
- 'for_each_cmsghdr'
- 'for_each_compatible_node'
- 'for_each_component_dais'
- 'for_each_component_dais_safe'
- 'for_each_comp_order'
- 'for_each_console'
- 'for_each_cpu'
- 'for_each_cpu_and'
- 'for_each_cpu_not'
- 'for_each_cpu_wrap'
- 'for_each_dev_addr'
- 'for_each_dev_scope'
- 'for_each_displayid_db'
- 'for_each_dma_cap_mask'
- 'for_each_dpcm_be'
- 'for_each_dpcm_be_rollback'
- 'for_each_dpcm_be_safe'
- 'for_each_dpcm_fe'
- 'for_each_drhd_unit'
- 'for_each_dss_dev'
- 'for_each_efi_memory_desc'
- 'for_each_efi_memory_desc_in_map'
- 'for_each_element'
- 'for_each_element_extid'
- 'for_each_element_id'
- 'for_each_endpoint_of_node'
- 'for_each_evictable_lru'
- 'for_each_fib6_node_rt_rcu'
- 'for_each_fib6_walker_rt'
- 'for_each_free_mem_pfn_range_in_zone'
- 'for_each_free_mem_pfn_range_in_zone_from'
- 'for_each_free_mem_range'
- 'for_each_free_mem_range_reverse'
- 'for_each_func_rsrc'
- 'for_each_hstate'
- 'for_each_if'
- 'for_each_iommu'
- 'for_each_ip_tunnel_rcu'
- 'for_each_irq_nr'
- 'for_each_link_codecs'
- 'for_each_link_platforms'
- 'for_each_lru'
- 'for_each_matching_node'
- 'for_each_matching_node_and_match'
- 'for_each_memblock'
- 'for_each_memblock_type'
- 'for_each_memcg_cache_index'
- 'for_each_mem_pfn_range'
- 'for_each_mem_range'
- 'for_each_mem_range_rev'
- 'for_each_migratetype_order'
- 'for_each_msi_entry'
- 'for_each_msi_entry_safe'
- 'for_each_net'
- 'for_each_netdev'
- 'for_each_netdev_continue'
- 'for_each_netdev_continue_rcu'
- 'for_each_netdev_feature'
- 'for_each_netdev_in_bond_rcu'
- 'for_each_netdev_rcu'
- 'for_each_netdev_reverse'
- 'for_each_netdev_safe'
- 'for_each_net_rcu'
- 'for_each_new_connector_in_state'
- 'for_each_new_crtc_in_state'
- 'for_each_new_mst_mgr_in_state'
- 'for_each_new_plane_in_state'
- 'for_each_new_private_obj_in_state'
- 'for_each_node'
- 'for_each_node_by_name'
- 'for_each_node_by_type'
- 'for_each_node_mask'
- 'for_each_node_state'
- 'for_each_node_with_cpus'
- 'for_each_node_with_property'
- 'for_each_of_allnodes'
- 'for_each_of_allnodes_from'
- 'for_each_of_cpu_node'
- 'for_each_of_pci_range'
- 'for_each_old_connector_in_state'
- 'for_each_old_crtc_in_state'
- 'for_each_old_mst_mgr_in_state'
- 'for_each_oldnew_connector_in_state'
- 'for_each_oldnew_crtc_in_state'
- 'for_each_oldnew_mst_mgr_in_state'
- 'for_each_oldnew_plane_in_state'
- 'for_each_oldnew_plane_in_state_reverse'
- 'for_each_oldnew_private_obj_in_state'
- 'for_each_old_plane_in_state'
- 'for_each_old_private_obj_in_state'
- 'for_each_online_cpu'
- 'for_each_online_node'
- 'for_each_online_pgdat'
- 'for_each_pci_bridge'
- 'for_each_pci_dev'
- 'for_each_pci_msi_entry'
- 'for_each_populated_zone'
- 'for_each_possible_cpu'
- 'for_each_present_cpu'
- 'for_each_prime_number'
- 'for_each_prime_number_from'
- 'for_each_process'
- 'for_each_process_thread'
- 'for_each_property_of_node'
- 'for_each_registered_fb'
- 'for_each_reserved_mem_region'
- 'for_each_rtd_codec_dai'
- 'for_each_rtd_codec_dai_rollback'
- 'for_each_rtdcom'
- 'for_each_rtdcom_safe'
- 'for_each_set_bit'
- 'for_each_set_bit_from'
- 'for_each_sg'
- 'for_each_sg_dma_page'
- 'for_each_sg_page'
- 'for_each_sibling_event'
- 'for_each_subelement'
- 'for_each_subelement_extid'
- 'for_each_subelement_id'
- '__for_each_thread'
- 'for_each_thread'
- 'for_each_zone'
- 'for_each_zone_zonelist'
- 'for_each_zone_zonelist_nodemask'
- 'fwnode_for_each_available_child_node'
- 'fwnode_for_each_child_node'
- 'fwnode_graph_for_each_endpoint'
- 'gadget_for_each_ep'
- 'genradix_for_each'
- 'genradix_for_each_from'
- 'hash_for_each'
- 'hash_for_each_possible'
- 'hash_for_each_possible_rcu'
- 'hash_for_each_possible_rcu_notrace'
- 'hash_for_each_possible_safe'
- 'hash_for_each_rcu'
- 'hash_for_each_safe'
- 'hctx_for_each_ctx'
- 'hlist_bl_for_each_entry'
- 'hlist_bl_for_each_entry_rcu'
- 'hlist_bl_for_each_entry_safe'
- 'hlist_for_each'
- 'hlist_for_each_entry'
- 'hlist_for_each_entry_continue'
- 'hlist_for_each_entry_continue_rcu'
- 'hlist_for_each_entry_continue_rcu_bh'
- 'hlist_for_each_entry_from'
- 'hlist_for_each_entry_from_rcu'
- 'hlist_for_each_entry_rcu'
- 'hlist_for_each_entry_rcu_bh'
- 'hlist_for_each_entry_rcu_notrace'
- 'hlist_for_each_entry_safe'
- '__hlist_for_each_rcu'
- 'hlist_for_each_safe'
- 'hlist_nulls_for_each_entry'
- 'hlist_nulls_for_each_entry_from'
- 'hlist_nulls_for_each_entry_rcu'
- 'hlist_nulls_for_each_entry_safe'
- 'i3c_bus_for_each_i2cdev'
- 'i3c_bus_for_each_i3cdev'
- 'ide_host_for_each_port'
- 'ide_port_for_each_dev'
- 'ide_port_for_each_present_dev'
- 'idr_for_each_entry'
- 'idr_for_each_entry_continue'
- 'idr_for_each_entry_continue_ul'
- 'idr_for_each_entry_ul'
- 'in_dev_for_each_ifa_rcu'
- 'in_dev_for_each_ifa_rtnl'
- 'inet_bind_bucket_for_each'
- 'inet_lhash2_for_each_icsk_rcu'
- 'key_for_each'
- 'key_for_each_safe'
- 'klp_for_each_func'
- 'klp_for_each_func_safe'
- 'klp_for_each_func_static'
- 'klp_for_each_object'
- 'klp_for_each_object_safe'
- 'klp_for_each_object_static'
- 'kvm_for_each_memslot'
- 'kvm_for_each_vcpu'
- 'list_for_each'
- 'list_for_each_codec'
- 'list_for_each_codec_safe'
- 'list_for_each_entry'
- 'list_for_each_entry_continue'
- 'list_for_each_entry_continue_rcu'
- 'list_for_each_entry_continue_reverse'
- 'list_for_each_entry_from'
- 'list_for_each_entry_from_rcu'
- 'list_for_each_entry_from_reverse'
- 'list_for_each_entry_lockless'
- 'list_for_each_entry_rcu'
- 'list_for_each_entry_reverse'
- 'list_for_each_entry_safe'
- 'list_for_each_entry_safe_continue'
- 'list_for_each_entry_safe_from'
- 'list_for_each_entry_safe_reverse'
- 'list_for_each_prev'
- 'list_for_each_prev_safe'
- 'list_for_each_safe'
- 'llist_for_each'
- 'llist_for_each_entry'
- 'llist_for_each_entry_safe'
- 'llist_for_each_safe'
- 'media_device_for_each_entity'
- 'media_device_for_each_intf'
- 'media_device_for_each_link'
- 'media_device_for_each_pad'
- 'nanddev_io_for_each_page'
- 'netdev_for_each_lower_dev'
- 'netdev_for_each_lower_private'
- 'netdev_for_each_lower_private_rcu'
- 'netdev_for_each_mc_addr'
- 'netdev_for_each_uc_addr'
- 'netdev_for_each_upper_dev_rcu'
- 'netdev_hw_addr_list_for_each'
- 'nft_rule_for_each_expr'
- 'nla_for_each_attr'
- 'nla_for_each_nested'
- 'nlmsg_for_each_attr'
- 'nlmsg_for_each_msg'
- 'nr_neigh_for_each'
- 'nr_neigh_for_each_safe'
- 'nr_node_for_each'
- 'nr_node_for_each_safe'
- 'of_for_each_phandle'
- 'of_property_for_each_string'
- 'of_property_for_each_u32'
- 'pci_bus_for_each_resource'
- 'ping_portaddr_for_each_entry'
- 'plist_for_each'
- 'plist_for_each_continue'
- 'plist_for_each_entry'
- 'plist_for_each_entry_continue'
- 'plist_for_each_entry_safe'
- 'plist_for_each_safe'
- 'pnp_for_each_card'
- 'pnp_for_each_dev'
- 'protocol_for_each_card'
- 'protocol_for_each_dev'
- 'queue_for_each_hw_ctx'
- 'radix_tree_for_each_slot'
- 'radix_tree_for_each_tagged'
- 'rbtree_postorder_for_each_entry_safe'
- 'rdma_for_each_block'
- 'rdma_for_each_port'
- 'resource_list_for_each_entry'
- 'resource_list_for_each_entry_safe'
- 'rhl_for_each_entry_rcu'
- 'rhl_for_each_rcu'
- 'rht_for_each'
- 'rht_for_each_entry'
- 'rht_for_each_entry_from'
- 'rht_for_each_entry_rcu'
- 'rht_for_each_entry_rcu_from'
- 'rht_for_each_entry_safe'
- 'rht_for_each_from'
- 'rht_for_each_rcu'
- 'rht_for_each_rcu_from'
- '__rq_for_each_bio'
- 'rq_for_each_bvec'
- 'rq_for_each_segment'
- 'scsi_for_each_prot_sg'
- 'scsi_for_each_sg'
- 'sctp_for_each_hentry'
- 'sctp_skb_for_each'
- 'shdma_for_each_chan'
- '__shost_for_each_device'
- 'shost_for_each_device'
- 'sk_for_each'
- 'sk_for_each_bound'
- 'sk_for_each_entry_offset_rcu'
- 'sk_for_each_from'
- 'sk_for_each_rcu'
- 'sk_for_each_safe'
- 'sk_nulls_for_each'
- 'sk_nulls_for_each_from'
- 'sk_nulls_for_each_rcu'
- 'snd_array_for_each'
- 'snd_pcm_group_for_each_entry'
- 'snd_soc_dapm_widget_for_each_path'
- 'snd_soc_dapm_widget_for_each_path_safe'
- 'snd_soc_dapm_widget_for_each_sink_path'
- 'snd_soc_dapm_widget_for_each_source_path'
- 'tb_property_for_each'
- 'tcf_exts_for_each_action'
- 'udp_portaddr_for_each_entry'
- 'udp_portaddr_for_each_entry_rcu'
- 'usb_hub_for_each_child'
- 'v4l2_device_for_each_subdev'
- 'v4l2_m2m_for_each_dst_buf'
- 'v4l2_m2m_for_each_dst_buf_safe'
- 'v4l2_m2m_for_each_src_buf'
- 'v4l2_m2m_for_each_src_buf_safe'
- 'virtio_device_for_each_vq'
- 'xa_for_each'
- 'xa_for_each_marked'
- 'xa_for_each_start'
- 'xas_for_each'
- 'xas_for_each_conflict'
- 'xas_for_each_marked'
- 'zorro_for_each_dev'
#IncludeBlocks: Preserve # Unknown to clang-format-5.0
IncludeCategories:
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
#IndentPPDirectives: None # Unknown to clang-format-5.0
IndentWidth: 5
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
#ObjCBinPackProtocolList: Auto # Unknown to clang-format-5.0
ObjCBlockIndentWidth: 5
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
# Taken from git's rules
#PenaltyBreakAssignment: 10 # Unknown to clang-format-4.0
PenaltyBreakBeforeFirstCallParameter: 30
PenaltyBreakComment: 10
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 10
PenaltyExcessCharacter: 100
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: false
SortIncludes: false
#SortUsingDeclarations: false # Unknown to clang-format-4.0
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
#SpaceBeforeCtorInitializerColon: true # Unknown to clang-format-5.0
#SpaceBeforeInheritanceColon: true # Unknown to clang-format-5.0
SpaceBeforeParens: ControlStatements
#SpaceBeforeRangeBasedForLoopColon: true # Unknown to clang-format-5.0
SpaceInEmptyParentheses: true
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: true
SpacesInParentheses: true
SpacesInSquareBrackets: false
Standard: Cpp03
TabWidth: 5
UseTab: Never
+52
View File
@@ -0,0 +1,52 @@
.equ ADCL, 0x0078
.equ ADCH, 0x0079
.equ ADCSRA, 0x007A
.equ ADCSRB, 0x007B
.equ ADMUX, 0x007C
.equ DDIR0, 0x007E
.equ ADSC, 6 // bit 6 on the ADCSRA
.text
.global initAD
.global readAD
; LDI r16, 0b01100000
; add r16, r24
; STS ADMUX, r16
initAD: // routine which initializes the A/D lines
LDI R16, 0b00111111
STS DDIR0, R16
LDI R16, 0b10000111
STS ADCSRA, R16
ret // of initAD
readAD:
// routine which has one parameter in r24
// and then reads the A/D signal and places the result
// into r24, clearing r25
// we need to set up the ADMUX and ADSCSRA and then
// wait on ADSC
push r16
push r17
LDI r16, 0b01100000
add r16, r24
STS ADMUX, r16
LDS r17, ADCSRA
ori r17, 0b01000000
STS ADCSRA, r17
loopADC:
LDS r16, ADCSRA
andi r16, 0b01000000
brne loopADC
LDS r24, ADCH
clr r25
pop r17
pop r16
ret // we have our result, we are done
+18
View File
@@ -0,0 +1,18 @@
extern "C" {
void initAD( );
byte readAD( byte );
}
void setup( ) {
Serial.begin( 9600 );
initAD( ); // call assembly init A/D routine
}
void loop( ) {
byte v;
v = readAD( 2 ); // call assembly read sensor routine, A/D pin #2
Serial.print( " light = " );
Serial.println( v, HEX );
delay( 1000 ); // delay one second
}