# microccontroller at90s2313

#### ahuida_love

##### New Member
Hi, all how are you I dont for get to say thank you for all from my pleasure, My question this time about at90s2313 not work out
In the simulation work but on the circuit board not work so this is my first program can you guide me to set it also iam sorry for my bad English expression
thank you

#### ahuida_love

##### New Member
Hi, this is the program:

void main() {
ddrd=0x00;
portd=0x0e;

Portb=0;
ddrb=0xff;
while (1)
{
if (pind.b0==1 && pind.b1==1&& pind.b2==0&&pind.b3==0&& pind.B4==0)
Portb=0b00001011;
else
Portb=0;
if(pind.b0==1 && pind.b1==0&& pind.b2==0&&pind.b3==0&&pind.b4==0)
portb=0b00000011;
else
portb=0;
if(pind.b0==1&&pind.b1==0 && pind.b2==1&&pind.b3==0&&pind.b4==0)
portb=0b00000010;
else
portb=0;
if (pind.b0==1 && pind.b1==1&&pind.b2==1&&pind.b3==0&&pind.b4==0)
portb=0b00000100;
else
portb=0;
if(pind.b3==1&&pind.b1==1&&pind.b2==0&&pind.b0==0&&pind.b4==0)
portb=0b00011001;
else
portb=0;
if(pind.b3==1&&pind.b1==0&&pind.b2==0&&pind.b0==0&&pind.b4==0&&pind.B5==0)
portb=0b00010001;
else
portb=0;

if(pind.b3==1&&pind.b2==0&&pind.b1==1&&pind.b0==0&&pind.b4==0&&pind.B5==0)
portb=0b00010000;
else
portb=0;
if (pind.b3==1&&pind.b2==1&&pind.b1==1&&pind.b0==0&&pind.b4==0&&pind.B5==0)
portb=0b00010000;
else
portb=0;

}
}

#### ahuida_love

##### New Member
What simulator?? You have no fuses settings... Can you show the full code..ie.. all includes as well?
Hi,I use proteus7 profeessional as simulation

#### rjenkinsgb

##### Well-Known Member
Most Helpful Member
Look carefully at your program flow again.

Every IF line that does not match forces port B to 0, so even if one of them does match all the conditions and write a value to port B, the next IF line will go to it's ELSE and overwrite that with zero, probably within a fraction of a microsecond if its a fast MCU.

Should it actually be more like this?
For any matching input bits, set a fixed output value that stays active as long as the input does not change?

C:
Portb=0;
ddrb=0xff;
while (1)
{
if (pind.b0==1 && pind.b1==1 && pind.b2==0 && pind.b3==0 && pind.B4==0)
Portb=0b00001011;

else if(pind.b0==1 && pind.b1==0 && pind.b2==0 && pind.b3==0 && pind.b4==0)
portb=0b00000011;

else if(pind.b0==1 && pind.b1==0 && pind.b2==1 && pind.b3==0 && pind.b4==0)
portb=0b00000010;

else if (pind.b0==1 && pind.b1==1 && pind.b2==1 && pind.b3==0 && pind.b4==0)
portb=0b00000100;

else if(pind.b3==1 && pind.b1==1 && pind.b2==0 && pind.b0==0 && pind.b4==0)
portb=0b00011001;

else if(pind.b3==1 && pind.b1==0 && pind.b2==0 && pind.b0==0 && pind.b4==0 && pind.B5==0)
portb=0b00010001;

else if(pind.b3==1 && pind.b2==0 && pind.b1==1 && pind.b0==0 && pind.b4==0 && pind.B5==0)
portb=0b00010000;

else if (pind.b3==1 && pind.b2==1 && pind.b1==1 && pind.b0==0 && pind.b4==0 && pind.B5==0)
portb=0b00010000;

else
portb=0;

}
}

#### ahuida_love

##### New Member
For any matching input bits, set a fixed output value that stays active as long as the input does not change?
Hi, first thank you for reply but I ask you can you give me more explain by short example

#### rjenkinsgb

##### Well-Known Member
Most Helpful Member
In the original version, you have many separate sections that each say something like:

