NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Help with code

April 01, 2011
by jkoppp
jkoppp's Avatar

For some reason my code wont compile... can someone tell me what is wrong with it.

//Lasertest1.c //JKOPPP

define F_CPU 14745600

include <stdio.h>

include <avr/io.h>

include <avr/interrupt.h>

include <avr/pgmspace.h>

include <inttypes.h>

include <../libnerdkits/delay.h>

include <../libnerdkits/lcd.h>

// MCU PIN 23=SWITCH

void main() {

DDRC |= (1<<PC1);     //SET PC1 AS OUTPUT

DDRC &= ~(1<<PC0);   // SET PC0 AS IMPUT

PORTC |= (1<<PC0);  //  TURN ON INTERNAL PULL UP RESISTOR

uint8_t S1;        //  DEFINE VARIABLE TO STORE SWITCH READ

while 1{
      if (PORTC & = (1<<PC0))
      S1=1;
      else()
      S1=0;
      if (S1=0)
      (PORTC |= (1<<PC1);
      delay_ms(500);
      else()
      delay_ms(500);

}

      return 0;

}

April 01, 2011
by Ralphxyz
Ralphxyz's Avatar

What is it doing or not doing? Post a screen shot of your command line.

Here is your code using the "Indent Selection as Code Block" button at the bottom of the page it really is so much easier to read:

//Lasertest1.c //JKOPPP

define F_CPU 14745600

include <stdio.h>

include <avr/io.h>

include <avr/interrupt.h>

include <avr/pgmspace.h>

include <inttypes.h>

include <../libnerdkits/delay.h>

include <../libnerdkits/lcd.h>

// MCU PIN 23=SWITCH

void main() {

DDRC |= (1<<PC1);     //SET PC1 AS OUTPUT

DDRC &= ~(1<<PC0);   // SET PC0 AS IMPUT

PORTC |= (1<<PC0);  //  TURN ON INTERNAL PULL UP RESISTOR

uint8_t S1;        //  DEFINE VARIABLE TO STORE SWITCH READ

while 1{
      if (PORTC & = (1<<PC0))
      S1=1;
      else()
      S1=0;
      if (S1=0)
      (PORTC |= (1<<PC1);
      delay_ms(500);
      else()
      delay_ms(500);
}

return 0;
}

Ralph

April 01, 2011
by SpaceGhost
SpaceGhost's Avatar

Well... Your program seems to be lacking some { } 's here and there. Oh, and I think "while 1" has to be "while (1)". I don't know if it's okay your way, I haven't seen it written that way before.

Post a Reply

Please log in to post a reply.

Did you know that electric fields behave differently in different materials? Learn more...