Skip to content

Instantly share code, notes, and snippets.

@blondie7575
blondie7575 / AVRInterrupt.asm
Created August 19, 2012 23:49
AVR interrupt setup
// Configure INT2 (interrupt 2, on line PB2) to be a rising
// edge interrupt that we'll get from the CPU
// See ATmega324PA datasheet p68
cbi EIMSK,INT2_BIT
ldi accum,EICRA
ori accum,_BV(ISC20) | _BV(ISC21)
sts EICRA,accum
cbi EIFR,INTF2
sbi EIMSK,INT2_BIT
INT2_vect:
// Get ourselves completely off the bus
clr accum
out PORTD,accum
out DDRD,accum
out DDRC,accum
out DDRA,accum
sbi PORTB,vramWrite
// Plot a red pixel
testRender1:
// Take control of VRAM
EnableVRAMWrite
// Load a reasonable VRAM address
ldi accum,0x58
out PORTC,accum
ldi accum,0x1C
# Makefile
#
# Parts of this are borrowed from http://electrons.psychogenic.com
#
DEVICE=atmega324pa
CLOCK = 20000000UL
PROGRAMMER = usbtiny
FUSES = -U lfuse:w:0xe0:m -U hfuse:w:0xd9:m -U efuse:w:0xff:m
define(EnableVRAMWrite, `
sbi PORTB,vramOE
ldi accum,0xff
out DDRD,accum
')
define(DisableVRAMWrite, `
clr accum
out DDRD,accum
out PORTD,accum
ldy #$ff
OUTER:
ldx $ff
INNER:
nop
nop
nop
nop
nop
nop
0xAD,0xFF,0xEF, // LDA $EFFF : FE00
0xC9,0xFF, // CMP #$FF
0xF0,0xF9, // BEQ $FE00
0xAD,0xFF,0xEF, // LDA $EFFF : FE07
0xC9,0xFF, // CMP #$FF
0xD0,0xF9, // BNE $FE07
0xA9,0x04, // LDA #$04
0x8D,0xFF,0xEF, // STA $EFFF
0xA9,0x01, // LDA #$01
0xAD,0xFF,0xEF, // LDA $EFFF : FE00
0xC9,0xFF, // CMP #$FF
0xF0,0xF9, // BEQ $FE00
0xAD,0xFF,0xEF, // LDA $EFFF : FE07
0xC9,0xFF, // CMP #$FF
0xD0,0xF9, // BNE $FE07
0xA9,0x04, // LDA #$04
0x8D,0xFF,0xEF, // STA $EFFF
0xA9,0x01, // LDA #$01
/////////////////
// CPU Interrupt Service Routine
//
INT2_vect:
// Save registers
push accum
in accum,SREG
push accum
mainloop:
// Wait for VBL to process commands
sbrs VBL,0
rjmp mainloop
// See if there's a command pending
lds regS,CMDBUFFER_S
lds regT,CMDBUFFER_E