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 CCS Technical Support

PIC10F220 and Sleep()

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



Joined: 22 Aug 2005
Posts: 275

View user's profile Send private message

PIC10F220 and Sleep()
PostPosted: Fri Jul 15, 2011 8:39 am     Reply with quote

Hi to everybody,

I can't solve problem with PIC10F220 and sleep() function. The work of circuit is quite simple. The PIC is powered by 3V battery. Every 2,38 seconds wake-up and test level of one pin. In case of low level do some beeps by buzzer.

The problem is:
Every wake-up time there's a change level of pin for 40us. This change level sound buzzer for a little time.

Does it normal ?

This is simple program
Code:

#include  <10F220.H>
#include "def220.c"

#FUSES NOWDT                     
#FUSES NOMCLR               
#FUSES PROTECT
#FUSES IOSC8

#use delay(clock=4000000,RESTART_WDT)

#use fast_io(B)

int      codice_reset;
int      conteggio_routine_buzzer;
int      nr_beep;
int    codice_buzzer;


int16   conteggio_attesa;
int1   liquido_presente;

#define durata_beep 250
#define attesa_beep 10



//Definisci bit I/O
#bit ingresso_livello=GPIO.1
#bit buzzer=GPIO.0
#bit uscita_pwm=GPIO.2

/*
*************************************************
Routine gestione buzzer

int      nr_beep;
int      durata_beep;
int      attesa_beep;
int      conteggio_durata_beep;
int      conteggio_attesa_beep;
int    codice_buzzer;
*************************************************
*/

void gestione_buzzer(){

   switch (codice_buzzer){
      case 0:
      buzzer=false;
      break;

      case 1:
      conteggio_routine_buzzer=durata_beep;
      codice_buzzer=2;
      break;

      case 2:
      buzzer^=1;
      conteggio_routine_buzzer--;
      if (conteggio_routine_buzzer==0){
         codice_buzzer=3;
         conteggio_routine_buzzer=attesa_beep;
      }
      break;

      case 3:
      buzzer=false;
      delay_ms(10);
      conteggio_routine_buzzer--;
      if (conteggio_routine_buzzer==0){
         codice_buzzer=4;
      }
      break;

      case 4:
      nr_beep--;
      if (nr_beep==0)
         codice_buzzer=0;
      else
         codice_buzzer=1;   
   }
}


//#pragma zero_ram
void main() {

long i;
SET_TRIS_B(0b00000010);

SETUP_ADC_PORTS(NO_ANALOGS);
//Definisci interrupt TIMER0 ogni 100uS

//SETUP_TIMER_0(RTCC_DIV_1|RTCC_INTERNAL|RTCC_8_BIT);

SETUP_WDT(WDT_2304MS|DISABLE_WAKEUP_ON_CHANGE|PIN_CHANGE_FROM_SLEEP);

codice_reset= RESTART_CAUSE();
   if (codice_reset==NORMAL_POWER_UP){
      for(i=0;i<50;i++){
         delay_us(50);
         buzzer^=1;
      }   
   }
   if(codice_reset==MCLR_FROM_RUN){

      conteggio_attesa++;
      if(conteggio_attesa>3){

// PWM
         SET_TRIS_B(0b00000010);

         if (liquido_presente==false){

         codice_buzzer=1;
         nr_beep=3;
            while(codice_buzzer!=0){         
               delay_us(100);
               gestione_buzzer();
            }
         }
      conteggio_attesa=0;   
      }
   }
//buzzer=0;
//uscita_pwm=0;
SET_TRIS_B(0b00001111);
sleep();
delay_cycles(2);
}


Thanks for help,
Regards,
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