; ; hello.ftdi.echo.44.asm ; ; 115200 baud FTDI character echo ; ; Neil Gershenfeld ; 10/17/10 ; ; (c) Massachusetts Institute of Technology 2010 ; Permission granted for experimental and personal use; ; license for commercial sale available from MIT. ; .include "tn44def.inc" .def bitcnt = R16; bit counter .def temp = R17; temporary storage .def temp1 = R18; temporary storage .def ah = r19; adch .def al = r20; adcl .org 0 rjmp reset ; ; main ; reset: ; ; set fuse low byte to 0x7E for 20 MHz resonator ; ; set clock divider to /1 ; ldi temp, (1 << CLKPCE) ldi temp1, (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0) out CLKPR, temp out CLKPR, temp1 ; ; set stack pointer to top of RAM ; ldi temp, high(RAMEND) out SPH, temp ldi temp, low(RAMEND) out SPL, temp ; ; start main loop ; sbi PORTA, 2 ; enable pullup on port A, pin 2 sbi DDRA, 7 ; port A, pin 7 output ldi temp, 0x00 out prr, temp ldi temp, 0x02 out admux, temp ldi temp, 0b11100111 out adcsra, temp loop: in al, adcl ; adc low byte in ah, adch ; shift ADC output right 2 bits (1024 to 256, divide by 4) clc ror ah ror al clc ror ah ror al subi al, 0x02 pwm: mov bitcnt, al ; positive duty cycle mov temp, al com temp ; negative duty cycle sbi porta, 7 pause: dec bitcnt brne pause cbi porta, 7 pause2: dec temp brne pause2 rjmp loop