PIC 16F84
Posted: 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();
}
}
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();
}
}