Thread: Quick buzzer

  1. #1
    Registered User
    Join Date
    Dec 2018
    Posts
    9

    Quick buzzer

    Hi guys.i try to write a program for quick buzzer in codevision with atmega32 and BCD7448 .can someone help me to find out my mistakes?
    Code:
    #include <maga32.h>
    #include <delay.h>
    unsigned int i;
    viod init (){
    PORTA=0x00;
    DDRA=0xff;
    PORTC=0x00;
    DDRC=0xff;
    }
    void main (void){
    init ();
    while(1){
    for(i =0;i <10;i ++){
    if (PINA.0==0)
    i=1;
    elseif (PINA.1==0)
    i=2;
    elseif (PINA.2==0)
    i=3;
    elseif (PINA.3==0)
    i=4;
    elseif (PINA.4==0)
    i=5;
    elseif (PINA.5==0)
    i=6;
    elseif (PINA.6==0)
    i=7;
    elseif(PINA.7==0)
    i=8;
    else
    break;
    }
    delay_ms(150);
    }
    }
    Last edited by Salem; 12-14-2018 at 08:27 AM. Reason: Removed crayola

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,415
    > viod init ()
    Maybe post something that compiles?

    > elseif(PINA.7==0)
    Or even just syntactically valid.

    Post your error messages.
    The PINA.7 etc may be valid on your old compiler (through some vendor extension), but isn't valid on your new compiler.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2018
    Posts
    9
    My code doesn’t have any error and don’t running in proteus

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    3,653
    So, I suggest you find a support site for this non C code.

    C does not have an "elseif" key word; therefore you are not writing C.

    Link to Proteus Proteus Design Suite - Wikipedia

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    653
    Also:

    Quote Originally Posted by Afsaneh View Post
    Code:
    #include <maga32.h>
    I'm sure that should be "mega32.h", not "maga32.h".

    Afsaneh: did you re-type the code on this forum, or did you copy and paste it? I bet it's the former because no AVR C compiler would accept the code you posted.

    In the future, please be more considerate by copying and pasting your code rather than re-typing it.

  6. #6
    Registered User
    Join Date
    Dec 2018
    Posts
    9
    I write this code and don’t copy it!!!
    And ‘maga32.h’ ,The typo was here that I wrote.and I know it should be ‘mega32.h’!
    I think the problem is ‘elseif’ maybe C can’t understand it.
    If I write it by switch case can be true?

  7. #7
    Registered User
    Join Date
    Dec 2018
    Posts
    9
    Quote Originally Posted by stahta01 View Post
    So, I suggest you find a support site for this non C code.

    C does not have an "elseif" key word; therefore you are not writing C.

    Link to Proteus Proteus Design Suite - Wikipedia

    Tim S.
    So i have to write it with switch case!

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,415
    > I think the problem is ‘elseif’ maybe C can’t understand it.
    Well if you made it "else if" by putting a space in there, that would work.

    But there are several other things as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    653
    Quote Originally Posted by Afsaneh View Post
    I write this code and don’t copy it!!!
    And ‘maga32.h’ ,The typo was here that I wrote.and I know it should be ‘mega32.h’!
    I think the problem is ‘elseif’ maybe C can’t understand it.
    If I write it by switch case can be true?
    I think there's a misunderstanding here. I did not mean to suggest that you copied your code from anywhere. I requested that you copy and paste your code to this forum. Otherwise we'll be trying help you to debug code that's different from the code you're actually trying to compile. That wastes our time and your time.

    So, if you want help, copy and paste your code to this forum. Don't type it again.

  10. #10
    Registered User
    Join Date
    Dec 2018
    Posts
    9
    Quote Originally Posted by christop View Post
    I think there's a misunderstanding here. I did not mean to suggest that you copied your code from anywhere. I requested that you copy and paste your code to this forum. Otherwise we'll be trying help you to debug code that's different from the code you're actually trying to compile. That wastes our time and your time.

    So, if you want help, copy and paste your code to this forum. Don't type it again.
    Code:
    #include <mega32.h>
    #include <delay.h>
     int i;
    void main(void){
    DDRA=0xff;
    PORTA = 0x00;
    
    
    PORTC = 0x00;
    DDRC = 0xff;
    
    
    while(1){
    for (i=0;i<10;i++){
    if (PINA.0==0)
    i=1;            
    else if (PINA.1==0)
    i=2;
    else if (PINA.2==0)
    i=3;
    else if (PINA.3==0)
    i=4;
    else if (PINA.4==0)
    i=5;
    else if (PINA.5==0)
    i=6;
    else if (PINA.6==0)
    i=7;
    else if (PINA.7==0)
    i=8;
    else break;
    }
    delay_ms(150);
    }
    }
    this is my code with a little change
    Last edited by Afsaneh; 12-21-2018 at 01:57 AM.

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,415
    Here is your code indented so it's easier to follow what's going on.
    Code:
    #include <mega32.h>
    #include <delay.h>
    
    int i;
    
    void main(void)
    {
      DDRA = 0xff;
      PORTA = 0x00;
      PORTC = 0x00;
      DDRC = 0xff;
    
      while (1) {
        for (i = 0; i < 10; i++) {
          if (PINA.0 == 0)
            i = 1;
          else if (PINA.1 == 0)
            i = 2;
          else if (PINA.2 == 0)
            i = 3;
          else if (PINA.3 == 0)
            i = 4;
          else if (PINA.4 == 0)
            i = 5;
          else if (PINA.5 == 0)
            i = 6;
          else if (PINA.6 == 0)
            i = 7;
          else if (PINA.7 == 0)
            i = 8;
          else
            break;
        }
        delay_ms(150);
      }
    }
    So what's your new question?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  12. #12
    Registered User
    Join Date
    Dec 2018
    Posts
    9
    Quote Originally Posted by Salem View Post
    Here is your code indented so it's easier to follow what's going on.
    Code:
    #include <mega32.h>
    #include <delay.h>
    
    int i;
    
    void main(void)
    {
      DDRA = 0xff;
      PORTA = 0x00;
      PORTC = 0x00;
      DDRC = 0xff;
    
      while (1) {
        for (i = 0; i < 10; i++) {
          if (PINA.0 == 0)
            i = 1;
          else if (PINA.1 == 0)
            i = 2;
          else if (PINA.2 == 0)
            i = 3;
          else if (PINA.3 == 0)
            i = 4;
          else if (PINA.4 == 0)
            i = 5;
          else if (PINA.5 == 0)
            i = 6;
          else if (PINA.6 == 0)
            i = 7;
          else if (PINA.7 == 0)
            i = 8;
          else
            break;
        }
        delay_ms(150);
      }
    }
    So what's your new question?
    why it doesn’t answer in proteus?
    What changes should I make in the code?

  13. #13
    Registered User
    Join Date
    May 2009
    Posts
    3,653
    While do you think it should do something?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  14. #14
    Registered User
    Join Date
    Dec 2018
    Posts
    9
    Quote Originally Posted by stahta01 View Post
    While do you think it should do something?

    Tim S.
    I want 7seg show the number of each key to be pressed.😔

  15. #15
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,415
    Quote Originally Posted by Afsaneh View Post
    I want 7seg show the number of each key to be pressed.��
    What's that got to do with buzzer in the thread title?

    Look at your circuit diagram and figure out how the port and pin logic applies to buttons, then try and use that for your display.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 14
    Last Post: 01-26-2010, 11:18 AM
  2. Would like some quick help...
    By ibanez81 in forum C Programming
    Replies: 11
    Last Post: 12-15-2007, 04:41 AM
  3. buzzer?
    By MJS252 in forum C++ Programming
    Replies: 14
    Last Post: 07-05-2007, 02:12 PM
  4. Another Quick One
    By Necrofear in forum Windows Programming
    Replies: 7
    Last Post: 06-16-2006, 12:13 PM
  5. Quick help
    By webbizdesign in forum C Programming
    Replies: 1
    Last Post: 10-06-2003, 10:33 PM

Tags for this Thread