Jump to content
The Official Site of the Vancouver Canucks
Canucks Community

Stuck On Homework? **The Homework Thread v0.01** is here!


More-is-on

Recommended Posts

I don't wanna do my work :cry: :cry: :cry: :cry: :cry: :cry: :cry: :cry: :cry: :cry: :cry: :cry: :cry: :cry: :cry:

anyway...

I have to program an LED to flash with a duty cycle that changes every time a button is pressed.

0 then 33 then 67 then 100%

then back to zero.

I have some sort of bug, the LED works until I get to the 67% I think...

here:

#include <p18cxxx.h>


#include <timers.h>


#include "osc.h"




#pragma config WDT = OFF


#pragma config OSC = INTIO7  // puts osc/4 on pin 14


#pragma config MCLRE = OFF


#pragma config LVP = OFF


#pragma config PBADEN = OFF // Necessary if RB0 … RB3 used as IO.




int checkButton(int buttonState);




int i;


void main(void)


{


set_osc_32MHz();       // select 32 MHz oscillator speed




TRISBbits.TRISB0 = 0;  // Configure as an output for an LED


TRISDbits.TRISD0 = 1;  // Configure as an button


PORTDbits.RD0 = 0;


PORTBbits.RB0 = 0;




i = 0;






	while(1)


	{	


  i = checkButton(i);




  // for 0% duty cycle


 	 if (i==0)


 	 {


    PORTBbits.RB0 = 0;


 	 }




  // for 33% duty cycle


 	 if (i == 1)


 	 {


     	 OpenTimer0(TIMER_INT_OFF & T0_SOURCE_INT & T0_16BIT & T0_PS_1_32);


    WriteTimer0(0);


   	 PORTBbits.RB0 = 0;    


    while( ReadTimer0() < 18800)


    {


   	 checkButton(i);


    }




    CloseTimer0();




    OpenTimer0(TIMER_INT_OFF & T0_SOURCE_INT & T0_16BIT & T0_PS_1_32);


    WriteTimer0(0);


   	 PORTBbits.RB0 = 1;    


    while( ReadTimer0() < 6200)


    {


   	 checkButton(i);


    }




    CloseTimer0();


 	 }




  // for 50% duty cycle


 	 if (i == 2)


 	 {


     	 OpenTimer0(TIMER_INT_OFF & T0_SOURCE_INT & T0_16BIT & T0_PS_1_32);


    WriteTimer0(0);


   	 PORTBbits.RB0 = 0;    


    while( ReadTimer0() < 12500)


    {


   	 checkButton(i);


    }




    CloseTimer0();




    OpenTimer0(TIMER_INT_OFF & T0_SOURCE_INT & T0_16BIT & T0_PS_1_32);


    WriteTimer0(0);


   	 PORTBbits.RB0 = 1;    


    while( ReadTimer0() < 12500)


    {


   	 checkButton(i);


    }




    CloseTimer0();


 	 }




  // for 67% duty cycle


 	 if (i == 3)


 	 {


     	 OpenTimer0(TIMER_INT_OFF & T0_SOURCE_INT & T0_16BIT & T0_PS_1_32);


    WriteTimer0(0);


   	 PORTBbits.RB0 = 0;    


    while( ReadTimer0() < 6200)


    {


   	 checkButton(i);


    }




    CloseTimer0();




    OpenTimer0(TIMER_INT_OFF & T0_SOURCE_INT & T0_16BIT & T0_PS_1_32);


    WriteTimer0(0);


   	 PORTBbits.RB0 = 1;    


    while( ReadTimer0() < 18800)


    {


   	 checkButton(i);


    }




    CloseTimer0();


 	 }




  //	for 100% duty cycle


 	 if (i == 4)


 	 {


    PORTBbits.RB0 = 1;


 	 }


	}


}






int checkButton(int buttonState)


{


	if (PORTDbits.RD0 == 1)


	{


  buttonState++;




	}	


	if (buttonState > 4)


  {


 	 buttonState = 0;


  }


	return (buttonState);


}

Link to comment
Share on other sites

If u want to be a tutor, please fill in this forum:

Grade level: 1st year University

Type of subject u specialize: Biology(zoology in particular), English, Chemistry, Physics, and Calculus Fundamentals

Current grade in subject: In midterms currently.

How active can you be: Message me or post on this board and I'll get back to you as soon as I can (if I know how to do the problem :lol:

Hours u're available: Varied.

What more can you offer: Have some early Canadian history knowledge, and am a very competent paper editor (ie. grammar, sentence/paragraph structure, spelling, punctuation)

Link to comment
Share on other sites

