469,306 Members | 1,903 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before '{' token

Hi
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
  1. #include <avr\io.h>
  2.  
  3. #include <stdio.h>
  4.  
  5. #include <avr\delay.h>
  6.  
  7. #include <math.h>
  8.  
  9. void initialize(void);
  10.  
  11. char val;
  12.  
  13.  
  14.  
  15. // current measurement state
  16.  
  17. enum {PULSE, GSR, BREATH} measure, nextmeasure;
  18.  
  19.  
  20.  
  21. // current signal voltages
  22.  
  23. char pulseV = 0;
  24.  
  25. char gsrV = 0;
  26.  
  27. char breathV = 0;
  28.  
  29.  
  30.  
  31. // enter every 100Hz
  32.  
  33. interrupt(TIM0_COM) void getAD(void)
  34.  
  35. {
  36.  
  37.     // sample A/D and store
  38.  
  39.     val = ADCH;
  40.  
  41.     // start a/d converter
  42.  
  43.     switch(measure)
  44.  
  45.     {
  46.  
  47.         case PULSE:
  48.  
  49.             pulseV = val << 1;
  50.  
  51.             nextmeasure = GSR;
  52.  
  53.             break;
  54.  
  55.         case GSR:
  56.  
  57.             gsrV = val;
  58.  
  59.             nextmeasure = BREATH;
  60.  
  61.             break;
  62.  
  63.         case BREATH:
  64.  
  65.             breathV = val;
  66.  
  67.             nextmeasure = PULSE;
  68.  
  69.             break;
  70.  
  71.     }
  72.  
  73.  
  74.  
  75.     switch(nextmeasure)
  76.  
  77.     {
  78.  
  79.         case PULSE:  ADMUX = 0b01100001; break;
  80.  
  81.         case GSR:    ADMUX = 0b01100010; break;
  82.  
  83.         case BREATH: ADMUX = 0b01100011; break;
  84.  
  85.     }
  86.  
  87.     measure = nextmeasure;
  88.  
  89.  
  90.  
  91.     ADCSR.6 = 1;
  92.  
  93. }
  94.  
  95.  
  96.  
  97. // send signals to MATLAB for drawing
  98.  
  99. void transmit()
  100.  
  101. {
  102.  
  103.     printf("%d ", (int)pulseV);
  104.  
  105.     printf("%d ", (int)gsrV);
  106.  
  107.     printf("%d ", (int)breathV);
  108.  
  109.     printf("\r");    // end packet
  110.  
  111.     PORTD.7 = ~PORTD.7;
  112.  
  113. }
  114.  
  115.  
  116.  
  117. // read A/D converter and communicate with MATLAB
  118.  
  119. void main(void)
  120.  
  121. {
  122.  
  123.     char inchar;
  124.  
  125.  
  126.  
  127.     initialize();
  128.  
  129.  
  130.  
  131.     while(1)
  132.  
  133.     {
  134.  
  135.         // when signaled by MATLAB, return current values
  136.  
  137.         if (UCSRA.7)
  138.  
  139.         {
  140.  
  141.             inchar = UDR;
  142.  
  143.             if (inchar=='s') {
  144.  
  145.                 transmit();
  146.  
  147.             }
  148.  
  149.         }
  150.  
  151.     }
  152.  
  153. }
  154.  
  155.  
  156.  
  157. // setup
  158.  
  159. void initialize(void)
  160.  
  161. {
  162.  
  163.     // comm indicator LED
  164.  
  165.     DDRD.7 = 1;
  166.  
  167.     PORTD.7 = 0;
  168.  
  169.  
  170.  
  171.     // serial RS-232  setup for debugging using printf, etc.
  172.  
  173.     UCSRB = 0x18;
  174.  
  175.     UBRRL = 103;
  176.  
  177.  
  178.  
  179.     // set up timer0 to sample a/d at about 100Hz
  180.  
  181.     TCCR0 = 0b00000101;
  182.  
  183.     TIMSK = 0b00000010;
  184.  
  185.     OCR0 = 156;
  186.  
  187.  
  188.  
  189.     // set up a/d for external Vref, channel 0
  190.  
  191.     // channel zero / left adj / AVcc Reference
  192.  
  193.     // A1=PULSE, A2=GSR, A3=BREATH
  194.  
  195.     ADMUX = 0b01100001;
  196.  
  197.  
  198.  
  199.     // enable ADC and set prescaler to 1/128*16MHz=125kHz
  200.  
  201.     // and clear interupt enable
  202.  
  203.     // and start a conversion
  204.  
  205.     ADCSR = 0b11000111;
  206.  
  207.  
  208.  
  209.     measure = PULSE;
  210.  
  211.     _sei();
  212.  
  213. }
Oct 18 '09 #1
10 29692
Banfa
9,064 Expert Mod 8TB
I can't see anything particularly wrong with this code, allowing for AVR micro-controller extensions, are these the only errors you are getting?

If not please post all your errors.
Oct 18 '09 #2
I am getting the following errors:

