cv avr errors - can't figure out: Please Help

Go To Last Post
19 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#include <mega8.h>
#include <delay.h>
#define pinWrite(i,j,port)port=(i)?port|(1<<j):port&(~(1<<j))
#define pinPulse(j,port)port|=(1<<j)\
                        port&=(~(1<<j))
      
#define sport  PORTB
#define sclock PORTB1    
#define slatch PORTB2
#define sdata PORTB0

uint8_t j,i=0,a[]={255,	255,	193,	221,	221,	255,	255,	255};
void dshift(uint8_t data)
{
   for(uint8_t i=0;i<8;i++)
   {
      
      if(data & 0b10000000)
      {
         pinWrite(1,sdata,sport);
      }
      else
      {
         
         pinWrite(0,sdata,sport);
      }

      pinPulse(sclock,sport);
      data=data<<1;  //Now bring next bit at MSB position

   }

   
   pinPulse(slatch,sport);
}
 
void main(void)
{
    

// Input/Output Ports initialization
// Port B initialization
// Function: Bit7=Out Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out 
DDRB=(1<<DDB7) | (1<<DDB6) | (1<<DDB5) | (1<<DDB4) | (1<<DDB3) | (1<<DDB2) | (1<<DDB1) | (1<<DDB0);
// State: Bit7=0 Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0 
PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0);

// Port C initialization
// Function: Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out 
DDRC=(1<<DDC6) | (1<<DDC5) | (1<<DDC4) | (1<<DDC3) | (1<<DDC2) | (1<<DDC1) | (1<<DDC0);
// State: Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0 
PORTC=(0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0);

// Port D initialization
// Function: Bit7=Out Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out 
DDRD=(1<<DDD7) | (1<<DDD6) | (1<<DDD5) | (1<<DDD4) | (1<<DDD3) | (1<<DDD2) | (1<<DDD1) | (1<<DDD0);
// State: Bit7=0 Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0 
PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) | (0<<PORTD1) | (0<<PORTD0);


while (1)
      {
         for(i=0;i<8;i++)
         {
            j=a[i];
            dshift(j);
            pinPulse(PORTB4,PORTB);
         }
            

      }
}

The above code gives the error

Error: C:\Users\deepa\Desktop\matrix\ledm.c(12): '(' expected

 

When I convert the first uint8_t to int, it gives even more errors:

 

Error: C:\Users\deepa\Desktop\matrix\ledm.c(13): declaration syntax error
Error: C:\Users\deepa\Desktop\matrix\ledm.c(15): ')' expected, but ';' found
Error: C:\Users\deepa\Desktop\matrix\ledm.c(15): ';' expected, but ')' found
Error: C:\Users\deepa\Desktop\matrix\ledm.c(28): ';' expected
Error: C:\Users\deepa\Desktop\matrix\ledm.c(29): operand types 'int (*)()' and 'int' are incompatible with the '<<' or '<<=' operator
Error: C:\Users\deepa\Desktop\matrix\ledm.c(34): ';' expected
Error: C:\Users\deepa\Desktop\matrix\ledm.c(137): too many arguments in function call
Error: C:\Users\deepa\Desktop\matrix\ledm.c(138): ';' expected

 

I am just a beginner, so sorry for any mistakes i might have made.

This topic has a solution.
Last Edited: Sat. Feb 9, 2019 - 06:11 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why on earth are you making life so complicated when you have Codevision?

#define sport  PORTB
#define sclock PORTB1    
#define slatch PORTB2

can just be:

#define sclock PORTB.1    
#define slatch PORTB.2

then later in the code you do things like:

sclock = 1;
slatch = 0;

to write those individual port bits. No need for all this nonsense:

#define pinWrite(i,j,port)port=(i)?port|(1<<j):port&(~(1<<j))
#define pinPulse(j,port)port|=(1<<j)\
                        port&=(~(1<<j))

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The error you need to take care of first is the first listed errror:

 

Error: C:\Users\deepa\Desktop\matrix\ledm.c(12): '(' expected

 

I cannot tell which line is line 12 so I can't help you more.

 

#define pinPulse(j,port)port|=(1<<j)\
                        port&=(~(1<<j))

I cannot tell what you are trying to do. This is a place where comments would be REALLY useful.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Fri. Feb 8, 2019 - 09:08 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You make life very complicated.   Surely this is clearer:

void dshift(uint8_t data)
{
	uint8_t i;      //.kbv CV does not allow declaration inside for()
	for(i = 0; i < 8; i++) {
		if(data & 0b10000000) PORTB.0 = 1;
		else PORTB.0 = 0;
		PORTB.1 = 1;
		PORTB.1 = 0;
		data = data << 1; //Now bring next bit at MSB position
	}
	PORTB.2 = 1;
	PORTB.2 = 0;
}

But it would be even clearer if you defined the pins e.g.

#define DATAPIN PORTB.0

There are several problems with your approach.   Please look at the comments marked .kbv

#include <mega8.h>
#include <delay.h>
#include <stdint.h>  //.kbv for uint8_t
#define pinWrite(i,j,port) port=(i)?port|(1<<j):port&(~(1<<j))
#define pinPulse(j,port)   { port|=(1<<j); port&=(~(1<<j)); } //.kbv correct macro

#define sport  PORTB
#define sclock PORTB1
#define slatch PORTB2
#define sdata PORTB0

uint8_t j, i = 0, a[] = {255,    255,    193,    221,    221,    255,    255,    255};
void dshift(uint8_t data)
{
	uint8_t i;      //.kbv CV does not allow declaration inside for()
	for(i = 0; i < 8; i++) {
		if(data & 0b10000000) {
			pinWrite(1, sdata, sport);
		} else {
			pinWrite(0, sdata, sport);
		}
		pinPulse(sclock, sport);
		data = data << 1; //Now bring next bit at MSB position
	}
	pinPulse(slatch, sport);
}

void main(void)
{
	// Input/Output Ports initialization
	// Port B initialization
	// Function: Bit7=Out Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out
	DDRB = (1 << DDB7) | (1 << DDB6) | (1 << DDB5) | (1 << DDB4) | (1 << DDB3) | (1 << DDB2) | (1 << DDB1) | (1 << DDB0);
	// State: Bit7=0 Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0
	PORTB = (0 << PORTB7) | (0 << PORTB6) | (0 << PORTB5) | (0 << PORTB4) | (0 << PORTB3) | (0 << PORTB2) | (0 << PORTB1) | (0 << PORTB0);
	// Port C initialization
	// Function: Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out
	DDRC = (1 << DDC6) | (1 << DDC5) | (1 << DDC4) | (1 << DDC3) | (1 << DDC2) | (1 << DDC1) | (1 << DDC0);
	// State: Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0
	PORTC = (0 << PORTC6) | (0 << PORTC5) | (0 << PORTC4) | (0 << PORTC3) | (0 << PORTC2) | (0 << PORTC1) | (0 << PORTC0);
	// Port D initialization
	// Function: Bit7=Out Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out
	DDRD = (1 << DDD7) | (1 << DDD6) | (1 << DDD5) | (1 << DDD4) | (1 << DDD3) | (1 << DDD2) | (1 << DDD1) | (1 << DDD0);
	// State: Bit7=0 Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0
	PORTD = (0 << PORTD7) | (0 << PORTD6) | (0 << PORTD5) | (0 << PORTD4) | (0 << PORTD3) | (0 << PORTD2) | (0 << PORTD1) | (0 << PORTD0);
	while (1) {
		for(i = 0; i < 8; i++) {
			j = a[i];
			dshift(j);
			pinPulse(PORTB4, PORTB);
		}
	}
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The error is resolved. But someone said that since I'm using CodeVision, I can directly use PORTB.3=1; 

Could anyone point me to some kind of documentation or website for codevision?

I have been studying directly from avr tutorials.

Last Edited: Fri. Feb 8, 2019 - 09:42 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Okay, turns out you were right on all counts. I also had 1 question.

Why did I have to use <stdint.h> to use uint8_t?

Isn't it just another name for char?(Source:Google)

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No,  uint8_t etc are not part of the C language.    They need to be declared from < stdint.h >

 

GCC is naughty.   It silently includes several headers via < avr/io.h > e.g. < stdint.h >

 

I suggest that you get into the habit of specifying which headers to include.

It does no harm.    You will find that your code works seamlessly with other toolchains.

 

David.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
GCC is naughty.   It silently includes several headers via < avr/io.h > e.g. < stdint.h >
I'm not entirely sure how it is "naughty" ?? The fact is that almost everything in the device definition headers is done in terms of uint8_t, uint16_t objects so for those headers to work they have to know what "uint8_t" is. So isn't it simply an inevitable consequence of the way the device headers are defined that it has to start by including the <stdint.h> types it uses?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

C is a very simple language with very few keywords.

Everything is built with header files and libraries.

 

Without includes you have nothing more than char, int, long, ...

 

If you want access to special function registers you have to include the relevant header e.g. < avr/io.h >

Yes,   < stdint.h > is a wise include in almost every source file.    It removes ambiguity from the "implementation defined" int etc.

 

There is nothing wrong with putting all your "usual" includes into a special "david.h" or "cliff.h"

In fact I quite like the idea that "Arduino.h" or "mbed.h" tend to know EVERYTHING.

 

But this is not part of the C language.    The user should determine which headers that she wants to include.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

zackdgod wrote:

Could anyone point me to some kind of documentation or website for codevision?

 

The manual for Codevision, all 900 pages of it, is installed when you installed the compiler. It's in the 'documentation' folder.

 

Everything else is just plain 'C' about which there are 100s of websites. Some good, some bad.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just out of interest how would you pass something like PORTB.3 into a function? 

 

Say you wanted to be able to:

pulse(PORTB.3);
pulse(PORTD.7);

How could you pass that? Presumably by reference but as what type? Is it something like:

void pulse(sbit * x) {
    *x = 1;
    *x = 0;
}

void main(void) {
    pulse(&PORTB.3);
}

Or what exactly? Or is it even do-able?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
can just be: #define sclock PORTB.1
Oh, how you have fallen!  Do I recall incorrectly that you led a platoon of "Non-standard!" flag-wavers earlier in the century? ;)

