CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

it's toooo long but how to!!!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rachel
Guest







it's toooo long but how to!!!
PostPosted: Thu May 13, 2004 10:48 am     Reply with quote

i want to pass led1, led2, led3 into function to execute it with other output(led)
this is the program:
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 ADCvaleur;
int32 ADCvtot;
int32 Counter1;
int32 Counter2;
int32 counter3 =499;
int32 cnt;

#int_TIMER2
TIMER2_isr()
{
Counter1++;
Counter2--;
ADIF=0;
}

void InitialiseADC ()
{
setup_port_a( RA0_ANALOG );
setup_adc( ADC_CLOCK_DIV_8 );
set_adc_channel( 0 );
delay_us(10);
}

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;

            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)             //if1
                        {
                        output_high (led1);
                        }
                        else
                           if (ADCvaleur=Vppfluct)
                           {
                             output_low(led1);
                             disable_interrupts (INT_TIMER2);
                             delay_ms(2100);
                             ADCvaleur=read_ADC();
                               if ((ADCvaleur<=tension_maxi_touche_0) && (ADCvaleur>=tension_mini_touche_0))
                                 {
                                 output_high(led4);
                                 delay_ms(2000);
                                 counter1==0;
                                 setup_timer_2(T2_DIV_BY_4,5,5);
                                 enable_interrupts(INT_TIMER2);
                                 enable_interrupts(GLOBAL);
                                 ADCvaleur=read_ADC();
                                 while ((counter1<=counter3) && (ADCvaleur<=tension_maxi_touche_0) && (ADCvaleur>=tension_mini_touche_0));/* increment count */
                                 {
                                 ADCvaleur = Read_ADC();           /* read the ADC */
                                 ADCvtot = ADCvtot + ADCvaleur;           /* add it to total, for later averaging */
                                 }
                                 disable_interrupts (INT_TIMER2);    /* don't allow interrupts */
                                 ADCvtot /= (long)500;    /* division par 500 échantillons pour calculer la moyenne des tensions relevée */
                                 output_high(led6);
                                 if ((ADCvtot<=tension_maxi_touche_0) && (ADCvtot>=tension_mini_touche_0))
                                 {
                                 output_high(led7);
                                 }
                                 else
                                 {
                                 output_high(led3);
                                 }
                                 delay_ms(2000);
                                 counter1==0;
                                 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);
                                    output_high(led8);
                                    delay_ms(2000);
                                    delay_ms(20);
                                    counter2==200;
                                    setup_timer_2(T2_DIV_BY_4,15,5);
                                    enable_interrupts(INT_TIMER2);
                                    enable_interrupts(GLOBAL);
                                    ADCvaleur=read_ADC();
                                    if ((ADCvaleur>=Vppfluct) && (counter2>=0))
                                    {
                                    output_high(led2);
                                    disable_interrupts(INT_timer2);
                                    }
                                    else
                                    output_high(led3);
                                 }
                                else
                                    output_high(led3);
                                 }
                               else
                              output_high(led3);
                            }
               }

               if ((counter1++==19999)&&(ADCvaleur>=Vppfluct))
               {
               disable_interrupts (INT_TIMER2);
               output_high(led3);
               output_low(led1);
               
               }
          }


thank you
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu May 13, 2004 12:38 pm     Reply with quote

Different nick-name and subject, same question..... ?????

http://www.ccsinfo.com/forum/viewtopic.php?t=19284

Crying or Very sad
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri May 14, 2004 1:24 am     Reply with quote

Dear Rachel , nfs4, or whatever nickname you choose next time,

The people in this forum, and all forums in general, are willing to help you, but they are not going to do your work for you!

Just dumping a large packet of code and saying it doesn't work is very impolite. We all have limited time, so try to be as specific with your problem as possible. Describe exactly what your program is supposed to do, what is working and what is not. And as a general rule, never post more than 20 lines of code unless asked for. If your program is larger than those 20 lines, then create a new program with only the problem part in it. Yes, this is a lot of work for you but saves us a lot of time. If you want us to help you, you have to make it easy for us.

I will give you the same advice as Neutone gave you in your previous thread: Debug your code by starting with a very small program and confirm that this works. Then add more code to it and confirm it still works. Continue this process until it stops working, than you will know there was an error in the last part added.

Without knowing what your code is supposed to do, one possible bug in your code:
Code:

while ((counter1<=counter3) && (ADCvaleur<=tension_maxi_touche_0) && (ADCvaleur>=tension_mini_touche_0));/* increment count */
{
    ADCvaleur = Read_ADC();           /* read the ADC */
    ADCvtot = ADCvtot + ADCvaleur;           /* add it to total, for later averaging */
}


Are you sure you want the ';' after the while statement?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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