Need help with my program!!!!!!1

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guys i rlly need help. I am working on this program and its about reading liquid level. I wanna have 3 sensor and everyone of them prints the level  at which  the liquid is and how long it takes that triggered the sensor and it all displays on LCD . With push button we turn off the system. Pls help me with this code  cuz its not working. 

 

 

 

 

 

#include <avr/io.h>
#include "AVR lib/AVR_lib.h"
#include <avr/interrupt.h>
#include <util/delay.h>
#include "LCD/lcd.h"
#include "timer/timer.h"

uint16_t sekunde=1;

ISR(TIMER0_OVF_vect){ // prekidna rutina za timer 1
    
    TCNT1 = 0; // početna vrijednost registra
    TOGGLE_PORT(PORTB,PB1);
}

ISR(INT0_vect) // prekidna rutina za INT0
{
    // ako je brid rastuci
    if( get_pin(PIND,PD2) == 1){
        TCNT1 = 0; // t1 = 0
    }
    else // ako je brid padajuci
    {
        sekunde += TCNT1;
    }
}
ISR(INT1_vect) // prekidna rutina za INT1
{
    if (get_pin(PIND,PD3) == 1){
        TCNT1 = 0; //
    }
    else // ako je brid padajuci
    {
        sekunde  += TCNT1; //
    }
}
ISR(INT2_vect) // prekidna rutina za INT2
{
    if(get_pin(PINB,PB2) == 1){
        TCNT1 = 0; //
    }
    else // ako je brid padajuci
    {
        sekunde += TCNT1; //
    }
}

