Nojman
Newbie level 6
- Joined
- Jan 11, 2014
- Messages
- 11
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 108
Hi!
I have build a clapper from this site https://embedded-lab.com/blog/?p=6439
He used a PIC12F683 but I hade a PIC16F628 home so I used it.
I wonder if someone could help med with the c code? And correct me if I have put the wires to the right pins.
I have tried to read the datasheets for both the PICs, on the pins and how to change the configuration bits by but I have a hard time to understand it fully.
I have wired the pins like this from the site.
(I have wires to the pins)
And here is the code with my changes.
My error message..
(I'm using MPLAB IDE 8.92, PICkit 3, B Knudsen Data CC5X)
I would be realy thankfull if someone could help me
I have build a clapper from this site https://embedded-lab.com/blog/?p=6439
He used a PIC12F683 but I hade a PIC16F628 home so I used it.
I wonder if someone could help med with the c code? And correct me if I have put the wires to the right pins.
I have tried to read the datasheets for both the PICs, on the pins and how to change the configuration bits by but I have a hard time to understand it fully.
I have wired the pins like this from the site.
Code:
/*
________ ________
| \/ |
T1 and R10K---|RA2 16F628 RA1|
|RA3 RA0|
|RA4-od RA7/OSC1|
|RA5/MCLR RA6/OSC2|
GND ---|Vss Vdd|--- +5V
|RB0/INT (RB7)/PGD|
|RB1/Rx (RB6)/PGC|--- the LED with R330
|RB2/Tx RB5|
|RB3/CCP (RB4)/PGM|
|__________________|
*/
And here is the code with my changes.
Code:
//sbit Output_LED at GP5_bit; on the original code
#define Output_LED PORTD.F3;
//sbit led_led at PORTc.c2;
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 ;
//ANSEL = 0x00; on the original code
INTCON = 0b11000000 ; // Enable GIE and PEIE for Timer1 overflow interrpt
PIE1 = 0b00000001 ; // Enable TMR1IE
// Configure Comparator module
// CIN- pin is configured as analog,
// CIN+ pin is configured as I/O,
// COUT pin is configured as I/O,
// Comparator output available internally,
// CVREF is non-inverting input
// CINV is set to 1
COMCON = 0b00010100;
VRCON = 0b10100011; // Vref is set to VDD/8
Output_LED = 0;
do{ TMR1H = 0x00;
TMR1L = 0x00;
TIME_UP = 0;
i = 0;
T1CON = 0b00110000; // Configure Timer 1
if(CMCON0.COUT){ // First clap detected
Delay_ms(100);
T1CON.TMR1ON = 1; // Start Timer1
while(!COMCON.COUT && !TIME_UP); // Wait until second clap is
T1CON.TMR1ON = 0; // detected or Timer1 overflows
if(COMCON.COUT && !TIME_UP) Output_LED = ~Output_LED;
Delay_ms(100);
}
} while(1);
}
//- See more at: http://embedded-lab.com/blog/?p=6439#sthash.YHvZk7SY.dpuf
My error message..
Code:
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files (x86)\PK2proj\Cc5x\CC5X.EXE" clapper.c -CC -fINHX8M -p16F628 -a -L -Q -V -FM
CC5X Version 3.3A, Copyright (c) B Knudsen Data, Norway 1992-2007
--> FREE edition, 8-16 bit int, 24 bit float, 1k code, reduced optim.
clapper.c:
void first_interrupt( void){
if(PIR1.TMR2IF){
^------
Error[1] C:\Program Files (x86)\PK2proj\Work\clapper.c 31 : Syntax error
(The expression must be corrected. The marker ^------ shows
the approximate position where CC5X gives up. The documentation
should be checked if the cause is not obvious)
Error options: -ew: no warning details -ed: no error details -eL: list details
BUILD FAILED: Wed Jan 15 01:36:50 2014
(I'm using MPLAB IDE 8.92, PICkit 3, B Knudsen Data CC5X)
I would be realy thankfull if someone could help me
Last edited: