PIC 16F84

General discussion on mikroC.
Post Reply
Author
Message
hazem
Posts: 4
Joined: 01 May 2010 08:39

PIC 16F84

#1 Post by hazem » 01 May 2010 08:42

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();

}
}

MHI
Posts: 56
Joined: 13 Mar 2010 20:52

Re: PIC 16F84

#2 Post by MHI » 01 May 2010 11:34

hello hazem,
I have tested your project on Proteus, It's working well,
Where is your problem ?

Regards

hazem
Posts: 4
Joined: 01 May 2010 08:39

Re: PIC 16F84

#3 Post by hazem » 01 May 2010 13:18

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

MHI
Posts: 56
Joined: 13 Mar 2010 20:52

Re: PIC 16F84

#4 Post by MHI » 01 May 2010 18:55

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

Post Reply

Return to “mikroC General”