I don't wanna do my work :cry:  :cry:  :cry:  :cry:  :cry:  :cry:  :cry:  :cry:  :cry:  :cry:  :cry:  :cry:  :cry:  :cry:  :cry:  

anyway...

I have to program an LED to flash with a duty cycle that changes every time a button is pressed.

0 then 33 then 67 then 100%

then back to zero.

I have some sort of bug, the LED works until I get to the 67% I think...

here:

#include <p18cxxx.h>


#include <timers.h>


#include "osc.h"




#pragma config WDT = OFF


#pragma config OSC = INTIO7  // puts osc/4 on pin 14


#pragma config MCLRE = OFF


#pragma config LVP = OFF


#pragma config PBADEN = OFF // Necessary if RB0 … RB3 used as IO.




int checkButton(int buttonState);




int i;


void main(void)


{


set_osc_32MHz();       // select 32 MHz oscillator speed




TRISBbits.TRISB0 = 0;  // Configure as an output for an LED


TRISDbits.TRISD0 = 1;  // Configure as an button


PORTDbits.RD0 = 0;


PORTBbits.RB0 = 0;




i = 0;






	while(1)


	{	


  i = checkButton(i);




  // for 0% duty cycle


 	 if (i==0)


 	 {


    PORTBbits.RB0 = 0;


 	 }




  // for 33% duty cycle


 	 if (i == 1)


 	 {


     	 OpenTimer0(TIMER_INT_OFF & T0_SOURCE_INT & T0_16BIT & T0_PS_1_32);


    WriteTimer0(0);


   	 PORTBbits.RB0 = 0;    


    while( ReadTimer0() < 18800)


    {


   	 checkButton(i);


    }




    CloseTimer0();




    OpenTimer0(TIMER_INT_OFF & T0_SOURCE_INT & T0_16BIT & T0_PS_1_32);


    WriteTimer0(0);


   	 PORTBbits.RB0 = 1;    


    while( ReadTimer0() < 6200)


    {


   	 checkButton(i);


    }




    CloseTimer0();


 	 }




  // for 50% duty cycle


 	 if (i == 2)


 	 {


     	 OpenTimer0(TIMER_INT_OFF & T0_SOURCE_INT & T0_16BIT & T0_PS_1_32);


    WriteTimer0(0);


   	 PORTBbits.RB0 = 0;    


    while( ReadTimer0() < 12500)


    {


   	 checkButton(i);


    }




    CloseTimer0();




    OpenTimer0(TIMER_INT_OFF & T0_SOURCE_INT & T0_16BIT & T0_PS_1_32);


    WriteTimer0(0);


   	 PORTBbits.RB0 = 1;    


    while( ReadTimer0() < 12500)


    {


   	 checkButton(i);


    }




    CloseTimer0();


 	 }




  // for 67% duty cycle


 	 if (i == 3)


 	 {


     	 OpenTimer0(TIMER_INT_OFF & T0_SOURCE_INT & T0_16BIT & T0_PS_1_32);


    WriteTimer0(0);


   	 PORTBbits.RB0 = 0;    


    while( ReadTimer0() < 6200)


    {


   	 checkButton(i);


    }




    CloseTimer0();




    OpenTimer0(TIMER_INT_OFF & T0_SOURCE_INT & T0_16BIT & T0_PS_1_32);


    WriteTimer0(0);


   	 PORTBbits.RB0 = 1;    


    while( ReadTimer0() < 18800)


    {


   	 checkButton(i);


    }




    CloseTimer0();


 	 }




  //	for 100% duty cycle


 	 if (i == 4)


 	 {


    PORTBbits.RB0 = 1;


 	 }


	}


}






int checkButton(int buttonState)


{


	if (PORTDbits.RD0 == 1)


	{


  buttonState++;




	}	


	if (buttonState > 4)


  {


 	 buttonState = 0;


  }


	return (buttonState);


}

Link to comment
Share on other sites

A cubic crystal is being grown in a laboratory. Find the instantaneous rate of change when x = 4.

I know how to do these types of questions, but an equation isn't given. It says cubic crystal...do I assume it's y = x^3?

The answer is 48 mm^3/mm, or 48 mm^2

Link to comment
Share on other sites

OK. This one I'm actually stuck on. I promise :)!

If a tank holds 1000L of water, which takes an hour to drain from the bottom of the tank, then the volume V of water remaining in the tank after t minutes is:

V = 1000( 1 - t/60 )^2 0 < t < 60.

Find the rate at which the water is flowing out of the tank (the instantaneous rate of change of V with respect to t) after 10 min.

The answer is 250L/min.

No derivative rules may be used to show work. (chapter 1 still)

Thanks in advance.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...