c programming help?

This is a discussion on c programming help? within the C Programming forums, part of the General Programming Boards category; hello, so basically i have a big switch that executes actions depending on the button press of a tv remote, ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    2

    c programming help?

    hello,

    so basically i have a big switch that executes actions depending on the button press of a tv remote, sometimes a function call the function call successfully operates a timer counter which i am using to generate a PWM signal and output a square wave to a speaker. I understand how everything works, I wrote every line of code that I have thus far, the only thing i do not understand is how to make it break out of the "subswitch".

    basicallly what is happening when you press a button on the remote, i want it to alter the frequency of the note that plays. I calculated how many counts are required for each frequency of note that is desired. So basically the subswitch is supposed to operate via a counter, to know where it is in the sequence of notes, then I have to pass the timer variable back to the switch so i can do the same thing with another button, except this time, decrease the frequency with a button press

    if you need any further information I can surely provide it. I tried to include as many important details as possible

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    A look at your source code would help...

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    2
    sorry here is the necessary code, i have the timer counter subsystem 1 set up properly. If it helps this is on an arduino uno with a atmega 328p mc

    Code:
    void increase(uint8_t);//function prototype for increase frequency function
    void switch(uint16_t dnum)//dnum is a decimal number that is passed to this program via a decoder
    {
        uint8_t note;
    
        switch(dnum)
        {
    
            case 146://volume up button is pressed on remote
                lcd_goto_xy(0,1);
                lcd_printf("Volume Up   ");
                lcd_goto_xy(0,0);
                lcd_printf("000010010010");
                increase(note);
                break;
        }
    
    }
    
    
    void increase(uint8_t note)//increase function
    {
        DDRD &= ~(0b00000010); // set DDRC as an input
        PORTC |= (0b00000010); // enable pullups
        DDRB |= (0b00000010); //PORTB1 use OCR0A, SPEAKER plugged in here
    
    
        if (note==0);
        OCR1A=30577;//set compare for timer counter subsystem 1
        note++;
        if (note==1)
        OCR1A=6427;
        note++;
        if (note==2)
        OCR1A=6809;
        note++;
        if (note==3)
        OCR1A=7644;
        note++;
        if (note==4)
        OCR1A=8580;
        note++;
        if (note==5)
        OCR1A=9630;
        note++;
        if (note==6)
        OCR1A=10203;
        note++;
    
    }

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,676
    • Don't put a semicolon on the line with the if statement, it's like "throwing away" the if portion, so everything inside it gets executed regardless.
    • You can't call your function switch, that's a reserved word.
    • Learn about brackets, what they're for and when to use them.
    • Learn how to use else and else if statements.
    Those last three points tell me you need to seriously brush up on your basic C skills. Read a tutorial or twenty (start with this link), read your textbooks, class notes, etc and work some basic examples to get the feel for how if, else and else if work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. About Device Driver Programming And Socket Programming
    By pritesh in forum Linux Programming
    Replies: 6
    Last Post: 01-23-2010, 03:46 AM
  2. Replies: 1
    Last Post: 08-19-2007, 04:55 AM
  3. small programming job VCPP / Object Oriented Programming
    By calgonite in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 01-04-2006, 11:48 PM
  4. Total newb to programming here... Question about the many programming languages. Ty!
    By tsubotakid1 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 10-05-2003, 11:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21