From 0d6c506efe38ba9bf69355609a01e8a7634eff69 Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Mon, 25 Apr 2022 18:48:41 +0200 Subject: Initial commit --- .gitignore | 1 + templed.asm | 71 +++++++ templed.cof | 0 templed.obj | Bin 0 -> 411 bytes tn85def.inc | 683 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 755 insertions(+) create mode 100644 .gitignore create mode 100644 templed.asm create mode 100644 templed.cof create mode 100644 templed.obj create mode 100644 tn85def.inc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eee4db0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.hex diff --git a/templed.asm b/templed.asm new file mode 100644 index 0000000..dfe4131 --- /dev/null +++ b/templed.asm @@ -0,0 +1,71 @@ +.include "tn85def.inc" +.def tmp0 = r16 +.def tmp1 = r17 +.def tmp2 = r18 +.def tmp3 = r19 + +; Interrupt vectors +.org 0x0000 +interrupts: + rjmp init + .org ADCCaddr + rjmp adc_isr + +.org INT_VECTORS_SIZE +init: + ; Initialize stack pointer + ldi tmp0, HIGH(RAMEND) + out SPH, tmp0 + ldi tmp0, LOW(RAMEND) + out SPL, tmp0 + ; Set pin directions + ldi tmp0, 0b00010010 + out DDRB, tmp0 + ; Set default outputs + ;ldi tmp0, 0b00000010 + ;out PORTB, tmp0 + ; Initialize timer 0B + ldi tmp0, 0b00100011 + out TCCR0A, tmp0 + ldi tmp0, 0b00000001 + out TCCR0B, tmp0 + ; Initialize timer 1B + ldi tmp0, 0b00000001 + out TCCR1, tmp0 + ldi tmp0, 0b01100000 + out GTCCR, tmp0 + ; Enable interrupts + ldi tmp0, 0b10000000 + out SREG, tmp0 + ; Initialize ADC + ldi tmp0, 0b01000001 + out ADMUX, tmp0 + ldi tmp0, 0b10101000 + out ADCSRA, tmp0 + ; Start ADC conversion + sbi ADCSRA, ADSC + +main: + rjmp main + +adc_isr: + push tmp0 + push tmp1 + ; Read out ADC + in tmp0, ADCL + in tmp1, ADCH + ; Substract offset + subi tmp0, LOW(638) + sbci tmp1, HIGH(638) + ; Normalize to 8 bit for timer + lsr tmp1 + ror tmp0 + lsr tmp1 + ror tmp0 + ; Set as timer compare + out OCR0B, tmp0 + com tmp0 + out OCR1B, tmp0 + pop tmp1 + pop tmp0 + reti diff --git a/templed.cof b/templed.cof new file mode 100644 index 0000000..e69de29 diff --git a/templed.obj b/templed.obj new file mode 100644 index 0000000..2f61f7b Binary files /dev/null and b/templed.obj differ diff --git a/tn85def.inc b/tn85def.inc new file mode 100644 index 0000000..fc7fc59 --- /dev/null +++ b/tn85def.inc @@ -0,0 +1,683 @@ +;***** THIS IS A MACHINE GENERATED FILE - DO NOT EDIT ******************** +;***** Created: 2011-02-09 12:04 ******* Source: ATtiny85.xml ************ +;************************************************************************* +;* A P P L I C A T I O N N O T E F O R T H E A V R F A M I L Y +;* +;* Number : AVR000 +;* File Name : "tn85def.inc" +;* Title : Register/Bit Definitions for the ATtiny85 +;* Date : 2011-02-09 +;* Version : 2.35 +;* Support E-mail : avr@atmel.com +;* Target MCU : ATtiny85 +;* +;* DESCRIPTION +;* When including this file in the assembly program file, all I/O register +;* names and I/O register bit names appearing in the data book can be used. +;* In addition, the six registers forming the three data pointers X, Y and +;* Z have been assigned names XL - ZH. Highest RAM address for Internal +;* SRAM is also defined +;* +;* The Register names are represented by their hexadecimal address. +;* +;* The Register Bit names are represented by their bit number (0-7). +;* +;* Please observe the difference in using the bit names with instructions +;* such as "sbr"/"cbr" (set/clear bit in register) and "sbrs"/"sbrc" +;* (skip if bit in register set/cleared). The following example illustrates +;* this: +;* +;* in r16,PORTB ;read PORTB latch +;* sbr r16,(1<