https://www.avrfreaks.net/commen...

clawson wrote:
While CV's bit access method on low ports is a nice (non standard) feature it's downside seems to be that it prevents folks learning the "standard" way to set and clear bits with good old ORs and AND/NOTs

and https://www.avrfreaks.net/commen...

clawson wrote:
It does not - but it draws beginners into a mindset of believing that setting/clearing bits is as simple as setting XXXX.n to 0 or 1. They come to rely on it and are then sadly let down when it is not applicable to out of range registers.

Maybe "fallen" is not the right word.  You had an "epiphany", perhaps?

 

Anyway, early responders here seem to have concentrated in OP's style and approach.  I don't disagree, but first tell why there is a syntax error.

 

Re uint8_t and friends -- I have to do some digging but I seem to recall that it might depend on what level (e.g. C99) the toolchain generally follows.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Fri. Feb 8, 2019 - 02:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't think that I have ever wanted to pass a "sbit" to a function.    I don't think that I have even tried with Keil 8051

 

It is a lot easier to use straightforward statements or macros.

 

Of course you can do anything in CV that is possible with GCC.    It just requires the appropriate address dereferencing.

The CV SFR.# extension makes the code look intuitive.    GCC can generate the same ASM sequences but requires convoluted construction to satisfy C syntax.

 

David.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

zackdgod wrote:
Could anyone point me to some kind of documentation or website for codevision?

That is indeed an "interesting" question.  Doesn't your menu bar have a "Help" section?  What does that say?

 

Note the "Help Topics" and "HP InfoTech on the Web" -- doesn't that address the situation?

 

How did you get your copy of CV?  What version?

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lee,

 

Having a bad hair day? Or is it a long time chip on the shoulder? cheeky

 

