nfs
Joined: 28 Apr 2004 Posts: 18
|
non stop timer???? |
Posted: Thu May 06, 2004 5:46 am |
|
|
i fixed the following timer to count 20000 times of 100�s the once
the timer still in function over the time configured.
what's the matter?
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_high (led6);
output_low (led7);
output_low (led8);
output_high (led9);
output_low (led10);
output_low (led11);
output_high (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_high (led3);
output_low (led7);
output_low (led8);
output_high (led9);
output_low (led10);
output_low (led11);
output_high (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_high (led3);
output_low (led4);
output_low (led5);
output_high (led6);
output_low (led10);
output_low (led11);
output_high (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_high (led3);
output_low (led4);
output_low (led5);
output_high (led6);
output_low (led7);
output_low (led8);
output_high (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 |
|