Pages: 1 [2]   Go Down
Author Topic: Compile problem using macro  (Read 4333 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 4
Posts: 218
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was just under the naive impression that the DDRB ("B" port or any other register port) was limited to declaring IO direction.
You set two registers at 255=11111111 Passing  PORTB=0 turns them all off =00000000
From Mellis
Quote from: Mellis MIT
   DDRB is the data direction register for port B. It determines whether each pin is an input or an output.
    PORTB is the data register for port B. For output pins, this determines whether the pin is set high or low.

Each of the eight bits of the register corresponds to one of the eight pins of the port. The 0'th (right-most) bit of the register corresponds to PB0. The 7'th (left-most) bit to PB7. If a bit of the DDRB register is set to 1, the corresponding pin is set as an output. If the bit is 0, the pin is an input. The pins default to being inputs (i.e. the bits of DDRB default to 0). If a bit of the PORTB register is set to 1, and the pin is set as an output, the microcontroller will hold the pin high - that is, set it to 5V (or whatever voltage is used to power the microcontroller). If a bit of PORTB is 0, and the pin is an output, the microcontroller will hold the pin low (0V).
« Last Edit: September 30, 2012, 03:53:46 pm by april » Logged

0
Offline Offline
Full Member
***
Karma: 4
Posts: 218
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote from: SurferTim
/arduino-101/hardware/tools/avr/avr/include/avr/
As I remember, the exact file in that directory will depend on the device selected for compile.
Thanks ,I looked at 328p as an example and I found some fuse setting but not macros
Code:
/* Fuses */
#define FUSE_MEMORY_SIZE 3

/* Low Fuse Byte */
#define FUSE_CKSEL0 (unsigned char)~_BV(0)  /* Select Clock Source */
#define FUSE_CKSEL1 (unsigned char)~_BV(1)  /* Select Clock Source */
#define FUSE_CKSEL2 (unsigned char)~_BV(2)  /* Select Clock Source */
#define FUSE_CKSEL3 (unsigned char)~_BV(3)  /* Select Clock Source */
#define FUSE_SUT0   (unsigned char)~_BV(4)  /* Select start-up time */
#define FUSE_SUT1   (unsigned char)~_BV(5)  /* Select start-up time */
#define FUSE_CKOUT  (unsigned char)~_BV(6)  /* Clock output */
#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)

/* High Fuse Byte */
#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)  /* Brown-out Detector trigger level */
#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)  /* Brown-out Detector trigger level */
#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)  /* Brown-out Detector trigger level */
#define FUSE_EESAVE    (unsigned char)~_BV(3)  /* EEPROM memory is preserved through chip erase */
#define FUSE_WDTON     (unsigned char)~_BV(4)  /* Watchdog Timer Always On */
#define FUSE_SPIEN     (unsigned char)~_BV(5)  /* Enable Serial programming and Data Downloading */
#define FUSE_DWEN      (unsigned char)~_BV(6)  /* debugWIRE Enable */
#define FUSE_RSTDISBL  (unsigned char)~_BV(7)  /* External reset disable */
#define HFUSE_DEFAULT (FUSE_SPIEN)
Logged

Miramar Beach, Florida
Online Online
Faraday Member
**
Karma: 147
Posts: 6039
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe I misunderstood. Exactly what macros are you looking for?
Did you look at the "io.h" file there?
« Last Edit: September 30, 2012, 09:55:56 pm by SurferTim » Logged

0
Offline Offline
Full Member
***
Karma: 4
Posts: 218
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was referring to this macro
Code:
PORTB = _BV(PB0);
_BV(?) whatever bit you put in here (?) is set ie _BV(3) sets bit 3 on

I did look in io.h but did not see it ?
« Last Edit: October 01, 2012, 03:53:20 pm by april » Logged

0
Offline Offline
Full Member
***
Karma: 4
Posts: 218
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmm curiouser and curioser if that's a word. I have been looking at compiling these outside of Arduino but using the same header files and compile tools.

The truth of the matter is the PB0/PORTB0  thing  it is an Arduino anomaly !
Using the same header files as used by Arduino I have compiled and flashed an Atmega328p with all of these original examples with the expected results .

The cross definitions in the headers files are correct . The problem then, is in the Arduino usage of these somewhere.
Isn't it peculiar how people seek to hide the truth to protect the established system they have an allegiance to.
Logged

Pages: 1 [2]   Go Up
Jump to: