khaled01819
Newbie level 6
- Joined
- May 27, 2010
- Messages
- 11
- Helped
- 2
- Reputation
- 4
- Reaction score
- 1
- Trophy points
- 1,283
- Location
- bangladesh
- Activity points
- 1,370
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 //Type 1 //If button is pressed do something //If button is pressed the input pin of the button goes high if(RB0) { //if button pressed Delay_ms(200); if(RB0) { //if button still pressed //Turn ON LED } } //Type 2 //If button is pressed and released then do something //If button is pressed the input pin of the button goes high if(RB0) { Delay_ms(200); while(RB0); //wait till button is released //Turn ON LED } //Type 3 //If button is pressed do something //If button is pressed the input pin of the button goes low if(!RB0) { //if button pressed Delay_ms(200); if(!RB0) { //if button still pressed //Turn ON LED } } //Type 2 //If button is pressed and released then do something //If button is pressed the input pin of the button goes high if(!RB0) { Delay_ms(200); while(!RB0); //wait till button is released //Turn ON LED }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 //button pressed if((PORTA & 0x03) == 0x01) { Delay_ms(200); if((PORTA & 0x03) == 0x01) { //do something } } if((PORTA & 0x03) == 0x02) { Delay_ms(200); if((PORTA & 0x03) == 0x02) { //do something } } //button pressed and released if((PORTA & 0x03) == 0x01) { Delay_ms(200); while(PORTA & 0x03); //do something } if((PORTA & 0x03) == 0x02) { Delay_ms(200); if(PORTA & 0x03); //do something }
Looping and incrementing a counter doesn't freeze program execution ?
main()
{
if (input == 0) {
if (integrator > 0)
integrator--;
}
else if (integrator < MAXIMUM)
integrator++;
if (integrator == 0)
output = 0;
else if (integrator >= MAXIMUM) {
output = 1;
integrator = MAXIMUM; /* defensive code if integrator got corrupted */
}
// place here your code (with no freeze of course !!)
....
}