Ok, so after getting some feasibility questions answered in the microcontroller section, I have started to program my project (mostly driving a 7-segment display [bare '328]).
I have successfully been able to modify the PORTB values, but I am having trouble with PORTD. Namely, with this bit of code (library).
void Seg::initialization()
{
DDRB = B11111111;
DDRD = DDRD | 11110011;
/*
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);*/
PortD[0] = 00010011; //The HIGH value of pins 0 and 1 are for something else
PortD[1] = 00100011;
PortD[2] = 01000011;
PortD[3] = 10000011;
}
void Seg::update() {
for (int x = 0; x < 4; x++) {
//digitalWrite(x+4, HIGH);
PORTB = PortB[x]; //don't worry about this, there's more to this program
PORTD = PortD[x];
delayMicroseconds(5000);
//digitalWrite(x+4, LOW);
}
}
The PORTD values don't all change state, but when digitalWrite is used instead, it works perfectly.
Exactly, except PORTD only seems to work on PD7 and PD6... and strangely, according to the oscilloscope, pin 7 seems to also be acting like an extra pin! (Double duty cycle w/ tiny dip halfway through HIGH state)
Since the language can already specify binary values.
Personally I'd use hexadecimal, because counting zeroes in values like 0b01000000000000000000000000000000 is error-prone and painful. 0x40000000 is
so much easier.
Since the language can already specify binary values.
Personally I'd use hexadecimal, because counting zeroes in values like 0b01000000000000000000000000000000 is error-prone and painful. 0x40000000 is
so much easier.
PORTD = 0x40 ;
Thanks for the suggestion! Maybe that could fix some issues I'm having with assigning bytes to an array!