Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Help me fix my mikroC program for flashing a LED

Status
Not open for further replies.

mailus

Full Member level 4
Joined
Mar 6, 2012
Messages
234
Helped
7
Reputation
16
Reaction score
7
Trophy points
1,308
Location
-
Activity points
2,706
what is problem in my program,

ABOUT PROGRAM
i want to flash a LED when push button once pressed.on next pressing the flasher should off.

*/controller:pic 16f84A osc:8.000Mhz porta RA2_output porta RA3_input*/


Code:
sbit led at RA2_bit;
sbit sw at RA3_bit;
#define port porta
#define pin 3
#define time 20
short int co;
void main()
{
 trisb=0x00;
 trisa=0b01000;
 portb=0x00;
 porta=0x00;

  do
  {
  co=0;
   if(button(&port, pin, time, 1))
    {
     (co>1)?co=0:co++;
     }
       if(co=0)
         {
           led=0x00;
          } while(!sw);
       if(co=1)
       {
       led=0xff;
           delay_ms(40);
           led=0x00;
           delay_ms(40);
       }while(!sw);
     }while(1);
   }


by this my program LED flashes when switch is pressed,otherwise LED off....
 
Last edited:

re: help mikroc pic

Try

co = (co > 1) ? 0 : co++;

Also 40mS is very fast, you might not see it?
 

re: help mikroc pic

it does not flash when button pressed
 

re: help mikroc pic

if(co=0) ???

if(co == 0)
 

re: help mikroc pic

I am a beginner. so I don't know the exact code..
My idea is when a push button once pressed the led starts flashing.next time push button pressed the led stop flashing.
 

re: help mikroc pic

If(co = 0) this expression assigns the value 0 to the variable co. So this wont work as a test for 0.

if(co == 0) this expression test whether co is equal to 0.

if(co == 1) same here test for co equal to 1
 

Re: help mikroc pic

I know little bit about c.but I don't know how to program with mikroc. Please tell how to program a flasher when switch once pressed.next time it should stop.
 

Re: help mikroc pic

i done this project.it's my own code....
Code:
sbit sw at RA4_bit;
bit oldstate;
void main()
{
 trisb=0x00;
 trisa=0b10000;
 porta=0x00;
 portb=0x00;
  oldstate=0;
 for(;;)
 {

    if (Button(&PORTa, 4, 10, 1))
      oldstate = ~oldstate;
    if(oldstate==1)
    portb=0xff;
    delay_ms(100);
    portb=0x00;
    delay_ms(200);
  if(oldstate==0)
   portb=0x00;
  }
 }

if any error inform me... i will correct it. thank you..
 

hi..may i know what the meaning of 'if (Button(&PORTa, 4, 10, 1)) ???

im newbie here~~
 

Button(&PORTA, 4, 10, 1) is a library routine. &PORTA selects the PORTA as the PORT to which switch is connected. 4 is the pin no. of PORTA i.e., RA4, 10 is the debounce delay of 10ms, 1 is the pin state i.e., if pin RA4 is high for 10ms then toggle oldstate.

@mailus

Your code is ok.

You can use

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if(PORTA.F4 == 1) {
    Delay_ms(30);
    if(PORTA.F4 == 1) {
 
        aldstste = ~oldstate;
 
    }
 
}
 
if(oldstate) {
       PORTB = ~PORTB
       Delay_ms(500);
}
else {
       PORTB = 0x00;
}

 

sbit sw at RA4_bit;
bit oldstate;

for the above code is there any missing key..i've just try on mikroc but it show some error
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top