mrarslanahmed
Full Member level 2
- Joined
- Nov 15, 2011
- Messages
- 143
- Helped
- 6
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 1,298
- Location
- gujranwala pakistan
- Activity points
- 2,205
It seems it is not OK for you...is it okay to reset or not OK?
#define internal_oscilator_frequency 0x71; // 0b01110010; 8 MHZ internal oscillator enabled
#define clear_bytes 00;
#define as_output 00;
#define as_input 255;
#define all_high 255;
#define all_low 00;
#define off 00;
#define on 255;
bit timer_0_ready;
const int motor_wait_check = 2000;
/*// volatile variable may change its value during runtime independently from the program*/
// volatile int MAXIMUM VALUE OF 281
volatile int motor_forward_count = 0; // used when motor is operating without left right being pressed
volatile int motor_forward_left_count = 0; // used when motor is operating with left being pressed
volatile int motor_forward_right_count= 0; // used when motor is operating with right being pressed
volatile int motor_back_count = 0; // used when motor is operating without left right being pressed
volatile int motor_back_left_count = 0; // used when motor is operating with left being pressed
volatile int motor_back_right_count= 0; // used when motor is operating with right being pressed
volatile int timer_0_jumps_check_1;
volatile int timer_0_jumps_check_2;
volatile int motor_initiated;
void initialise_global();
void all_motors_off();
void update_counters();
void clear_ports();
void IO_configuration();
void TImer1_Gate_Configuration();
void timer0_configuration();
void all_motors_off();
void motor_forward();
void motor_forward_left();
void motor_forward_right();
void motor_back();
void motor_back_left();
void motor_back_right();
void start_robot_to_work();
/////////////////////////////////////////////
/////////////////////////////////////////////
sbit L293_REVERSE_IP_DIR at TRISD.B0;
sbit L293_foward_IP_DIR at TRISD.B1;
sbit L293_LEFT_IP_DIR at TRISD.B2;
sbit L293_RIGHT_IP_DIR at TRISD.B3;
sbit Remote_control_forward_signal_DIR at TRISD.B4;
sbit Remote_control_back_signal_DIR at TRISD.B5;
sbit Remote_control_left_signal_DIR at TRISD.B6;
sbit Remote_control_right_signal_DIR at TRISD.B7;
sbit L293_REVERSE_IP at PORTD.B0; //
sbit L293_FORWARD_IP at PORTD.B1; // COMMAND FROM THE REMOTE LOCATION TO THE CONTROLER
sbit L293_LEFT_IP at PORTD.B2; //
sbit L293_RIGHT_IP at PORTD.B3; //
sbit Remote_control_forward_signal at PORTD.B4; // COMMAND FROM THE CONTROLLER TO THE MOTORS VOA L293
sbit Remote_control_back_signal at PORTD.B5;
sbit Remote_control_left_signal at PORTD.B6;
sbit Remote_control_right_signal at PORTD.B7;
///
/////////////////////////////////////////////
/*we will make an array whcih can be used to store data of 10
different inputs, the recording will start as soon as any one key
forward or reverse is pressed and after that if key is not pressed
for specied time say 5 seconds then robot will continue the path it
stored
*/
/////////////////////////////////////////////
sbit T1__G at PORTB.b5;
sbit T1__G_dir at TRISB.b5;
void interrupt()
{
INTCON.GIE=0;
INTCON.PEIE=0;
PIR1.TMR1IF=0; // clear the timer 1 interupt flag
if(T0IF_bit && !T1__G && motor_initiated==1)
{
portc=0xff;
timer_0_jumps_check_1++;
if(timer_0_jumps_check_1==150) // approximatly 5 seconds gap
{
timer_0_jumps_check_2++;
timer_0_jumps_check_1=0;
if(timer_0_jumps_check_2==1) // set this to have time as multiple 5
{
start_robot_to_work();
timer_0_jumps_check_2=0;
portc=0x00;
}
}
}
if(T1__G)
{
update_counters();
}
tmr1h=0;
tmr1l=0; // these values are set temporarily will be chaged as per interupt routine time
INTCON.TMR0IF=0;
INTCON.GIE=1;
INTCON.PEIE=1;
}
void main()
{
osccon=internal_oscilator_frequency;
initialise_global();
clear_ports();
IO_configuration();
TImer1_Gate_Configuration();
timer0_configuration();
all_motors_off();
T1Con=0xB4;
timer_0_ready=0;
timer_0_ready=1;
while(1)
{
if(T1__g)
{
motor_initiated=1;
T1Con=0xB5;
while (T1__G)
{
if(Remote_control_forward_signal)
{
if(Remote_control_left_signal)
{
motor_forward_left();
}
else if(Remote_control_right_signal)
{
motor_forward_right();
}
else
motor_forward();
}
else if(Remote_control_back_signal)
{
if(Remote_control_left_signal)
{
motor_back_left();
}
else if(Remote_control_right_signal)
{
motor_back_right();
}
else
motor_back();
}
// just done not necessary
} // end of while timer gate 1
}
else
{
T1Con.TMR1ON=84;
all_motors_off();
}
}
}
void initialise_global()
{
timer_0_jumps_check_1=0;
timer_0_jumps_check_2=0;
motor_initiated=0;
}
void update_counters()
{
if(Remote_control_forward_signal)
{
if(Remote_control_left_signal)
{Motor_forward_left_count=Motor_forward_left_count+1;}
else if(Remote_control_right_signal)
{Motor_forward_right_count=Motor_forward_right_count+1;}
else Motor_forward_count=Motor_forward_count+1;
}
else if(Remote_control_back_signal)
{
if(Remote_control_left_signal)
{Motor_back_left_count=Motor_back_left_count+1;}
else if(Remote_control_right_signal)
{Motor_back_right_count=Motor_back_right_count+1;}
else Motor_back_count=Motor_back_count+1;
}
}
void clear_ports()
{
// port are cleared
trisa=as_output;
trisB=as_output;
trisc=as_output;
trisd=as_output;
trise=as_output;
porta=clear_bytes;
portb=clear_bytes;
portc=clear_bytes;
portd=clear_bytes;
porte=clear_bytes;
}
void test_check()
{
porta=all_high;
portb=all_high;
portc=all_high;
portd=all_high;
porte=all_high;
Delay_ms(50);
porta=all_low;
portb=all_low;
portc=all_low;
portd=all_low;
porte=all_low;
Delay_ms(50);
}
void motor_check()
{
Remote_control_forward_signal=all_high;
Delay_ms(motor_wait_check);
Remote_control_back_signal=all_high;
Delay_ms(motor_wait_check);
Remote_control_left_signal=all_high;
Delay_ms(motor_wait_check);
Remote_control_right_signal=all_high;
Delay_ms(motor_wait_check);
}
void IO_configuration()
{
L293_foward_IP_DIR = as_output;
L293_REVERSE_IP_DIR= as_output;
L293_RIGHT_IP_DIR= as_output;
L293_LEFT_IP_DIR= as_output;
T1__G_dir= as_input;
Remote_control_forward_signal_DIR= as_input;
Remote_control_left_signal_DIR= as_input;
Remote_control_right_signal_DIR= as_input;
Remote_control_back_signal_DIR =as_input;
ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
}
void all_motors_off()
{
L293_REVERSE_IP=off;
L293_FORWARD_IP=off;
L293_LEFT_IP=off;
L293_RIGHT_IP=off;
}
void motor_forward()
{
L293_REVERSE_IP=off;
L293_FORWARD_IP=on;
L293_LEFT_IP=off;
L293_RIGHT_IP=off;
}
void motor_forward_left()
{
L293_REVERSE_IP=off;
L293_FORWARD_IP=on;
L293_LEFT_IP=on;
L293_RIGHT_IP=off;
}
void motor_forward_right()
{
L293_REVERSE_IP=off;
L293_FORWARD_IP=on;
L293_LEFT_IP=off;
L293_RIGHT_IP=on;
}
void motor_back()
{
L293_REVERSE_IP=on;
L293_FORWARD_IP=off;
L293_LEFT_IP=off;
L293_RIGHT_IP=off;
}
void motor_back_left()
{
L293_REVERSE_IP=on;
L293_FORWARD_IP=off;
L293_LEFT_IP=on;
L293_RIGHT_IP=off;
}
void motor_back_right()
{
L293_REVERSE_IP=on;
L293_FORWARD_IP=off;
L293_LEFT_IP=off;
L293_RIGHT_IP=on;
}
void timer0_configuration()
{
trisa=0;
intcon=0xa0;
option_reg=0x07;
ccp1con=0;
trisd=0;
portd=0;
}
void TImer1_Gate_Configuration()
{
CM2CON1.T1GSS=1; // to take pulse from gate
T1CON.T1GINV=0; // measures only when gate is high
TMR1GE_Bit=1; // enable t1gate
T1CON.TMR1CS=0; // Fosc/4 if it was 1 then it would be waiting for the pulses from pin 15
T1CON.T1CKPS0=1;
T1CON.T1CKPS1=1; // prescalor set 8 to measure maximum time =65536*8
T1CON.T1SYNC=1; // run synchronously
T1CON=0X74;
PIE1.TMR1IE=1;
INTCON.GIE=1;
INTCON.PEIE=1;
TMR1H=0;
TMR1L=0;
}
void start_robot_to_work()
{
// in this function robot will start repeating its function
portc=00;
}
wdt is the watchdog timer.wdt is resetting
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?