|
|
View previous topic :: View next topic |
Author |
Message |
umka
Joined: 28 Aug 2007 Posts: 99 Location: New Zealand
|
Help with Optimization |
Posted: Fri Nov 16, 2007 1:10 am |
|
|
I am trying to write a program that tests differant types of hand controllers that all use the same plug at the end but have differant functions and pin wirings. They use a DB15 connection so 15 pins maximum.
I want to use adc0 to select what type of hand controller is connected using if adc0 <10 controller x, if adc0>10 controller y etc. Then when the controller is selected it configures the pins and there functions. Then when a button is pressed on the control handle it displays the function of the pressed button on a lcd display.
so far i have written code like below to display the function when the corosponding pin goes high.
Code: | //****************************************************************************//
// //
// Mini-Me Right Hand Sure-Grip //
// //
//****************************************************************************//
#define P_1 Pin_A1 //
#define P_2 Pin_A2 //
#define P_3 Pin_A3 // Define Pins for DB15 connection
#define P_4 Pin_A4 //
#define P_5 Pin_A5 //
#define P_6 Pin_C0 //
void MM_RH_SG (void)
{
//PIN 1
output_high(P_1); //Supply voltage to handle
//PIN 2
if( input(P_2) == 1 ) //Spare button 1
{
printf(lcd_putc, "\nSpare B-1");
delay_ms(50);
}
//PIN 3
else if( input(P_3) == 1 ) //Spare button 2
{
printf(lcd_putc, "\nSpare B-2");
delay_ms(50);
}
//PIN 4
else if( input(P_3) == 1 ) //Rotate CW button 3
{
printf(lcd_putc, "\nRotate CW B-3");
delay_ms(50);
}
//PIN 5
else if( input(P_3) == 1 ) //Head open button 4
{
printf(lcd_putc, "\nHead Open B-4");
delay_ms(50);
}
//PIN 6
else if( input(P_3) == 1 ) //Head close trigger 1
{
printf(lcd_putc, "\nHead Open T-1");
delay_ms(50);
}
//PIN 7
//PIN 8
//PIN 9
//PIN 10
//PIN 11
//PIN 12
//PIN 13
//PIN 14
//PIN 15
else
{
printf(lcd_putc, "\fMini Me R/H SureGrip");
printf(lcd_putc, "\nNo Button Pressed");
delay_ms(50);
}
} |
then a differant controller
Code: | //****************************************************************************//
// //
// T10 Right Hand Sure-Grip //
// //
//****************************************************************************//
#define P_1 Pin_A1 //
#define P_2 Pin_A2 //
#define P_3 Pin_A3 //
#define P_4 Pin_A4 //
#define P_5 Pin_A5 //
#define P_6 Pin_C0 //
#define P_7 Pin_C1 //
#define P_8 Pin_C2 // Define Pins for DB15 connection
#define P_9 Pin_C3 //
#define P_10 Pin_D0 //
#define P_11 Pin_D1 //
void T10_RH_SG (void)
{
//PIN 1
output_high(P_1); //Supply voltage to handle
//PIN 9
output_high(P_9); //Supply voltage to handle
//PIN 10
output_high(P_10); //Supply voltage to handle
//PIN 2
if( input(P_2) == 1 ) // Urea Button 2
{
printf(lcd_putc, "\nUrea B-2");
delay_ms(50);
}
//PIN 3
else if( input(P_3) == 1 ) // Motor Reverse Button 6
{
printf(lcd_putc, "\nMotor Rev B-6");
delay_ms(50);
}
//PIN 4
else if( input(P_4) == 1 ) // Motor Forward Button 5
{
printf(lcd_putc, "\nMotor FWD B-5");
delay_ms(50);
}
//PIN 5
else if( input(P_5) == 1 ) // Drive arm close Trigger down
{
printf(lcd_putc, "\nDrive Arm Close T-1");
delay_ms(50);
}
//PIN 6
else if( input(P_6) == 1 ) // Drive arm open Trigger up
{
printf(lcd_putc, "\nDrive Arm Open T-2");
delay_ms(50);
}
//PIN 7
else if( input(P_7) == 1 ) // Grapple open Button 7
{
printf(lcd_putc, "\nGrapple Open B-7");
delay_ms(50);
}
//PIN 8
else if( input(P_8) == 1 ) // Bottom delimb open Button 3
{
printf(lcd_putc, "\nBtm Delimb Open B-3");
delay_ms(50);
}
//PIN 9 -- Supply
//PIN 10 -- Supply
//PIN 11
else if( input(P_11) == 1 ) // Grapple close Button 8
{
printf(lcd_putc, "\nGrapple Close B-8");
delay_ms(50);
}
//PIN 12
//PIN 13
//PIN 14
//PIN 15
else
{
printf(lcd_putc, "\fT10 R/H Sure-Grip");
printf(lcd_putc, "\nNo Button Pressed");
delay_ms(50);
}
} |
how do i tie them all together including the control selector so as to optimize the memery as i have about 16 controller to do listed in the #include below. all of the #includes are writen the same as the above two but can be changed if there is a better way to do it. i was thinking an interupt thats why i set out the main code like below.
Code: | #include <16F877a.h>
#device adc=8
#fuses XT NOLVP NOWDT NOPROTECT
#use delay(clock=4000000)
#include <Flex_LCD420.c>
#include <MM_RH_SG.c> //Mini-Me Right Hand Sure-Grip
#include <MM_LH_SG.c> //Mini-Me Left Hand Sure-Grip
#include <T10_RH_SG.c> //T10 Right Hand Sure-Grip
#include <T10_RH_SG_BUT.c> //T10 Right Hand Sure-Grip 8 Button
#include <T10_LH_SG.c> //T10 Left Hand Sure-Grip
#include <T10_RH_DF.c> //T10 Right Hand Danfoss
#include <T10_LH_DF.c> //T10 Left Hand Danfoss
#include <T10_PRE_KEY.c> //T10 Preset Keypad
#include <LR_RH_SG.c> //Logrite Right Hand Sure-Grip
#include <LR_RH_SG_BUT.c> //Logrite Right Hand Sure-Grip 8 Button
#include <LR_LH_SG.c> //Logrite Left Hand Sure-Grip
#include <LR_LH_SG_BUT.c> //Logrite Left Hand Sure-Grip 8 Button
#include <LR_RH_DF.c> //Logrite Right Hand Danfoss
#include <LR_LH_DF.c> //Logrite Left Hand Danfoss
//#include <T20_RH_SG.c> //Timberrite Right Hand Sure-Grip
//#include <T20_LH_SG.c> //Timberrite Left Hand Sure-Grip
unsigned int8 model = 0; //ADC Control Model Selector
void main()
{
MM_RH_SG();
MM_LH_SG();
T10_RH_SG();
T10_RH_SG_BUT();
T10_LH_SG();
T10_RH_DF();
T10_LH_DF();
T10_PRE_KEY();
LR_RH_SG();
LR_RH_SG_BUT();
LR_LH_SG();
LR_LH_SG_BUT();
LR_RH_DF();
LR_LH_DF();
lcd_init(); //LCD Initialize and Clear
printf(lcd_putc, "\f");
delay_ms(50);
setup_adc( ADC_CLOCK_INTERNAL ); //Setup ADC use timer 0 divide 1
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
while(1)
{
OUTPUT_A(0x00); //Clear Port A
OUTPUT_C(0x00); //Clear Port C
OUTPUT_D(0x00); //Clear Port D
set_adc_channel(0);
delay_ms(50);
model = read_adc(); //Read Control Model Selector
//NOTE: check if can leave out repition of all the top
// lines after initial selection
}
} |
any help appretiated |
|
|
SET
Joined: 15 Nov 2005 Posts: 161 Location: Glasgow, UK
|
|
Posted: Fri Nov 16, 2007 12:53 pm |
|
|
I'm intrigued - how can you tell which controller is connected by reading an analog voltage? |
|
|
umka
Joined: 28 Aug 2007 Posts: 99 Location: New Zealand
|
|
Posted: Fri Nov 16, 2007 3:15 pm |
|
|
i will use a ref value form the adc and then have and if statment if adc <10 do x if adc>10<20 do y if adc >20<30 do z and so on. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|