void inicijalizacija()    {
    lcd_init();

    

    // oba brida generiraju prekid INT0
    set_bit_reg(MCUCR,ISC00);
    reset_bit_reg(MCUCR,ISC01);
    
    set_bit_reg(GICR,INT0); // omogucanje vanjskog prekida INT0
    
    
    // oba brida generiraju prekid INT1
    set_bit_reg(MCUCR,ISC10);
    reset_bit_reg(MCUCR,ISC11);
    
    set_bit_reg(GICR,INT1); // omogucanje vanjskog prekida INT1
    
    
    // rastuci brid generira prekid  INT2     // TREBA TO PROMIJENITI
    set_bit_reg(MCUCSR,ISC2);
    
    
    set_bit_reg(GICR,INT2); // omogucanje vanjskog prekida INT2
    
    
    
    
    //F_CPU/64 
    reset_bit_reg(TCCR1B,CS10);
    set_bit_reg(TCCR1B,CS11);
    

    

    
    
    
    
    
    output_port(DDRB,PB7);  // pin PB7 postavljen kao izlazni(ledica)
    output_port(DDRB,PB6); // pin PB6 postavljen kao izlazni(pocetni senzor)
    output_port(DDRB,PB5); // pin PB5 postavljen kao izlazni(srednji senzor)
    output_port(DDRB,PB4); // pin PB4 postavljen kao izlazni(zavrsni senzor)

    input_port(DDRB,PB3); // PB3 postavljen kao ulazni (tipkalo)
    input_port(DDRB,PB2); // PB1 postavljen kao ulazni (pocetni senzor)
    input_port(DDRD,PD2); // PD2 postavljen kao ulazni (srednji senzor)
    input_port(DDRD,PD3); // PD3 postavljen kao ulazni (zavrsni senzor)
    
    set_port(PORTB,PB3,1); // ukljucivanje priteznog otpornika na PB3
    set_port(PORTD,PD3,1); // ukljucivanje priteznog otpornika na PD3
    set_port(PORTD,PD2,1); // ukljucivanje priteznog otpornika na PD2
    set_port(PORTB,PB2,1); // ukljucivanje priteznog otpornika na PB2
    sei(); // globalno omogucenje prekida
    
}
    

    int main(void){
        
        inicijalizacija();
        
        while (1){
            
            set_port(PORTB, PB4, 1); //postavljanje vrijednosti PB4 u 1
            _delay_us(20); // trigger impuls
            set_port(PORTB, PB4, 0);
            _delay_ms(500);
            
            
            set_port(PORTB, PB5, 1); //postavljanje vrijednosti PB5 u 1
            _delay_us(20); // trigger impuls
            set_port(PORTB, PB5, 0);
            _delay_ms(500);
            
            set_port(PORTB, PB6, 1); //postavljanje vrijednosti PB6 u 1
            _delay_us(20); // trigger impuls
            set_port(PORTB, PB6, 0);
            _delay_ms(500);
            
            
            lcd_clrscr();
            lcd_home();
            
            
            
            if (get_pin(PINB,PB3) == 0) { //uvjet za tipkalo
                sekunde=0;
                set_port(PORTB,PB7,0); //pocetno stanje ledice u 0
            }
            else{
                
                
                if( get_pin(PINB,PB2) == 1){
                    
                    lcd_print("razina 1:\n");
                    lcd_print("\n%u s",sekunde);
                    
                }else
                
                if( get_pin(PIND,PD2) == 1){
                    
                    lcd_print("razina 2:\n");
                    lcd_print("\n%u s",sekunde);
                    
                }else
                
                if( get_pin(PIND,PD3) == 1){
                    
                    lcd_print("razina 3:\n");
                    lcd_print("\n%u s",sekunde);
                    
                    set_port(PORTB,PB7,1);  //ukljuci led diodu
                    
                    
                }
            }
        }
    
    
    
        
    
    

                                            
            

    return 0;
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dominik96 wrote:
its not working

tells us nothing

 

http://www.catb.org/esr/faqs/smart-questions.html#code

 

What testing / investigation / debugging have you done to find where it's going wrong ?

 

https://www.avrfreaks.net/forum/help-it-doesnt-work

 

How To Debug: https://www.avrfreaks.net/commen...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Fri. Jul 3, 2020 - 04:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Theres no errors but when i put this code in SimulIde doesnt do anything. Just wanna ask what my program rlly do? Where are my mistakes if u can tell me .

 

Ty :D 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dominik96 wrote:
Theres no errors

That, of course, is no guarantee  that any code is going to do what you wanted.

 

but when i put this code in SimulIde doesnt do anything.

Never heard of it.

 

However,

 

SimulIDE wrote:

SimulIDE also features a code Editor and Debugger for GcBasic, Arduino, PIC asm and AVR asm. It is still in it's firsts stages of development, with basic functionalities, but it is possible to write, compile and basic debugging with breakpoints, watch registers and global variables.

 

https://www.simulide.com/p/home.html

 

So make use of those features - get debugging! Step through your code! Watch what is (and isn't) happening - and see where that differs from what you wanted to happen!

 

Are you sure you have it all set up correctly ?

 

have you successfully run other code in it?

 

 

Just wanna ask what my program rlly do?

You wrote it - don't you know?!

 

The way to approach this, as always, is to break it down.

 

Start simple, then add bits a step at a time.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

why do you bother to write an entire program, then say it doesn't work?  That is your giant mistake.  First decide on all the pices you will need, like display a message,, any message...get that working 100%.  How about reading an on/off switch and displaying the result?  got it ?

How about reading displaying one raw sensor?  got it? Displaying the sensor calibrated value? got it?  Read  multiple sensors? Add some more control logic

 

....  See, one step at a time, like creating a spaceship.  Don't create everything all at once and expect to hop in for a ride...kaboom 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It would also be helpful if the comments were in English and to have a circuit diagram; we can't just guess the pin connections and components you are using.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which device?

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 4

You can use the book:  https://vub.hr/izdavastvo/knjiga/mikroracunala-programiranje-mikrokontrolera-porodice-atmel-u-programskom-o.

 

Guys, my name is Zoran and I am Dominik's professor. That project task is an exam for course Microcomputer. Please, don't help him! :-)