I've always thought that compilers that offer the .n access provide a nice feature for micro work. The only argument against as I've stated before is that it is non-standard so it can miseducate folks, esp. beginners if they don't realise that it is "something special" and they can't rely on it if they see other architectures/compilers in their future.

 

But if your plan is to work solely with a particular architecture and a particular compiler then I'd always use it if possible as it makes life a lot easier.

 

At one stage you may remember I actually wrote a whole header file generating system for AVRs purely to deliver the kind of Adc.Aden = 1 sort of syntax which is as close as you can get if limited to "standard C" but "normal" C limits this to PortB.b1 = 0 rather than the preferable PortB.1 = 0 which isn't quite achievable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So I took everyone's advice and used the function TSTBIT to get input for the given circuit

#include <mega8.h>
#include <delay.h>
#include <stdint.h>
#include <iobits.h>  

#define sclock PORTB.1    
#define slatch PORTB.2
#define sdata PORTB.0

uint8_t f,m=0, j,i=0,d[]={255,	255,	255,	255,	254,	255,	255,	255},s[]={255,255,255,255,255,255,255,255};
void lmov()
{  
    if(!(~d[0]))
        {
            for(f=0;f<7;f++)
                d[f]=d[f+1];
            d[7]=255;
        } 
        
}
void rmov()
{
    if(!(~d[7]))
        {
            for(f=7;f>0;f--)
                d[f]=d[f-1];
            d[0]=255;  
        }
}
void dshift(uint8_t data)
{  uint8_t i=0;
   for(i=0;i<8;i++)
   {
      
      if(data & 0b10000000)
      {
         sdata=1;
      }
      else
      {
         
         sdata=0;
      }

      sclock=1;sclock=0;
      data=data<<1;  //Now bring next bit at MSB position

   }
   
   
   slatch=1;slatch=0;
   delay_us(5);
}
 
void main(void)
{
    

// Input/Output Ports initialization
// Port B initialization
// Function: Bit7=Out Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out 
DDRB=(1<<DDB7) | (1<<DDB6) | (1<<DDB5) | (0<<DDB4) | (1<<DDB3) | (1<<DDB2) | (1<<DDB1) | (1<<DDB0);
// State: Bit7=0 Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0 
PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0);

// Port C initialization
// Function: Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out 
DDRC=(1<<DDC6) | (1<<DDC5) | (1<<DDC4) | (1<<DDC3) | (1<<DDC2) | (1<<DDC1) | (1<<DDC0);
// State: Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0 
PORTC=(0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0);

// Port D initialization
// Function: Bit7=Out Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out 
DDRD=(1<<DDD7) | (1<<DDD6) | (1<<DDD5) | (1<<DDD4) | (1<<DDD3) | (1<<DDD2) | (1<<DDD1) | (1<<DDD0);
// State: Bit7=0 Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0 
PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) | (0<<PORTD1) | (0<<PORTD0);


while (1)
      {  
         dshift(d[0]);
         for(i=0;i<8;i++)
         { 
            delay_us(20); 
            dshift(d[(i+1)%8]);
            PORTB.3=1; 
            PORTB.3=0;
            
         } 
         if(TSTBIT(PORTB,4)==1 && m==0)            // To make sure that every switching on is taken as one switching instead of multiple such events
         {
            m++;
            lmov(); 
            PORTC=255;
         }
         if(TSTBIT(PORTB,4)==0)m=0;   
            

      }
}

I'm trying to move the dot left by one at every "ON" setting. But the dot is not moving.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I do not know what TSTBIT() does.   I suspect that you want to use PINB.4

 

I strongly advise you to format your code.   One click from the Codevision IDE.

Life is much better when your code looks neat and tidy.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And right again you are.

 

The help section never showed me anything along the lines of PINB.

 

BTW, why does PORTB.4 not work in the same manner as the PINB.4 command?

Something to do with input/output?

 

Also, what kind of formatting are we talking about here? I'm pretty sure I have my code indented out properly.

Last Edited: Fri. Feb 8, 2019 - 07:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Continue here please https://www.avrfreaks.net/forum/...

 

Never mind, unlocked now by popular demand.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Sat. Feb 9, 2019 - 06:12 AM