Skip to content

Instantly share code, notes, and snippets.

@BobBurns
Created November 14, 2014 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BobBurns/8ab17cb37a0959579021 to your computer and use it in GitHub Desktop.
Save BobBurns/8ab17cb37a0959579021 to your computer and use it in GitHub Desktop.
another assembly version of Elliot Williams AVR Programming. Chapter 4
;showingOffBits assembly version
;
;compile with gavrasm showBits.asm
;flash with avrdude -c avrisp -p m168 -P /dev/tty.XXXXXXX -b 19200 -U flash:w:showBits.hex
;--- set up ---
.device atmega168
.cseg
.org 0
.def delayH =r25
.def delayL =r24
.def rand =r27
.def delayC =r17
.def temp =r16
.def count =r18
.def led =r20
.equ dlp_init =25000 ; *4 clock cycles = .1 sec
.equ rand_init =0xad
;--- inits ---
ldi temp,0xff
out DDRB,temp
; need to setup stack
ldi temp,low(RAMEND)
out SPL,temp
ldi temp,high(RAMEND)
out SPH,temp
;--- main loop
lp:
ldi led,0x00 ;go left
ldi count,7
ldi temp,0x01
for1: or led,temp
out PORTB,led ;turn on temp bit
lsl temp
ldi delayC,1
rcall delay
dec count
brne for1
ldi count,7
ldi temp,0x01
for2: com temp
and led,temp
out PORTB,led ;turn off temp bit
com temp
lsl temp
ldi delayC,1
rcall delay
dec count
brne for2
ldi delayC,5
rcall delay
; toggle random bits
ldi count,75
ldi rand,rand_init
for3: ldi temp,205
mul rand,temp
ldi temp,32
add r1,temp
mov rand,r0
out PORTB,rand ;flash random leds
ldi delayC,1
rcall delay
dec count
brne for3
ldi led,0 ; all LED's off
out PORTB,led
ldi delayC,5 ;pause
rcall delay
rjmp lp
;--- delay subroutine
delay:
ldi delayH,high(dlp_init)
ldi delayL,low(dlp_init)
dlp: sbiw delayH:delayL,1
brne dlp
dec delayC
brne delay
ret
@BobBurns
Copy link
Author

This has some issues, but works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment