Wednesday, May 14, 2014

Delays in assembler and some tasks.

We often need to introduce a small delay into our programs. We often do this decrementing  or incrementing a register until it becomes a zero.

.include "m328pdef.inc"
ldi r16,1
ldi r17,1
call delay
here: nop
rjmp here
delay:
inc r16
brne delay
;rjmp here
ret

-----------------------------------some tasks----------------------------------------------
;helpful code. See below
.include "m328pdef.inc"
startprog: nop
up1:inc r5
brne up1
nop
nop
nop
inc r6
brne up1
end: rjmp end

Write short code segments in AVR Studio 4 to do the following. Put the code into your blog. Also add the relevant part of

the list file. Say how many cycles at 16MHz your segemnt used.

1) Put $16 into r16 and $17 into r17.
2) Put $11 in r11 and $12 into r12.
3) The above program takes over 49ms to get to the end: label. Say exactly how many micro-seconds.
4) Tweak number 3 above to take exactly 50ms.
5) In the Arduino we have a delay() for so many milli-seconds. Write a segment to delay r0 milli seconds. For instance if r0 contained 50 the delay would be 50ms.
6) Repeat number 4 but use dec instead of inc.
7) Write a segment to swap the contents of r0 and r1.Use specific numbers that you chose for contents.
8) Write a segment to reverse the order of the contents in r0,r1 and r2.
9) Replace any $01 in r0,r1,r2 with $ff. (Hint. Dec and check Z flag with brne or breq.)
10) Using inc, increment r0 as many times as the number in r1. Eg if r0=3 and r1= 4, then r0 would become 7.

Monday, May 5, 2014

Monday, March 31, 2014

RS232 protocol

The RS232 protocol has been around for many years now. There are various versions and we have to be aware that non-standard applications are used often. The main aspects are the sockets and plugs and the packet sending rules.





Monday, March 17, 2014

First sensor: the LDR






Some good code and information here.
Light dependent resistor circuit. See http://www.ladyada.net/learn/sensors/cds.html





Some voltage divider images

We often want a sensor to send its signal using a changing voltage. For instance when the temperature is high we get a big voltage, and when the temperature is low we get a low voltage. Note that normally the input to an Arduino analog pin has to be between 0 and 5 volts.