; Assembler: avra version 1.3.0 build 1
; Command..: avra reset.asm
.nolist
.include "/usr/share/avra/tn15def.inc"
.list
;==============
; Declarations
; PB0 - reset for z80
; PB1 - z80`s clock
; PB2 - led blink
; PB3 - Clock`s Configuration bit 1 (cfg1)
; PB4 - Clock`s Configuration bit 2 (cfg2)
;=================
; Variable Declarations
.equ OSCCAL_val = 0x6F ; Calibrate
.def cseg = r21
.cseg ; Code segment.
; Start of Program
.org 0
rjmp Init ; First line executed
reti ; IRQ0 handler
reti ; Pin change handler
rjmp timer1CM ; Timer1 compare match
reti ; Timer1 overflow handler
rjmp timer0; ; Timer0 overflow handler
reti ; Eeprom Ready handler
reti ; Analog Comparator handler
reti ; ADC Conversion Handler
;============
Init:
; writing calibration byte to the OSCCAL Register.
ldi r16, OSCCAL_val
out OSCCAL, r16
nop
nop
;Analogue comparator initialization
ldi r16, 0b10000000 ; Disable analogue comparator
out ACSR, r16
;PORTB initialization
ldi r16, 0b00000111 ; 1 = output e 0 =input1/6
out DDRB, r16 ; pb0 and pb1 = output pb2 = input
ldi r16, 0b11111000
out PortB, r16
;Timer initialization
ldi r16, 0x05 ; Timer 0 rolls over at 1.6MHz/1024/256 = 6.1Hz
out TCCR0, r16
;timer 1
in r16, PinB ; Input port b to read clock configuration
andi r16, 0b00011000 ; pb3 and pb4
cpi r16, 0b00000000 ; 00 = 12,847Mhz
brne test6mhz
ldi r16, 0b10010001 ; 12Mhz
rjmp init2
test6mhz:
cpi r16, 0b00001000 ; 01 = 6Mhz
brne test3mhz
ldi r16, 0b10010010 ; 6,396 Mhz
rjmp init2
test3mhz:
cpi r16, 0b00010000 ; 10 = 3Mhz
brne test1mhz
ldi r16, 0b10010011 ; 3,210Mhz
rjmp init2
test1mhz:
ldi r16, 0b10010100 ; 1,605Mhz
init2:
out TCCR1, r16
ldi r16, 0b00000000
out TCNT1, r16
ldi r16, $02 ; Enable TOVF0
out TIMSK, r16
ldi cseg, $01 ; Start at segment
ldi r17, 0x00
ldi r16, 0x00
sei ; Enable Interrupts
;======================
; Main body of program:
Main:
loopRst:
cbi PortB, pb0
cpi r16, 6 ; Wait some time here before to raise z80's reset line
brne loopRst
sbi PortB, pb0
blink:
;blink a led
SBRS r16, 0 ;2 Skip next instruction if bit0 = 1
SBI PORTB, pb2 ;2 Turn LED ON if bit0 = 0
SBRC r16, 0 ;2 Skip next instruction if bit0 = 0
CBI PORTB, pb2 ;2 Turn LED OFF if bit0 = 1
rjmp blink ;2 loops back to the start of Main
timer0:
inc r16 ;Increment and will be used to blink a led
reti
timer1CM: