; ; hello.temp.45.asm ; ; read and send temperature ; ; Neil Gershenfeld ; CBA MIT 10/25/07 ; ; (c) Massachusetts Institute of Technology 2007 ; Permission granted for experimental and personal use; ; license for commercial sale available from MIT. ; .include "tn44def.inc" ; ; pins ; .equ led1=PA2 ; ; registers ; .def bit_count = R16; bit counter .def temp = R17; temporary storage .def temp1 = R18; temporary storage .def compare = R19; data byte ; ;definitions-- the 44 takes in the voltage and compares it to Vcc ; by the following equation: (Vcc*1024)/Vref-- the accel. defines ; the voltages output by going up or down in the datasheet ; .equ moving= 512 ; ; code segment ; .cseg .org 0 rjmp reset ; ; bit delay ; serial bit delay ; .equ b = 13 ; 9600 baud (clock /8) ;.equ b = 8 ; 115200 baud (clock /1) bit_delay: ldi temp, b bitloop: dec temp brne bitloop ret ; ; main program ; reset: ; ; set stack pointer to top of RAM ; ldi temp, high(RAMEND) out SPH, temp ldi temp, low(RAMEND) out SPL, temp ; ; init LED ; cbi PORTA, led1 sbi DDRA, led1 ; ; init A/D--see register description at ; end of ADC Conversion chapter in Datasheet for explanation ; of bit number codes ; cbi ADMUX, REFS1 ; use Vcc as reference cbi ADMUX, REFS0 ; " cbi ADMUX, ADLAR ; right-adjust result ; ; set MUX to ADC1 (PA1) by settings bits to 000001 ; cbi ADMUX, MUX5 cbi ADMUX, MUX4 cbi ADMUX, MUX3 cbi ADMUX, MUX2 cbi ADMUX, MUX1 sbi ADMUX, MUX0 sbi ADCSRA, ADEN ; enable A/D cbi ADCSRA, ADPS2 ; set prescaler to /2 cbi ADCSRA, ADPS1 ; " cbi ADCSRA, ADPS0 ; " ; ; start main loop ; main_loop: ;test ;sbi PORTA, led1 cbi PORTA, led1 sbi ADCSRA, ADSC ; start conversion AD_loop: sbic ADCSRA, ADSC ; loop until complete rjmp AD_loop rcall check rjmp main_loop check: in compare, ADCL ; low byte in compare, ADCH ; hi byte ldi temp, high(moving) cpc temp, compare brlo main_loop sbi PORTA, led1 ret ;1575= up ;2925.7= down