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

Program stopping in the delay () function

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



Joined: 02 Sep 2017
Posts: 75

View user's profile Send private message Send e-mail

Program stopping in the delay () function
PostPosted: Wed Jul 04, 2018 8:40 am     Reply with quote

Friends, good afternoon. Can anybody help me? I do not know why any timed line increased below the trigger(); prototype is not executed while looping (true). It looks like the program for in delay(). If you remove the delay, the loop is executed by executing the trigger(); is really very strange. Program stopping in the delay() function;
Code:

#include <16F877A.h>

#FUSES NOWDT, HS, PUT, NOPROTECT, NODEBUG, BROWNOUT, NOLVP, NOCPD, NOWRT     
#use delay(clock= 20M)

//--->>>>>>>>>> O programa funciona sem estas diretivas fast_io nem tris_x

#use fast_io(c)

//*******COnecoes LCD*********
#define LCD_DB4   PIN_A4 // Pino bloco dados 4 no pino microcontrolador
#define LCD_DB5   PIN_A3
#define LCD_DB6   PIN_A2
#define LCD_DB7   PIN_A1
#define LCD_RS    PIN_E0
#define LCD_E     PIN_A5
#include <lcd4bitsMicrostronic.c>

#define trig    PIN_C1


// --- Protótipo da Função Auxiliar ---
void trigger();

// --- Variáveis Globais ---


void main()
{
      //Configura PORTS
      SET_TRIS_C(0X04); // C2 configurado como entrada, pois é o ECHO DO SENSOR e CCP1 do PIC. C1 é TRIG do 16F877A para sensor, ENTAO SAIDA.
      output_c(0x00);   
     
      Enable_Interrupts(GLOBAL);
      DISABLE_INTERRUPTS(INT_TIMER1);
      Enable_Interrupts(INT_CCP1 );  // USEI CCP1IE  = 0x01; Habilita interrupção do periférico CCP
      Setup_ccp1(CCP_CAPTURE_FE);   //  CCP1CON  = 0x04; CONFIGURA BYTE BORDA SUBIDA NOREGISTADOR
      Setup_Timer_1(T1_INTERNAL|T1_DIV_BY_2);
   
      //Inicializa LCD
      lcd_init();
      lcd_putc("\f");
      lcd_gotoxy(1,1); //lcd_gotoxy para coluna, linha
      printf(lcd_putc,"distancia");
      lcd_gotoxy(14,2); //lcd_gotoxy para coluna, linha
      printf(lcd_putc,"cm");
      delay_ms(100);
   
 while(TRUE)
   {
      trigger();                               //Chama a função de trigger

      delay_ms(100);                           //lEITURA DO PULSO A CADA 100ms Taxa de atualização
   
   } //end while
}// end void main     
      //TODO: User Code

void trigger()
{
  output_high(trig); // trih = 0x01; trig em nível high
  delay_us(10);      //por 10 micro segundos
  output_low(trig); //trig = 0x00;

} //end trigger
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Jul 04, 2018 9:06 am     Reply with quote

There is no sign of an interrupt handler for CCP1. The code will crash without this.
jacktaylor



Joined: 02 Sep 2017
Posts: 75

View user's profile Send private message Send e-mail

PostPosted: Wed Jul 04, 2018 9:59 am     Reply with quote

Ttelmah wrote:
There is no sign of an interrupt handler for CCP1. The code will crash without this.


Even commenting on all the configuration lines of the CCP1 module, the program is stopped in delay (); Commenting on the delay, the program executes the while (1) {trigger ();}

Note below.

Why is this happening?
Code:

#include <16F877A.h>

#FUSES NOWDT, HS, PUT, NOPROTECT, NODEBUG, BROWNOUT, NOLVP, NOCPD, NOWRT     
#use delay(clock= 20M)

//--->>>>>>>>>> O programa funciona sem estas diretivas fast_io nem tris_x

#use fast_io(c)

//*******COnecoes LCD*********
#define LCD_DB4   PIN_A4 // Pino bloco dados 4 no pino microcontrolador
#define LCD_DB5   PIN_A3
#define LCD_DB6   PIN_A2
#define LCD_DB7   PIN_A1
#define LCD_RS    PIN_E0
#define LCD_E     PIN_A5
#include <lcd4bitsMicrostronic.c>

#define trig    PIN_C1


// --- Protótipo da Função Auxiliar ---
void trigger();

// --- Variáveis Globais ---


void main()
{
      //Configura PORTS
      SET_TRIS_C(0X04); // C2 configurado como entrada, pois é o ECHO DO SENSOR e CCP1 do PIC. C1 é TRIG do 16F877A para sensor, ENTAO SAIDA.
      output_c(0x00);   
//!     
//!      Enable_Interrupts(GLOBAL);
//!      DISABLE_INTERRUPTS(INT_TIMER1);
//!      Enable_Interrupts(INT_CCP1 );  // USEI CCP1IE  = 0x01; Habilita interrupção do periférico CCP
//!      Setup_ccp1(CCP_CAPTURE_FE);   //  CCP1CON  = 0x04; CONFIGURA BYTE BORDA SUBIDA NOREGISTADOR
//!      Setup_Timer_1(T1_INTERNAL|T1_DIV_BY_2);
//!   
      //Inicializa LCD
//!      lcd_init();
//!      lcd_putc("\f");
//!      lcd_gotoxy(1,1); //lcd_gotoxy para coluna, linha
//!      printf(lcd_putc,"distancia");
//!      lcd_gotoxy(14,2); //lcd_gotoxy para coluna, linha
//!      printf(lcd_putc,"cm");
//!      delay_ms(100);
   
 while(TRUE)
   {
      trigger();                               //Chama a função de trigger

      delay_ms(100);                           //lEITURA DO PULSO A CADA 100ms Taxa de atualização
   
   } //end while
}// end void main     
      //TODO: User Code

void trigger()
{
  output_high(trig); // trih = 0x01; trig em nível high
  delay_us(10);      //por 10 micro segundos
  output_low(trig); //trig = 0x00;

} //end trigger
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Jul 04, 2018 10:02 am     Reply with quote

Are you running this 'for real' , or in a simulator?.
In a simulator, a delay can take ages to execute.
If 'for real', are you sure you will see/detect a 10uSec pulse every 100mSec?.
jacktaylor



Joined: 02 Sep 2017
Posts: 75

View user's profile Send private message Send e-mail

PostPosted: Wed Jul 04, 2018 10:57 am     Reply with quote

Ttelmah wrote:
Are you running this 'for real' , or in a simulator?.
In a simulator, a delay can take ages to execute.
If 'for real', are you sure you will see/detect a 10uSec pulse every 100mSec?.



It's you absolutely right. In the simulator without the delay_us (100);, I have the signal of the trigger and I can measure 10us of signal with ease in the virtual oscilloscope, when I put the delay_ms (100), it becomes more complicated to read the signal of 10us. In actual assembly I try to work the Echo signal of the Ultrasonic Sensor HC-SR04. And I was having problems with the Echo signal, so I was reducing the program until I got to the trigger. The ideal is to have even a real oscilloscope. Thank you Ttelmah.
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