Haberler:

Eposta uyarılarını yanıtlamayınız ( ! ) https://bit.ly/2J7yi0d

Ana Menü

ana programda sorun

Başlatan OptimusPrime, 03 Haziran 2009, 08:34:08

ahmet2004

20 Mhz XTAL de çalışan kod. :?:

#include <18F452.h>
#device adc=10

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOOSCSEN                 //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES NOPUT                    //No Power Up Timer
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOCPD                    //No EE protection
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPD

#use delay(clock=20M)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) 

#define StepForOneRevolution  400         //Step for one revolution x2 
#define Forward               1 
#define Backward              0 
#define EngineRpmOffset       500 

#use fast_io(a) 
#use fast_io(b) 
#use fast_io(c) 
#use fast_io(d) 
#use fast_io(e)

unsigned int16 uiEngineRpm; 
unsigned int16 uiRevolution=(unsigned int16)(1+StepForOneRevolution); 
unsigned int8  bDirection=Forward; 
unsigned int8  bStepperIsActive=False; 

float volt0;
long uiADC;

#int_TIMER2 
void  TIMER2_isr(void) 
{ 
if(bDirection==Forward) output_low(PIN_A3); 
   else output_high(PIN_A3); 
    
if(uiRevolution<=(unsigned int16)(StepForOneRevolution)) { output_toggle(PIN_A2); uiRevolution++; bStepperIsActive=TRUE; } 
   else bStepperIsActive=FALSE
;

enable_interrupts(INT_TIMER2); 
return; 
} 

#int_EXT 
void  EXT_isr(void) 
{ 
//external interrupt on rising edge 
if(bStepperIsActive==FALSE) { 
                              bDirection=Forward; 
                              uiRevolution=(unsigned int16)(1); } 
enable_interrupts(INT_EXT); 
return; 
} 

#int_EXT1 
void  EXT1_isr(void) 
{ 
//external interrupt on rising edge 
if(bStepperIsActive==FALSE) { 
                              bDirection=Backward; 
                              uiRevolution=(unsigned int16)(1); } 
enable_interrupts(INT_EXT1); 
return; 
} 

#int_EXT2 
void  EXT2_isr(void) 
{ 
//external interrupt on rising edge 
//output_d(0x04); 
//output_d((uiEngineRpm>>2));  //burasi çalisiyor 
enable_interrupts(INT_EXT2); 
return; 
} 

#int_AD 
void  AD_isr(void)
{
uiADC=read_adc(ADC_READ_ONLY); 
output_d((uiADC>>2)); 
read_adc(ADC_START_ONLY);
enable_interrupts(INT_AD);
return; 
} 

void main(void) 
{
   setup_adc_ports(AN0); 
   setup_adc(ADC_CLOCK_DIV_32); 
   setup_psp(PSP_DISABLED); 
   setup_spi(SPI_SS_DISABLED); 
   setup_wdt(WDT_OFF); 
         setup_timer_0(RTCC_OFF);
         setup_timer_2(T2_DIV_BY_16,200,1);
         enable_interrupts(INT_TIMER2); 
         enable_interrupts(INT_EXT); 
         enable_interrupts(INT_EXT1); 
         enable_interrupts(INT_EXT2);
   enable_interrupts(INT_AD); 
   enable_interrupts(GLOBAL); 

set_tris_a(0b11111111); 
set_tris_b(0b00000000); 
set_tris_c(0b10000000); 
set_tris_d(0b00000000); 
set_tris_e(0b00000000);

output_b(0x00);
output_c(0x00);
output_d(0x00);
output_e(0x00);


      set_adc_channel(0); 
      read_adc(ADC_START_ONLY); 
      delay_us(13);
      
   while(1)
   {
      //disable_interrupts(GLOBAL);
      //printf(uiEngineRpm);
      volt0 = (uiADC * 4.8828125)/ 1024.0;
      printf("Volt0: %3.5f \n\r",volt0);
  
   }
}

OptimusPrime

https://donanimveyazilim.wordpress.com || Cihân-ârâ cihân içredir ârâyı bilmezler, O mâhîler ki deryâ içredir deryâyı bilmezler ||