Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

clap switch with PIC16F876A

Status
Not open for further replies.
Hello Sir,considering one project of clap switch on
PHP:
http://embedded-lab.com/blog/?p=6439
;how can we edit those codes for having a lap switch with PIC16F877A?

Thanks.
 

I am compiling using Mikroc PRO for PIC V.4.60.0.0 ,but I am having many errors,do you think that mikroc PRO PIC demo version will be perfect?

I am using PIC16F877A,a quartz of 4MHz.I want to change the output bit to be PORTD.D3 but when changing those codes ,I am getting errors.

Please help.

Thanks
 

Download latest mikroC demo version and Compile. You have to configure ADCON1 register. See datasheet to configure.


Code C - [expand]
1
2
3
sbit Output_LED at GP5_bit  //Replace this
 
#define Output_LED PORTD.F3;  //with this



Remove this line.


Code C - [expand]
1
ANSEL = 0x00;

 

do you think that after those adjustment that program will work with pic16f877a?what does that .F3 means,the codes posted on the link I gave you are using a comparator module and I think the output of comparator module for pic16f877A is on C2?Am I right?

I got Mirkoc Pro for PIC V.6.0.0 hope it will help.

Thanks.


Thanks,please help.
 

Check the Comparator connections. CMCON0 has to be replaced by COMCON. Read datasheet Comparator and ADC sections. You only need to configure CMCON and ADCON1.
 

Hello, I did the change but see the error I am getting image attached here with my project.

And also some of the codes I think they are not fine they have to be changed example where is written:
PHP:
if(CMCON0.COUT && !TIME_UP) Output_LED = ~Output_LED;
I think it has to be changed.

Please help.

Thanks.
 

Attachments

  • code.zip
    16.8 KB · Views: 41
Last edited:

Hello ,see the new codes here below:I tried to edit the ones of the link I posted this morning I compoled they run without error but I am asking my self if they will work because what is called COUT for example on 12F683 is AN5 on PIC16F877A while this C2OUT was supposed to be the output signal.

can you help me to edit very well those codes,but I compiled and they are running without error;
PHP:
/*
 Project: A very basic clap switch
 Description : Clap switch using built-in comparator module
               of PIC12F683
 MCU: PIC12F683
 Oscillator: Internal 4.0000 MHz, MCLR Disabled, PWRT ON enabled
 Written by: Rajendra Bhatt (www.embedded-lab.com)
 Date:       Nov 21, 2012
*/

#define Output_LED  PORTC.F2;
unsigned short i, TIME_UP;

void interrupt(void){
  if(PIR1.TMR1IF) {
    i ++;
    if(i == 3) TIME_UP = 1;  // Time Up in 1.5 sec
    PIR1.TMR1IF = 0;
 }
}

void main() {
  //TRISIO = 0b00000011 ;
  TRISA= 0b00000011 ;
  //ANSEL = 0x00;
  INTCON = 0b11000000 ; // Enable GIE and PEIE for Timer1 overflow interrpt
  PIE1 = 0b00000001 ;   // Enable TMR1IE


  //CMCON0 = 0b00010100;
  CMCON = 0b00010100;
  //VRCON  = 0b10100011;
 CVRCON  = 0b10100011;
  //Output_LED = 0;
  PORTC=0x00;
  do{
     TMR1H = 0x00;
     TMR1L = 0x00;
     TIME_UP = 0;
     i = 0;
     T1CON = 0b00110000;   // Configure Timer 1
     if(CMCON.C2OUT){      // First clap detected
       Delay_ms(100);
       T1CON.TMR1ON = 1;   // Start Timer1
       while(!CMCON.C2OUT && !TIME_UP); // Wait until second clap is
       T1CON.TMR1ON = 0;  // detected or Timer1 overflows
       if(CMCON.C2OUT && !TIME_UP)
       //Output_LED = ~Output_LED;
       PORTC=~PORTC;
       Delay_ms(100);
     }
  }  while(1);
}
The circuit I assumed the one posted here,in my proteus there is no MIC simulation component,please help.

The edited codes are commented above the line which replaced it.

Thanks ;please help
 

Attachments

  • CRTT.zip
    19.8 KB · Views: 36

Hello jayanth.devarayanadurga;
can those codes be heklpfull for my project using T1CKI of PIC16F877A and the AN0 of this mcrocontroller?

I have been unable to get the good answer with the codes in MikroC

Here below are the codes
PHP:
#include <16f877a.h>  
#device adc=10  
#fuses HS,NOWDT,NOLVP,NOCPD,NODEBUG 
#use delay(clock=4M)   

float volt,x, oldval, volt1; 
int count= 0;
int data,time ;
void main() 
{ 
    set_tris_a(0xff); 
    set_tris_b(0x00); 
    set_tris_c(0x01); 
    set_tris_d(0x00); 
        
    //Analog module configuration for reading the voltage from the PIN_AN0 
    setup_comparator(NC_NC_NC_NC); 
    setup_adc(ADC_CLOCK_INTERNAL); 
    setup_adc_ports(AN0); 
    set_adc_channel(0);  
    setup_vref(FALSE);    
   output_low(PIN_D3);
    while(1) 
    { 
//time=delay_ms(2500);
        delay_us(20); 
        read_adc(adc_start_only); 
        delay_us(100); 
        volt = read_adc(adc_read_only); 
       volt = (volt * 5.0)/ 1023.0; 
set_timer1(0); 
setup_timer_1(T1_EXTERNAL| T1_DIV_BY_1);
delay_ms(x);
setup_timer_1(T1_DISABLED);
data=get_timer1();//getting the value of frequency
x=(1/data); //calaculation of period=x (delay generated corresponding to the measured frequency)

if(volt>1)
{
delay_ms(1);
output_high(PIN_D3);
delay_ms(1500);   
}   
 if((x>500)&&(x<3500)&&(volt>1))
{
output_low(PIN_D3);
delay_ms(1500);
}

Thanks.,Please help!!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top