Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/05/04 16:58
Read: times


 
#64089 - re:flash a led???
Hi,
Can anyone tell me what I am doing wrong.I am trying to light a led to a 8051.The code is below.I am using a manual switch to light the led.The led comes on and sometimes it goes off but sometimes it lights very dim.
Can anyone please help me.


#pragma small //default to small memory model
#include<reg51.h> //include header file

/*****************************************************************/
/*Initialisation and declaration of led, buzzer and switch */
/*The flag is used to memorize the state of the switch */
/*****************************************************************/

sbit LED = P2^0; //LED
sbit BUZZER = P2^1; //Buzzer
sbit SWITCH = P2^2; //On/Off switch
bit FLAG; //variable

void main(){
LED = 0; //LED off
BUZZER = 1; //Buzzer off
FLAG = 0; //variable off
IE |= 0x82; //enable timer 0
while(1){
if (!SWITCH){ //Switch pressed
SWITCH = 1; //Switch goes high (1)
FLAG = !FLAG; //Toggle FLAG

if(FLAG){ //If FLAG high
LED = 1; //Turn on LED
BUZZER = 0; //Turn on BUZZER

}

if (!FLAG){ //If FLAG low
LED = 0 ; //Turn off LED
BUZZER = 1; //Turn off BUZZER

} //end the if statement
}
}
} //end of main



List of 20 messages in thread
TopicAuthorDate
re:flash a led???            01/01/70 00:00      
   RE: re:flash a led???            01/01/70 00:00      
   RE: re:flash a led???            01/01/70 00:00      
   RE: re:flash a led???            01/01/70 00:00      
   RE: re:flash a led???            01/01/70 00:00      
      RE: re:flash a led???            01/01/70 00:00      
         RE: re:flash a led???            01/01/70 00:00      
         RE: re:flash a led???            01/01/70 00:00      
            RE: re:flash a led???            01/01/70 00:00      
            RE: re:flash a led???            01/01/70 00:00      
               RE: re:flash a led???            01/01/70 00:00      
                  RE: re:flash a led???            01/01/70 00:00      
                     RE: re:flash a led???            01/01/70 00:00      
                        RE: re:flash a led???            01/01/70 00:00      
                        RE: Connecting the LED            01/01/70 00:00      
                        RE: Connecting the Buzzer            01/01/70 00:00      
                        RE: Connecting Switches            01/01/70 00:00      
                           RE: Connecting Switches            01/01/70 00:00      
                              RE: Connecting Switches            01/01/70 00:00      
                              Your LED driver is a misconstruction!            01/01/70 00:00      

Back to Subject List