Co zmienić?

Nov 23, 2006 11 Replies

Co zmienić w programie żeby chulało mi pod ATmega8 (akurat taki mam na stanie)


/************************************** thermo.c Digital Thermometer -55C to +125C AVR 90S2313 & DS1820



Copyright 2001 by Wichit Sirichote


**************************************/

#include <90s2313.h>



#include <math.h>


// 1 Wire Bus functions #asm .equ __w1_port=0x12 .equ __w1_bit=6 #endasm #include <1wire.h>



// DS1820 temperature sensor functions #include <ds1820.h>



// Declare your global variables here



unsigned char tick,i,digit; unsigned char heat[4]; unsigned int xtimer1; int temp,T,X1,X2,X3,X4,X5; // signed number for negative and positve temperature manipulating



char key;



unsigned char convert[10] = {0x3F,0x06,0xdb,0xcf,0x66,0x6d,0x7d,0x07,0x7f,0x6f};



#define segment PORTB #define LED_digit PORTD


// converts 16-bit data in T to display buffer for both negative and positive reading



void heatToBuffer() { if(T<0){ heat[3] = 0x40; // if negative, put - heat[0] = 0x39; // C



T = abs(T); // get only amplitude heat[1] = convert[T%10]; heat[2] = convert[T/10]; if (heat[2] == 0x3f) heat[2] = 0; // off msd } else { heat[0] = 0x39; // C



heat[3] = convert[T/100]; temp = T%100; heat[1] = convert[temp%10]; heat[2] = convert[temp/10]; // off msd if (heat[3] == 0x3f) { heat[3] = 0; if(heat[2] == 0x3f) heat[2] = 0; } } }


LPF() // performs five-point moving average { X5=X4; X4=X3; X3=X2; X2=X1; X1= T; T = (X1+X2+X3+X4+X5)/5; }


read_temp() { if(++xtimer1 >=5) { xtimer1 = 0; segment = 0xff; T = ds1820_temperature_10(0)/10; // read DS1820 every 5 sec. LPF(); // enter filter heatToBuffer(); // convert it } }



// Timer 0 overflow interrupt service routine // timer interrupt every 1/15 sec provides foreground task to be run periodically.



interrupt [TIM0_OVF] void timer0_ovf_isr(void) { switch (++tick){ case 15: tick = 0; read_temp(); //second_task(); }



}

void scanLED() /* scan 4-digit LED and 4-key switch, if key pressed key =



0-3 else key = -1 */ // adapted from 89C2051 project if needs scan key, find one bit input port { char i; digit = 0x20; key = -1; for( i = 0; i < 4; i++) /* 4-DIGIT scanning */ { LED_digit = ~digit; /* send complement[digit] */ segment = ~heat[i]; /* send complement[segment] */ delay_ms(1); /* delay a while */ segment = 0xff; /* off LED */ // if ((PORTD & 0x10) == 0) /* if key pressed P3.4 became low */ // key = i; /* save key position to key variable */ digit>>=1; /* next digit */ } }

void main(void) {



DDRB=0xFF; PORTB=0x00;



DDRD=0x7F; PORTD=0x00;



// Timer/Counter 0 initialization // Clock source: System Clock // Clock value: 3.906 kHz // Mode: Output Compare // OC0 output: Disconnected TCCR0=0x05; TCNT0=0x00;



// Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x02;



// Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80;



// 1 Wire Bus initialization w1_init();



// Global enable interrupts #asm("sei")



// 1 Wire Bus initialization w1_init();



T = 34; heatToBuffer();



while (1) { scanLED(); // run background task forever }



Użytkownik "Gibol" napisał w wiadomości

Programiste ;P

MSPANC

Mam juz ten projekt na 8051, tylko to nie ma isp i nie che mi sie motać z programatorem. Znalazlem wiec na tego AVRa tyle ze mam mege 8 i na niej chciałbym to postawić a moje umiejetnosci programowania sa na poziomie bardzo początkującym. Mniej wiecej kojaze o co chodzi :P

Użytkownik "Gibol" napisał w wiadomości

To warto sobie cos w asmie napisac - pozwala na nauczenie sie zasady dzialania rodziny kontrolerow ;)

mIrO <miro@spamowi_mowie_nie.pl> napisał(a):

I słownik ortograficzny...

Dobra, dzięki za cenne rady, ale moze jednak ktoś mi powie, czy musze cos zmieniac oprócz <90s2313.h> ?

In the darkest hour on Thu, 23 Nov 2006 23:20:06 +0100, mIrO <miro@spamowi_mowie_nie.pl> screamed:

Szkoda tracić na pisanie w 100% asm czasu.

U?ytkownik "Gibol" <gibol@skrzynka_w_goglach.com> napisa? w wiadomo?ci news:ek56ck$cq7$ snipped-for-privacy@nemesis.news.tpi.pl...

Napisz sobie to samemu w Bascom'ie. Wieksza radosc bedzie a caly program termometru to zaledwie kilka linijek :)

Użytkownik " Wmak" napisał w wiadomości

Tego nawet nie zauwazylem :) A onegdaj w szkolach nawet wierszyka uczyli, zeby lepiej pisownie takich wyrazow zapamietac ;)

Użytkownik " Wmak" napisał w wiadomości

Tego nawet nie zauwazylem :) A onegdaj w szkolach nawet wierszyka takiego uczyli:

Kłopotliwe samo h, Dość szczególną skłonność ma, lubi hałaśliwe słowa: hak, harmider, hałasować, heca, hurmem, hej, hop, hura, hola, horda, hejnał, hulać, hasać, halo, hop, wataha ... W tych wypadkach się nie wahaj.

;)

Dnia Fri, 24 Nov 2006 00:06:25 +0100, Gibol napisał(a):

Nie każ nam grzebać po manualach procków ;) Znajdź w kodzie fragmenty zależne od sprzętu (na pierwszy rzut oka inicjalizacja timera i komparatora, fuse bity też będą inaczej ustawione) i posprawdzaj, czy żeby osiągnąć opisany w programie efekt nie trzeba przypadkiem wstawić innyh wartości.

Pozdrawiam Marcin Stanisz

Użytkownik "Artur M. Piwko" napisał w wiadomości

Na pisanie szkoda czasu, na nauke architektury kontrolera wcale.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required