If this input combination happens, turn some outputs on.
Otherwise, turn all outputs off.

Even if one code section matches, all the other sections that do not match will do the "turn everything off" part, writing zero to the port.

The outputs can never stay set, no matter what the inputs are.

The modified version looks for each possible input combination and only turns the outputs off (with portb = 0; ) if none of the match lines are valid.

#### ahuida_love

##### New Member
In the original version, you have many separate sections that each say something like:

If this input combination happens, turn some outputs on.
Otherwise, turn all outputs off.

Even if one code section matches, all the other sections that do not match will do the "turn everything off" part, writing zero to the port.

The outputs can never stay set, no matter what the inputs are.

The modified version looks for each possible input combination and only turns the outputs off (with portb = 0; ) if none of the match lines are valid.
In the original version, you have many separate sections that each say something like:

If this input combination happens, turn some outputs on.
Otherwise, turn all outputs off.

Even if one code section matches, all the other sections that do not match will do the "turn everything off" part, writing zero to the port.

The outputs can never stay set, no matter what the inputs are.

The modified version looks for each possible input combination and only turns the outputs off (with portb = 0; ) if none of the match lines are valid.
Hi.how are I hope you doing well do you men I should have to modify the out put to turn part of portb , not all the port must turn off and back turn part of it on

#### rjenkinsgb

##### Well-Known Member
Most Helpful Member
You need to explain exactly what you are trying to do?

The modified version I posted would give a fixed output on port b as long as the inputs matched one of the combinations in the appropriate IF line.

If that's not what you want, you need to say what it should do.

#### ahuida_love

##### New Member
You need to explain exactly what you are trying to do?

The modified version I posted would give a fixed output on port b as long as the inputs matched one of the combinations in the appropriate IF line.

If that's not what you want, you need to say what it should do.
Hi, is this right :
if(pind.b6==1&&pind.b2==0&&pind.b3==1&&pind.b1==0)
portb=0b00010000;
else
portb=0;

#### rjenkinsgb

##### Well-Known Member
Most Helpful Member
Hi, is this right :
On its own, as the only thing in the program loop - yes.

Having several blocks like that cannot work, as ALL the ones that do not pass the IF statement execute the "portb=0;" line.

That line must only exist once no matter how many conditional lines there are!

Do you have port d set to all inputs ?

#### ahuida_love

##### New Member
On its own, as the only thing in the program loop - yes.

Having several blocks like that cannot work, as ALL the ones that do not pass the IF statement execute the "portb=0;" line.

That line must only exist once no matter how many conditional lines there are!

Do you have port d set to all inputs ?
yes pord =input include reset pin and crystal 4,5 as you see in the code I just trigger it

#### ahuida_love

##### New Member
sorry port d
yes pord =input include reset pin and crystal 4,5 as you see in the code I just trigger it
sorry port d

#### be80be

##### Well-Known Member
If you have a at90s2313 proteus7 is not making code for it that will run on it is using the atiny 2313 which is not the same chip
The at90s2313 from what is see microchip is using the same chip for both parts but if you have a older
at90s2313 they have same pins and stuff but the older at90s2313 memory don't match.

• Data and Non-volatile Program Memory – 2K Bytes of In-System Programmable Flash Endurance 1,000 Write/Erase Cycles – 128 Bytes of SRAM – 128 Bytes of In-System Programmable EEPROM En
The atiny2313 has
AVR091: Replacing AT90S2313 by ATtiny2313
So long story short if you have a real at90s2313 and your complying code for it that code more then
likly not work on a newer attiny 2313 thats labeled as a at902313.

#### ahuida_love

##### New Member
If you have a at90s2313 proteus7 is not making code for it that will run on it is using the atiny 2313 which is not the same chip
The at90s2313 from what is see microchip is using the same chip for both parts but if you have a older
at90s2313 they have same pins and stuff but the older at90s2313 memory don't match.

The atiny2313 has
AVR091: Replacing AT90S2313 by ATtiny2313
So long story short if you have a real at90s2313 and your complying code for it that code more then
likly not work on a newer attiny 2313 thats labeled as a at902313.
thank you I will appreciate that and I flow your advices

Loading