|
|
View previous topic :: View next topic |
Author |
Message |
nfs
Joined: 28 Apr 2004 Posts: 18
|
how to pass "led" through function |
Posted: Tue May 11, 2004 9:44 am |
|
|
#define led1 PIN_A1
#define led1 PIN_A2
#define led1 PIN_A3
#define tension_maxi_touche_0 34
void calcul (ledx,int16 tension_maxi_touche_x,int16 tension_mini_touche_x,int1 ledy,int1 ledz)
{.....................
}
void main void
{
calcul(led1,tension_maxi_touche_0,tension_mini_touche_0,led2,led3);
}
so how can i set led in the function _________________ nfs |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Tue May 11, 2004 10:07 am |
|
|
Change
ledx
to this
Int1 ledx
Also you can not define a constant (led1) to have several values |
|
|
nfs
Joined: 28 Apr 2004 Posts: 18
|
re |
Posted: Tue May 11, 2004 10:12 am |
|
|
i've changed this but no result _________________ nfs |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Tue May 11, 2004 11:28 am |
|
|
Try this:
Code: |
void calcul(int8 ledx)
{
switch(ledx)
{
CASE 0:
output_high(PIN_A1);
break;
CASE 1:
output_high(PIN_A2);
break;
CASE 2:
output_high(PIN_A3);
break;
default:
break;
}
}
void main void
{
int8 led;
calcul(led);
while(1)
{
;
}
}
|
Just pass the correct number for the LED you want turned on. |
|
|
nfs
Joined: 28 Apr 2004 Posts: 18
|
re |
Posted: Wed May 12, 2004 2:04 am |
|
|
i've to pass more than one led into function like this code:
Code: |
#include <16F876.h>
/* Set configuration bits in the PIC processor */
#fuses XT, NOPROTECT, NOPUT, NOWDT, NOBROWNOUT, NOLVP, NOCPD, NOWRT
//crystal, no watchdog timer, no low programming, no powerup timer, noprotect=memory protection off
#device adc=10
#device *=16
#use delay (clock=4000000) /* sets appropriate compiler constants 1�second instruction cycle */
#use standard_io ( a )
#use standard_io ( b )
#use standard_io ( c )
#define led1 PIN_A1 //led jaune commutateur '0'
#define led2 PIN_A2 //led verte commutateur '0'
#define led3 PIN_A3 //led rouge commutateur '0'
#define led4 PIN_A5 //led jaune commutateur 'R'
#define led5 PIN_B0 //led verte commutateur 'R'
#define led6 PIN_B1 //led rouge commutateur 'R'
#define led7 PIN_B2 //led jaune commutateur '+'
#define led8 PIN_B3 //led verte commutateur '+'
#define led9 PIN_B4 //led rouge commutateur '+'
#define led10 PIN_B5 //led jaune commutateur '-'
#define led11 PIN_B6 //led verte commutateur '-'
#define led12 PIN_B7 //led rouge commutateur '-'
#define Vpp 1024 //seuil maxi de tension
#define Vppfluct 1003 //seuil autoris� de fluctuation de la tension
#define Vppmin 973 //seuil pour lequel la tension est pass�e du niveau haut � un niveau plus bas*****
#define Vss 0 //seuil minimal de tension
#define Vctq 921 //seuil de chute de la tension
#define tension_maxi_touche_0 34
#define tension_mini_touche_0 0
#define tension_maxi_touche_R 790
#define tension_mini_touche_R 750
#define tension_maxi_touche_plus 523
#define tension_mini_touche_plus 463
#define tension_maxi_touche_moins 287
#define tension_mini_touche_moins 245
#define txPC PIN_C6
#define rxPC PIN_C7
#use RS232(BAUD=9600,BITS=8,XMIT=PIN_C6,RCV=PIN_C7)
#bit ADFM_BIT=0x9F.7
#bit PCFG3_BIT=0X9F.3
#bit PCFG2_BIT=0X9F.2
#bit PCFG1_BIT=0X9F.1
#bit PCFG0_BIT=0X9F.0
#byte INTCON = 0x0b //registre des interruptions
#byte PIE1 = 0x8c //registre contenant les autorisations d'interruptions
#byte PIR1 = 0x0c
#byte ADCON0 = 0x1f //registre du convertisseur
#byte ADCON1 = 0x9f //r�le des pins+justification du resultat de la conversion
#byte ADRESH = 0x1e
#byte ADRESL = 0x9e
#byte port_b = 0x06
#byte port_c = 0x07
#bit GO_DONE = ADCON0.2
#bit ADON = ADCON0.0
#bit ADIE = PIE1.6
#bit ADIF = PIR1.6
#define SET_TRIS_A = 0b00001; // PORTA AN0 entr�e et les autres en sortie
#define SET_TRIS_B = 0x00; // PORTB en sortie
#define TMR1IE = PIE1.0
#define TMR1IF = PIR1.0
int16 us;
int16 ADCvaleur;
long ADCvtot;
int1 wait=true;
long Counter1;
int8 Counter2=99;
int8 counter3 =499;
int8 cnt;
#int_TIMER2
TIMER2_isr()
{
Counter1++;
ADIF=0;
}
void InitialiseADC ()
{
setup_port_a( RA0_ANALOG );
setup_adc( ADC_CLOCK_DIV_8 );
set_adc_channel( 0 );
delay_us(10);
}
#int_rtcc
isr()
{
cnt++;
}
void calcul (int1 ledx,int16 tension_maxi_touche_x,int16 tension_mini_touche_x,int1 ledy,int1 ledz)
{
setup_timer_2(T2_DIV_BY_4,5,5);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
ADCvaleur=read_ADC();
Counter1=0;
while (Counter1<19999)
{
ADCvaleur=read_ADC();
if (ADCvaleur>Vppfluct)
{
output_high (ledx);
}
else
if (ADCvaleur=Vppfluct)
{
disable_interrupts ( INT_TIMER2 );
delay_ms(10);
ADCvaleur=read_ADC();
if ((ADCvaleur<=tension_maxi_touche_x) && (ADCvaleur>=tension_mini_touche_x))
{
setup_counters(RTCC_INTERNAL, RTCC_DIV_2);
enable_interrupts (INT_RTCC);
enable_interrupts ( GLOBAL );
set_rtcc (216);
do
{
ADCvaleur = Read_ADC(); /* read the ADC */
ADCvtot += ADCvaleur; /* add it to total, for later averaging */
}
while ((cnt <= counter3) && (ADCvaleur<=tension_maxi_touche_x) && (ADCvaleur>=tension_mini_touche_x)); /* increment count, is it ten counts yet? */
disable_interrupts ( INT_RTCC ); /* don't allow interrupts during display */
ADCvtot /= 500; /* division par 500 �chantillons pour calculer la moyenne des tensions relev�e */
setup_timer_2(T2_DIV_BY_4,10,5);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
ADCvaleur=read_ADC();
if (ADCvaleur == ADCvtot+ADCvtot*0.1)
{
disable_interrupts(INT_timer2);
delay_ms(20);
counter1=0;
setup_timer_2(T2_DIV_BY_4,15,5);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
ADCvaleur=read_ADC();
do
output_high(ledy);
while ((ADCvaleur>=Vppfluct) && (counter1=199));
disable_interrupts(INT_timer2);
}
}
else
output_high(ledz);
}
else
output_high(ledz);
}
if (counter1=19999)
{
output_high(ledz);
output_low(ledx);
}
}
}
void main( void )
{
long ADCvaleur;
long ADCvtot;
OUTPUT_B(0x00);// clear all pins on port b
ADCON0=0x81; // fosc/32, RA0, a/d off, a/d operating
ADCON1=0x8E; // an0 is a/d input, rest port a digital, internal ref, right justified
INTCON=0xc0; // enable global interrupts and peripherals
InitialiseADC();
if (ADIF ==1)
ADIF = 0;
ADCvaleur = 0;
ADCvtot = 0;
calcul(led1,tension_maxi_touche_0,tension_mini_touche_0,led2,led3);
delay_ms(1000);
calcul(led4,tension_maxi_touche_R,tension_mini_touche_R,led5,led6);
delay_ms(1000);
calcul(led7,tension_maxi_touche_plus,tension_mini_touche_plus,led8,led9);
delay_ms(1000);
calcul(led10,tension_maxi_touche_moins,tension_mini_touche_moins,led11,led12);
delay_ms(1000);
}
|
_________________ nfs |
|
|
|
|
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
|