Page 1 of 1

PIC 16F84

Posted: 01 May 2010 08:42
by hazem
Hello guys out there,, i knw it might sounds a little bit odd that nowadays someone is still using PIC 16F84,, its just i have a small project and it fits my needs,,, i wrote a very simple mikro-C code but yet it isn't working !!!!! can anyone help me out please ?

here is the code : it's very simple just couple of inputs and outputs !!!!



void forward(){
PORTB.F0 = 1;
PORTB.F2 = 1;
Delay_ms(6000);
PORTB.F2 = 0;
PORTB.F0=0;

PORTB.F0 = 1;
PORTB.F3 = 1;
Delay_ms(12000);
PORTB.F3 = 0;
PORTB.F0=0;

PORTB.F1 = 1;
PORTB.F2 = 1;
Delay_ms(6000);
PORTB.F2 = 0;
PORTB.F1=0;

PORTB.F1 = 1;
PORTB.F4 = 1;
Delay_ms(6000);
PORTB.F4 = 0;
PORTB.F1=0;

PORTB.F1 = 1;
PORTB.F3 = 1;
Delay_ms(12000);
PORTB.F3 = 0;
PORTB.F1=0;

PORTB.F0 = 1;
PORTB.F4 = 1;
Delay_ms(6000);
PORTB.F4 = 0;
PORTB.F0=0;

}
void backward(){
PORTB.F0 = 1;
PORTB.F4 = 1;
Delay_ms(6000);
PORTB.F4 = 0;
PORTB.F0=0;

PORTB.F1 = 1;
PORTB.F3 = 1;
Delay_ms(12000);
PORTB.F3 = 0;
PORTB.F1=0;

PORTB.F1 = 1;
PORTB.F4 = 1;
Delay_ms(6000);
PORTB.F4 = 0;
PORTB.F1=0;

PORTB.F1 = 1;
PORTB.F2 = 1;
Delay_ms(6000);
PORTB.F2 = 0;
PORTB.F1=0;

PORTB.F0 = 1;
PORTB.F3 = 1;
Delay_ms(12000);
PORTB.F3 = 0;
PORTB.F0=0;

PORTB.F0 = 1;
PORTB.F2 = 1;
Delay_ms(6000);
PORTB.F2 = 0;
PORTB.F0=0;

}
void CamMotor(){
PORTB.F0 = 1;
PORTB.F5 = 1;
Delay_ms(750);
PORTB.F5 = 0;
PORTB.F0=0;
}
void CamPosition(){
while(1){
if(PORTA.F0 == 1){
PORTB.F7 = 1;
PORTB.F6 = 0;
Delay_ms(1000);
PORTB.F7 = 0; }
if(PORTA.F1 == 1){
PORTB.F6 = 1;
PORTB.F7 = 0;
Delay_ms(1000);
PORTB.F6 = 0; }
if(PORTA.F2 == 1 || PORTA.F3 == 1)
break;
}

}
void main(){
TRISA = 0x0F;
TRISB = 0x00;
PORTB = 0x00;
while(1){
if(PORTA.F0 == 1)
forward();
if(PORTA.F1 == 1)
backward();
if(PORTA.F2 == 1)
CamMotor();
if(PORTA.F3 == 1)
CamPosition();

}
}

Re: PIC 16F84

Posted: 01 May 2010 11:34
by MHI
hello hazem,
I have tested your project on Proteus, It's working well,
Where is your problem ?

Regards

Re: PIC 16F84

Posted: 01 May 2010 13:18
by hazem
Thank you,, well when i connect the PIC to a breadboard containing 8MHz oscillator, VCC ,GND, and VCC to reset nothing happens or the ports starts sending bits in a random way !!! am I missing something in my connections ???

i read through the internet about something called analog inout and output,, does this has to do with anything ??? how can i disable it ??

Thank you

Re: PIC 16F84

Posted: 01 May 2010 18:55
by MHI
hazem

you should do nothing for analog input or output,
making trisa=0x0f; and trisb=0 is all you need for I/O configuration,
Probably you have some wiring or oscillator problem,

make sure to put the same oscillator that you have chosen in your mikroC program,
connect the quartz with its capacitor between OSC1 and OSC2,
VSS: Ground
Vdd: Vc
MCLR: Vc (button in btween to reset, if you want).

Best Regards