I am using WINAVR compiler for ATMEGA32. While compiling c progam , I am getting the error
error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before '{' token
before evrey function.
code:
Expand|Select|Wrap|Line Numbers
- #include <avr\io.h>
- #include <stdio.h>
- #include <avr\delay.h>
- #include <math.h>
- void initialize(void);
- char val;
- // current measurement state
- enum {PULSE, GSR, BREATH} measure, nextmeasure;
- // current signal voltages
- char pulseV = 0;
- char gsrV = 0;
- char breathV = 0;
- // enter every 100Hz
- interrupt(TIM0_COM) void getAD(void)
- {
- // sample A/D and store
- val = ADCH;
- // start a/d converter
- switch(measure)
- {
- case PULSE:
- pulseV = val << 1;
- nextmeasure = GSR;
- break;
- case GSR:
- gsrV = val;
- nextmeasure = BREATH;
- break;
- case BREATH:
- breathV = val;
- nextmeasure = PULSE;
- break;
- }
- switch(nextmeasure)
- {
- case PULSE: ADMUX = 0b01100001; break;
- case GSR: ADMUX = 0b01100010; break;
- case BREATH: ADMUX = 0b01100011; break;
- }
- measure = nextmeasure;
- ADCSR.6 = 1;
- }
- // send signals to MATLAB for drawing
- void transmit()
- {
- printf("%d ", (int)pulseV);
- printf("%d ", (int)gsrV);
- printf("%d ", (int)breathV);
- printf("\r"); // end packet
- PORTD.7 = ~PORTD.7;
- }
- // read A/D converter and communicate with MATLAB
- void main(void)
- {
- char inchar;
- initialize();
- while(1)
- {
- // when signaled by MATLAB, return current values
- if (UCSRA.7)
- {
- inchar = UDR;
- if (inchar=='s') {
- transmit();
- }
- }
- }
- }
- // setup
- void initialize(void)
- {
- // comm indicator LED
- DDRD.7 = 1;
- PORTD.7 = 0;
- // serial RS-232 setup for debugging using printf, etc.
- UCSRB = 0x18;
- UBRRL = 103;
- // set up timer0 to sample a/d at about 100Hz
- TCCR0 = 0b00000101;
- TIMSK = 0b00000010;
- OCR0 = 156;
- // set up a/d for external Vref, channel 0
- // channel zero / left adj / AVcc Reference
- // A1=PULSE, A2=GSR, A3=BREATH
- ADMUX = 0b01100001;
- // enable ADC and set prescaler to 1/128*16MHz=125kHz
- // and clear interupt enable
- // and start a conversion
- ADCSR = 0b11000111;
- measure = PULSE;
- _sei();
- }