newbie question

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi guys

i started yesterday with embedded programming and i ran into some isues about the board, STK500. lucky i solved that :).

but now is it time to start programming, i have read some tutorials, but it doesn't really make sense to me. i used these 2 codes to make the led burn.

 DDRB.1 = 0xFF;
  PORTB.1= 0;

but now i want to connect a button to it. how can i do this. i looked at some pages on the internet, but i didn't really make sense. can somebody give me the codes, with some comment. thanks

Robbin

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

What compiler are you using?

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

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

CodeVisionAVR

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

Try 'reading' a couple of other codevision programs that do something simple. Try using the codevision wizard to generate some functions you can study. Try reading a few 'intro to c programming' examples in some c books. (sticky messages at top of forum). if you want to read the pins on port b into a variable called inputs, use inputs=PINB; There is also a way to look at one input: if(PINB & 1) turnonled(); else turnoffled();

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  while (1){ 
    inputs=PIND;
    if (inputs = 1){
      DDRB.1 = 255;       
      PORTB.1 = 0;        
    }
    else{
    DDRB.1 = 255;        
    PORTB.1 = 1;          
    }
  }

oke, i tried this, but it ain't working, i'm still doing something wrong.

the switches are connected to PORTD and the leds to PORTB.

Robbin

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

What about writing

if (inputs == 1){

as the conditional? This is a quite common error. Anyway, it looks like you have other problems than code. Did AVRStudio program the right part succesfully? How is it wired? Could you post more info?

Guillem.

Guillem.
"Common sense is the least common of the senses" Anonymous.

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

i use Codevision at the moment. what do you mean with wired ? (like --> the switches are connected to PORTD and the leds to PORTB)

is this correct:

    DDRB = 0xFF;    /* We put port B pins in output mode */ 
  PORTB = 0xFF;   /* put all leds in off state */ 

  DDRD = 0x00;    /* We put port D pins in input mode */ 
  PORTD = 0xFF;   /* we activate the internal pull-up*/

Robbin

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

But my example reads the port, then takes a look at ONLY THE ONE BIT by ANDing away the other 7 bits. If you just read the whole port, its probably all 1s, or 0xff dont you think?

Imagecraft compiler user

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

i named the port a bit preciesor, and it works now. it took me almost a day, figuring out how the make the leds and the buttons work :s. i feel ashamed :(.

Robbin

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

Don't feel ashamed. I'm a newbie at AVR, but I did a fair amount with other microcontrollers in college, and did a lot of things that made me slap my forehead in disgust!

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

Welcom to the real world. This kind of problems made you happy when solved. Remember that at the beggining, everything is not as easy as it would seem at first glance.

I hope you would enjoy this fantastic world. Good luck.

Guillem.

Guillem.
"Common sense is the least common of the senses" Anonymous.