Vizitator Mihai-Vivian Postat Iunie 1, 2012 Partajează Postat Iunie 1, 2012 Salutare. Proiectul meu este despre controlul temperaturii intr-un incubator daca ma poate ajuta cineva va rog la partea de cod. Am atasat poza cu schema realizata in Proteus. Pana acuma am reusit sa afisez temperatura pe LCD.Nu reusesc sa controlez ventilatoru si radiatoru. #define F_CPU 4000000UL #include #include #include #include /*Global Variables Declarations*/ /*LCD function declarations */ void LCD_send_command(unsigned char cmnd); void LCD_send_data(unsigned char data); void LCD_init(); void LCD_goto(unsigned char y, unsigned char x); void LCD_print(char *string); /*ADC Conversion Complete Interrupt Service Routine (ISR)*/ ISR(ADC_vect); #define LCD_DATA_PORT PORTB #define LCD_DATA_DDR DDRB #define LCD_DATA_PIN PINB #define LCD_CNTRL_PORT PORTC #define LCD_CNTRL_DDR DDRC #define LCD_CNTRL_PIN PINC #define LCD_RS_PIN 5 #define LCD_RW_PIN 6 #define LCD_ENABLE_PIN 7 void port_init() {DDRD=0xFF; // set all pins of PORTD as outputs PORTD=0x04; //set INT0 pin to HIGH } int main(void) { unsigned char i; LCD_init(); LCD_goto(1,3); LCD_print("Temp curenta:"); DDRA = 0x00; // Configure PortA as input ADCSRA = 0x8F; // Enable the ADC and its interrupt feature // and set the ACD clock pre-scalar to clk/128 ADMUX = 0xE0; // Select internal 2.56V as Vref, left justify // data registers and select ADC0 as input channel sei(); // Enable Global Interrupts ADCSRA |= 1< while(1); } /* This function sends a command 'cmnd' to the LCD module*/ void LCD_send_command(unsigned char cmnd) { LCD_DATA_PORT = cmnd; LCD_CNTRL_PORT &= ~(1< LCD_CNTRL_PORT &= ~(1< LCD_CNTRL_PORT |= (1< _delay_us(2); LCD_CNTRL_PORT &= ~(1< _delay_us(100); } /* This function sends the data 'data' to the LCD module*/ void LCD_send_data(unsigned char data) { LCD_DATA_PORT = data; LCD_CNTRL_PORT &= ~(1< LCD_CNTRL_PORT |= (1< LCD_CNTRL_PORT |= (1< _delay_us(2); LCD_CNTRL_PORT &= ~(1< _delay_us(100); } void LCD_init() { LCD_CNTRL_DDR = 0xFF; LCD_CNTRL_PORT = 0x00; LCD_DATA_DDR = 0xFF; LCD_DATA_PORT = 0x00; _delay_ms(10); LCD_send_command(0x38); LCD_send_command(0x0C); LCD_send_command(0x01); _delay_ms(10); LCD_send_command(0x06); } /* This function moves the cursor the line y column x on the LCD module*/ void LCD_goto(unsigned char y, unsigned char x) { unsigned char firstAddress[] = {0x80,0xC0,0x94,0xD4}; LCD_send_command(firstAddress[y-1] + x-1); _delay_ms(10); } void LCD_print(char *string) { unsigned char i=0; while(string!=0) { LCD_send_data(string); i++; } } /*ADC Conversion Complete Interrupt Service Routine (ISR)*/ ISR(ADC_vect) { char tempC,display; tempC = ADCH;// Output ADCH to PortA LCD_goto(2,4); itoa(tempC1/10,display,10); LCD_print(display); itoa(tempC1%10,display,10); LCD_print(display); LCD_send_data(0xDF); LCD_print("C "); if (tempC<=10); PORTD=0x10; _delay_ms(500); ADCSRA |= 1< } int main2(void) {port_init(); // initialize ports GICR=0x40; // enable INT0 interrupt MCUCR=0x02; //falling edge on INT0 generates an interrupt sei(); //enable all interrupts while(1) { //TODO:: Please write your application code } } Edit: Ce v-am zis despre formularea titlului? Link spre comentariu
Vizitator keller946 Postat Iunie 2, 2012 Partajează Postat Iunie 2, 2012 Salut, În primul rând cred că ne-ar ajuta mai mult dacă am vedea o schemă de o rezoluție mai bună.Apoi, motorul cred că vrei să îl controlezi prin PWM. Din câte văd, ți-ai cam ocupat porturile de PWM, mai ai liber OC2 care nu cred că te ajută.La fel și cu rezistența de încălzire.Codul, ar trebui să îl structurezi ceva mai bine, folosind headere. Codul pentru mega16 e ușor de scris, nefiind presat de spațiu.Pentru LCD nu ai nevoie de toate liniile de date. E suficient să folosești ultimele 4;)Spor:) Link spre comentariu
Vizitator Mihai-Vivian Postat Iunie 3, 2012 Partajează Postat Iunie 3, 2012 Salut Iti multumesc pentru raspuns mentionez ca la partea de programare sunt cam pe langa deci orice ajutor ii bine venit.Am atasat 2 poze de rezolutie sper sa ma poti ajuta iti multumesc. Link spre comentariu
Postări Recomandate
Creează un cont sau autentifică-te pentru a adăuga comentariu
Trebuie să fi un membru pentru a putea lăsa un comentariu.
Creează un cont
Înregistrează-te pentru un nou cont în comunitatea nostră. Este simplu!
Înregistrează un nou contAutentificare
Ai deja un cont? Autentifică-te aici.
Autentifică-te acum