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

how to memorize?

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



Joined: 28 Apr 2004
Posts: 18

View user's profile Send private message

how to memorize?
PostPosted: Fri May 07, 2004 4:08 am     Reply with quote

i have written the following program who's test voltage coming from an continual source. it works succesfully but i wish to make a cycle of the 4 tests and memorise every response one time living each one. so finally i have the reponse of the 4 voltage test.
if anyone help me to discuss about ideas.
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;
int1 wait=true;
int16 Counter=20000;


#int_TIMER2
TIMER2_isr()
{
     if (Counter)
      Counter--;
     else
     wait=true;
}

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


 void main( void )
    {
    long ADCvaleur;


      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();
      output_high (led1);
      output_high (led4);
      output_high (led7);
      output_high (led10);
      delay_ms(400);
      if (ADIF ==1)
      ADIF = 0;
      ADCvaleur = 0;

      while (wait)
         {
            setup_timer_2(T2_DIV_BY_4,5,5);
            enable_interrupts(INT_TIMER2);
            enable_interrupts(GLOBAL);
            ADCvaleur=read_ADC();
               if (ADCvaleur>Vctq)
                  {
                  output_low (led2);
                  output_low (led3);
                  output_low (led5);
                  output_low (led6);
                  output_low (led8);
                  output_low (led9);
                  output_low (led11);
                  output_low (led12);
                  output_low (led1);
                  output_low (led4);
                  output_low (led7);
                  output_low (led10);
                  delay_ms(400);
                  output_high (led1);
                  output_high (led4);
                  output_high (led7);
                  output_high (led10);
                  delay_ms(200);
                  }
               else
               {
                  if ((ADCvaleur<=tension_maxi_touche_0) && (ADCvaleur>=tension_mini_touche_0))
                     {
                     output_low (led3);
                     output_low (led1);
                     output_high (led2);
                     output_low (led4);
                     output_low (led5);
                     output_low (led6);
                     output_low (led7);
                     output_low (led8);
                     output_low (led9);
                     output_low (led10);
                     output_low (led11);
                     output_low (led12);
                     }
                        else

                  if ((ADCvaleur<=tension_maxi_touche_R) && (ADCvaleur>=tension_mini_touche_R))
                     {
                     output_low (led4);
                     output_low (led6);
                     output_high (led5);
                     output_low (led1);
                     output_low (led2);
                     output_low (led3);
                     output_low (led7);
                     output_low (led8);
                     output_low (led9);
                     output_low (led10);
                     output_low (led11);
                     output_low (led12);
                     }
                        else
                 if ((ADCvaleur<=tension_maxi_touche_plus) && (ADCvaleur>=tension_mini_touche_plus))
                     {
                     output_low (led7);
                     output_low (led9);
                     output_high (led8);
                     output_low (led1);
                     output_low (led2);
                     output_low (led3);
                     output_low (led4);
                     output_low (led5);
                     output_low (led6);
                     output_low (led10);
                     output_low (led11);
                     output_low (led12);
                     }
                        else
                 if ((ADCvaleur<=tension_maxi_touche_moins) && (ADCvaleur>=tension_mini_touche_moins))
                     {
                     output_low (led10);
                     output_high (led11);
                     output_low (led12);
                     output_low (led1);
                     output_low (led2);
                     output_low (led3);
                     output_low (led4);
                     output_low (led5);
                     output_low (led6);
                     output_low (led7);
                     output_low (led8);
                     output_low (led9);

                     }
                        else
                        {
                        output_low (led10);
                        output_low (led11);
                        output_high (led12);
                        output_low (led1);
                        output_low (led2);
                        output_high (led3);
                        output_low (led4);
                        output_low (led5);
                        output_high (led6);
                        output_low (led7);
                        output_low (led8);
                        output_high (led9);
                        }
                        }
                           }
                           }

_________________
nfs
SteveS



Joined: 27 Oct 2003
Posts: 126

View user's profile Send private message

PostPosted: Fri May 07, 2004 6:35 am     Reply with quote

Not sure I understand. If you want to keep the last four values then
create an array:

int16 values[4];

and have an index that increments each time through the loop. Is that what you mean?

Also, it looks like you use Timer2 to set the delay between samples by using the flag 'wait'. But I don't see where wait gets reset to false. And I don't see where you reset Counter to the initial value.

- SteveS
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