c:/winavr-20090313/lib/gcc/../../avr/include/avr\delay.h:36:2: warning: #warning "This file has been moved to <util/delay.h>."
try.c:33: warning: return type defaults to 'int'
try.c:33: warning: function declaration isn't a prototype
try.c: In function 'interrupt':
try.c:35: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
try.c:99: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
try.c:121: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
try.c:159: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
try.c:213: warning: type of 'TIM0_COM' defaults to 'int'
try.c:213: error: expected '{' at end of input
Oct 18 '09 #3
Banfa
9,064 Expert Mod 8TB
SOunds like a problem with

interrupt(TIM0_COM) void getAD(void)

I would start my removing interrupt(TIM0_COM) from this line and seeing it you can get it to compile. This wont produce a runable program but will make sure you have your C syntax correct.

The interrupt(TIM0_COM) is clearly an extension presumably to generate interrupt routines for the AVR micro-controler. That means it is an extension and not standard C. You will have to careful check your compiler documentation and make sure you are using the extension correctly including
  • Setting any compiler switches required by the extension.
  • Including any headers required by the extension.

Above all make sure you read your compiler documentation on how to define interrupt handlers.
Oct 18 '09 #4
Thanks.I have not included the file "avr\interrupt.h". But after adding this file I am getting the following errors :

try.c:91: error: expected ';' before numeric constant
try.c:111: error: expected ';' before numeric constant
try.c:137: error: expected ';' before numeric constant
try.c:165: error: expected ';' before numeric constant
try.c:167: error: expected ';' before numeric constant

Can't I access just one bit of any register?
Oct 19 '09 #5
newb16
687 512MB
You can, but the source code you got is for some other compiler for avr - iar, icc or whatever. avr-gcc doesn't support "regname.N" bit addressing, use instead
regname |= 1<<N to set bit N.
Oct 19 '09 #6
Banfa
9,064 Expert Mod 8TB
Well no, or may be yes, but not like that. There is no way that this syntax

ADCSR.6 = 1;

could be valid standard C and it is an unlikely extension.

The way to access a bit in the register (assuming 8 bit registers) is this
Expand|Select|Wrap|Line Numbers
  1.     /* To read */
  2.     unsigned char reg = ADCSR;
  3.     unsigned char bit;
  4.  
  5.     bit = (reg >> N) & 1;
  6.  
  7.     /* To Write */
  8.     ADCSR |= (1 << N);
  9.  
Where in both cases N is the bit number to access in the range 0 - 7.

Accessing bits in registers must be done carefully. It is easy to accidentally destroy data. For instance (and I take this from a real life error) imagine an 8 bit register that has 4 data bits and a data ready bit that indicates the data bits are valid. When you read the register the data ready bit is cleared and the hardware starts acquiring another value (as in an ADC).

I saw (and corrected an implementation) that did this

Expand|Select|Wrap|Line Numbers
  1.     int data;
  2.     if (REGISTER & DATA_READY_BIT) /* Test data ready bit */
  3.     {
  4.         data = REGISTER & DATA_BITS_MASK;
  5.     }
  6.  
The problem is that the register is actually read twice. The first time to test the data ready bit, the second time to read the data if it is set. That sounds fine but remember my description above. When you read the register the data ready bit is cleared and the hardware starts acquiring another value invalidating the data bits. This method effectively invalidates the data bits testing the data ready bit, you can never read a proper value form the register.

It needs to be written like this

Expand|Select|Wrap|Line Numbers
  1.     int data;
  2.     unsigned char reg;
  3.  
  4.     reg = REGISTER;
  5.  
  6.     if (reg & DATA_READY_BIT) /* Test data ready bit */
  7.     {
  8.         data = reg & DATA_BITS_MASK;
  9.     }
  10.  
This only reads the register once, then if the data ready bit is set it uses the value read at the same time as the data ready bit.


The point is that when you access (for read or write) hardware registers directly you have to be aware of any side effects that access may have on that or other registers.

You will need to know and understand the bitwise and shift operators.
Oct 19 '09 #7
Thanks a lot for your help. Can you also tell me how to go about correcting it :
PORTD.7 = ~PORTD.7; ?
Oct 19 '09 #8
Banfa
9,064 Expert Mod 8TB
You are trying to toggle bit 7, yes?

You need to use xor ^ operator.

Either read the register into a variable perform the xor and write out the new value or xor directly with the register ^=.

In the rhs operand set the bits you want to toggle to 1and bits you want to leave along to 0.

PORTD ^= 0x80;
Oct 19 '09 #9
Yes , I was trying to toggle that particular bit.
Thanks a lot for your help.
Oct 30 '09 #10
I have had this error and found that there was a ";" missing at the end of one of the statements in one of my .h files.
Nov 17 '10 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by jakkem | last post: by
5 posts views Thread by ritesh | last post: by
3 posts views Thread by creativeinspiration | last post: by
1 post views Thread by m.selvakannan | last post: by
2 posts views Thread by entellus | last post: by
4 posts views Thread by ...vagrahb | last post: by
2 posts views Thread by akhilesh.noida | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.