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

about this program

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







about this program
PostPosted: Wed May 12, 2004 7:11 am     Reply with quote

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;
long ADCvtot;
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 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)
                        {
                        output_high (led1);
                        }
                        else
                           if (ADCvaleur=Vppfluct)
                           {
                             output_high(led5);
                             delay_ms(2500);
                             disable_interrupts (INT_TIMER2);
                             delay_ms(10);
                             ADCvaleur=read_ADC();
                               if ((ADCvaleur<=tension_maxi_touche_0) && (ADCvaleur>=tension_mini_touche_0))
                                 {
                                 output_high(led6);
                                 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_0) && (ADCvaleur>=tension_mini_touche_0));              /* increment count, is it ten counts yet? */
                                 disable_interrupts (INT_RTCC);    /* don't allow interrupts */
                                 ADCvtot /= 500;    /* division par 500 échantillons pour calculer la moyenne des tensions relevée */
                                 if ((ADCvtot<=tension_maxi_touche_0) && (ADCvtot>=tension_mini_touche_0))
                                 {
                                 continue;
                                 }
                                 else
                                 {
                                 output_high(led3);
                                 }
                                 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)
                                    {
                                    output_high(led7);
                                    delay_ms(2500);
                                    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(led2);
                                    while ((ADCvaleur>=Vppfluct) && (counter1=199));
                                    disable_interrupts(INT_timer2);
                                    }
                                 }
                                else
                                    output_high(led3);
                                 }
                               else
                              output_high(led3);
                            }

               if ((counter1++==19999)&&(ADCvaleur>=Vppfluct))
               {
               output_high(led3);

               output_low(led1);
               }

          }


it seems to be some bugs or mistakes on this program?
sone help me plz
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Wed May 12, 2004 7:59 am     Reply with quote

When you have a problem thats too big to solve you have to break it into smaller parts. For example you know that you are getting good results from everything but the output pins. Write a simple program to toggle the output pins. Build on it one piece at a time until you are back at the program you have now. That way you will know where you it broke.
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