writing on PORTB

i have problem with writing on port. im writing a program that at the end of it the code will find an angle named teta (it is integer type). i want to know how can i write the this integer ( i mean teta ) on PORTB???

im writing a program

But not showing it to us.

i want to know how can i write the this integer ( i mean teta ) on PORTB???

Suppose that the value in the integer variable is 27. What, exactly, does "write this on PORTB" mean? PORTB is a collection of pins. Which pin(s) should the data go to? What is connected to the pin(s)?

i know portb is a collection of pins. actually i want to connect pins 8-13 (PORTB on arduino uno) to a dac (R2R ladder). because of this purpose i need to write teta value bit by bit on each pin (8-13) simultaneously for example teta is 4. in binary mode it is 000100 so i want pin 10 be high and all other pins be low.but i need all these to be done at same time thats why i want to write on whole port not single pins

PORTB = 0x04;  // or = teta;

this doesn't work PORTB =teta

Have you made all pins of port b an output?

PORTB = 0x04;  // or = teta;

this doesn't work PORTB = teta

Yes, you told that already...

As septillion wrote in #5, you have to set them as output first.

Also this should work:

/* all pins on the Port B set to output-low */
PORTB = 0x00;
DDRB = 0xFF;
PORTB=teta; // set port pins to required value

...or show your code.

Can also use pinMode to set them all as OUTPUTs in setup(), then the DDRB will be set correctly for sure.

PB6 & 7 are the crystal pins on 328, does it hurt to write PORTB = 0xC0? :confused:

No, if pins are used for crystal they cannot be used as I/O. The are disconnected, only crystal oscillator works. So, no worries. If you need whole Port B on 328P, internal oscillator can be used to free those pins.