Pic 16f84a help me plz. I am new

Status
Not open for further replies.

cellcare

Newbie level 4
Joined
Apr 17, 2010
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
uttar pradesh
Activity points
1,328
i am new in microcontroller , my led blinking program PORTA.F1 & PORTA.F2 not work Properly. plz solv my problam.

microcontroller= PIC 16F84A,]



SORCE CODE in mikro c pro,

void main() {

TRISA = 0xff;
TRISB = 0x00 ;
while (1){
if(PORTA.f1==0){

{
PORTB = 0x0f;
delay_ms(150);
PORTB = 0xff;
delay_ms(150);
PORTB = 0x0f;
delay_ms(150);
PORTB = 0xff;
delay_ms(150);
PORTB = 0x0f;
delay_ms(150);
PORTB = 0xff;
delay_ms(500);
PORTB = 0xff;
delay_ms(150);
PORTB = 0xf0;
delay_ms(150);
PORTB = 0xff;
delay_ms(150);
PORTB = 0xf0;
delay_ms(150);
PORTB = 0xff;
delay_ms(150);
PORTB = 0xf0;
delay_ms(150);
PORTB = 0xff;
delay_ms(500);
PORTB = 0xff;

}



while (1){
if(PORTA.f2==0 ){

PORTB = 0x0f;
delay_ms(150);
PORTB = 0xff;
delay_ms(150);
PORTB = 0x0f;
delay_ms(150);
PORTB = 0xff;
delay_ms(150);
PORTB = 0x0f;
delay_ms(150);
PORTB = 0xff;
delay_ms(3000);
PORTB = 0xff;
delay_ms(150);
PORTB = 0xf0;
delay_ms(150);
PORTB = 0xff;
delay_ms(150);
PORTB = 0xf0;
delay_ms(150);
PORTB = 0xff;
delay_ms(150);
PORTB = 0xf0;
delay_ms(150);
PORTB = 0xff;
delay_ms(3000);
PORTB = 0xff;
}
}
else
PORTB = 0xff;
}
}
 

what is f1 and f2?? switches??
if switches at ra0 and ra1 than use this:
if(ra0_bit==0) and if(ra1_bit==0)
also this program is not good, you can do this by using loops; for loop etc.this prog should be in 10 to 20 lines max.
 
Dear mr Malik
thanku for help,
As for have given the example my problem could not solv ,
sir, i want to make a switching function whenever. i need to on f1 or f2 this should
be run on f1 and consequent f2.
either it should be on by f2 first or f1 first. when i chang my switch from f1 to f2 it work
but when i turn my switch from f2 to f1 it did not work . please give some step to modify my
program.
 

yah; because you are using forever loop (while) that is why 'switch from f2 to f1 do not work; their should be one while(1) loop.
can you show your schematic?
 

You should indent your code and check for bracket matches to prevent weird scoping. You have two forever loops so only the first one gets executed. You should also think about wrapping the duplicate codes in functions so it's not so verbose. I didn't wrap the function for you so you can see what's wrong with your code.

Code:
// microcontroller= PIC 16F84A,]
// SORCE CODE in mikro c pro,

void main()
{
     TRISA = 0xff;
     TRISB = 0x00 ;
     while (1)
    {
        if(PORTA.f1==0)
       {
           PORTB = 0x0f;
           delay_ms(150);
           PORTB = 0xff;
           delay_ms(150);
           PORTB = 0x0f;
           delay_ms(150);
           PORTB = 0xff;
           delay_ms(150);
           PORTB = 0x0f;
           delay_ms(150);
           PORTB = 0xff;
           delay_ms(500);
           PORTB = 0xff;
           delay_ms(150);
           PORTB = 0xf0;
           delay_ms(150);
           PORTB = 0xff;
           delay_ms(150);
           PORTB = 0xf0;
           delay_ms(150);
           PORTB = 0xff;
           delay_ms(150);
           PORTB = 0xf0;
           delay_ms(150);
           PORTB = 0xff;
           delay_ms(500);
           PORTB = 0xff;
       }
       else if(PORTA.f2==0 )
       {
           PORTB = 0x0f;
           delay_ms(150);
           PORTB = 0xff;
           delay_ms(150);
           PORTB = 0x0f;
           delay_ms(150);
           PORTB = 0xff;
           delay_ms(150);
           PORTB = 0x0f;
           delay_ms(150);
           PORTB = 0xff;
           delay_ms(3000);
           PORTB = 0xff;
           delay_ms(150);
           PORTB = 0xf0;
           delay_ms(150);
           PORTB = 0xff;
           delay_ms(150);
           PORTB = 0xf0;
           delay_ms(150);
           PORTB = 0xff;
           delay_ms(150);
           PORTB = 0xf0;
           delay_ms(150);
           PORTB = 0xff;
           delay_ms(3000);
           PORTB = 0xff;
       }
       else
           PORTB = 0xff;
    }
}
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…