Hi
I am using WINAVR compiler for ATMEGA32. While compiling c progam , I am getting the error
error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribu te__’ before '{' token
before evrey function.
code: -
#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();
-
-
}
10 31964 Banfa 9,065
Recognized Expert Moderator Expert
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.
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
Banfa 9,065
Recognized Expert Moderator Expert
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.
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?
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.
Banfa 9,065
Recognized Expert Moderator Expert
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 -
/* To read */
-
unsigned char reg = ADCSR;
-
unsigned char bit;
-
-
bit = (reg >> N) & 1;
-
-
/* To Write */
-
ADCSR |= (1 << N);
-
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 -
int data;
-
if (REGISTER & DATA_READY_BIT) /* Test data ready bit */
-
{
-
data = REGISTER & DATA_BITS_MASK;
-
}
-
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 -
int data;
-
unsigned char reg;
-
-
reg = REGISTER;
-
-
if (reg & DATA_READY_BIT) /* Test data ready bit */
-
{
-
data = reg & DATA_BITS_MASK;
-
}
-
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.
Thanks a lot for your help. Can you also tell me how to go about correcting it :
PORTD.7 = ~PORTD.7; ?
Banfa 9,065
Recognized Expert Moderator Expert
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;
Yes , I was trying to toggle that particular bit.
Thanks a lot for your help.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: jakkem |
last post by:
For example the following gives me error
"expected `(' before '{' token"
"expected asm body before '{' token "
etc.
int main()
{
asm { /* some asm-functions */ }
}
|
by: ritesh |
last post by:
Hi,
I'm compiling the following code on linux/cc and keep getting a
compiler error
"attrib.c:4: syntax error before '{' token"
I'm using the following options to compile -
cc -Wall -c attrib.c
#include "stdio.h"
|
by: creativeinspiration |
last post by:
Hey guys. I am trying to implement a system call in linux kernel. I usually use ubutntu, but this I am doing on Fedora. I am using kernel 2.6. Here is what I did:
1. Added a line to arch/i386/kernel/syscall_table.S:
.long sys_foo
2. Added a line to linux/include/asm-i386/unistd.h:
#define __NR_foo 324
|
by: m.selvakannan |
last post by:
hi
iam working with uclinux
i got errors while compilation..
/opt/uClinux/bfin-uclinux/bfin-uclinux/runtime/usr/include/asm/
system.h: In function 'long unsigned int __cmpxchg(volatile void*,
long unsigned int, long unsigned int)':
/opt/uClinux/bfin-uclinux/bfin-uclinux/runtime/usr/include/asm/
system.h:204: error: expected...
|
by: entellus |
last post by:
I'm using gcc to compile the code listed below when I get the following error
error: expected '=', ',', ';', 'asm' or '__attribute__' before ' is_prime_number
/*
* What is the largest prime factor of the number 317584931803?
*/
#include <stdio.h>
| |
by: kya2 |
last post by:
I am not able to create following store procedure.
CREATE PROCEDURE DBSAMBA.InsertDeleteBatch(OUT norows INT )
RESULT SETS 1
LANGUAGE SQL
BEGIN part1
DECLARE TOTAL_LEFT INT DEFAULT 0;
SELECT COUNT(*)INTO TOTAL_LEFT FROM DBSAMBA.REPORTEDTRANSACTION_S;
WHILE (TOTAL_LEFT > 0)
DO
|
by: ...vagrahb |
last post by:
Hi,
I have the following structure
struct Format
{
char x;
unsigned char a;
unsigned char b;
unsigned char c;
char y;
|
by: singhPrabhat |
last post by:
Hi,
I am using gcc (GCC) 4.2.1 (SUSE Linux).
SUSE 10.3
While compiling a .c file I get following error ::::
CCWebConfiguration.h:70: error: expected =, ,, ;, asm or __attribute__ before extern
CCWebBrowser.c: In function main:
|
by: akhilesh.noida |
last post by:
I am trying to compile glibc-2.5 for ARM based board. But I am getting
errors while configuring it. Please check and give your inputs for
resolving this.
configure command :
$ ../glibc-2.5/configure --prefix=/mnt/new/Mars/glibc_HQ_test/GLIBC/
install/ --with-__thread
--enable-kernel=2.6.11 --enable-shared
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |