Split from: I/O problem with code

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

 Hi,how are you I have problem at90s2313 in simulation work and on circuit board not work how I can set this to work out.

 please guide me to set it. I use crystall and button to reset also nothing happend thanks

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;

 

    }
}

 

ihope you find me bascom error221

Last Edited: Mon. Aug 12, 2019 - 12:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

huida@love wrote:
in simulation work and on circuit board not work

Not much of a problem description, work/not work???

 

Tell what you expected the code to do, then what it is doing, and how you tested to come to your conclusion.

You also state it works (what ever that means) in simulation, but not on real hardware, so tell us about your real hardware, show a picture or a schematic.

Things we often see, are not all power pins are connected, no bypass caps (100nf) on all power/gnd pin pairs, etc, pictures and/or schematic will help with that.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
stack gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

 

Using all of those port compares is somewhat ridiculous and dangerous.  What if the port changes during the compares? That is probably not what you want.

Get the port first, then compare to that.

 

myport=portd;   //used for compares

 

// GCC supports 0b binary prefix

if ((myport & 0b00001111 )== 0b00001010)    

    blah blah

else

if ((myport & 0b00001111) == 0b00000111)
 

or using hex:

 

if ((myport & 0x0F) == 0x0A)

    blah blah

else

if ((myport & 0x0F) == 0x07)

 

 

edit: corrected binary notation & parenthesis

 

 

 

 

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Tue. Aug 13, 2019 - 08:09 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

if (myport & 0x00001111 == 0x00001010)

    blah blah

else

if (myport & 0x00001111 == 0x00000111)

 

I was going to suggest the OP learn to use hex and avoid the use of binary constants, it's just so easy to miscount the ones & zeros,

but then you used that incorrectly as well, or perhaps you have been working with a lot of 64 bit systems lately!  smiley

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
stack gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

 then you used that incorrectly as well 

That's funny...took a few secs to see what was wrong, I was too busy poking through his code...will update 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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


avrcandies wrote:

if (myport & 0x0F == 0x0A)

    blah blah

 

I've been doing C for some decades, and the precedence table isn't ingrained in my synapses.  So I find it easier to just use a set of parentheses and avoid the strain.

if ((myport & 0x0F) == 0x0A)

 

Hmmm-- do you see which operators are in levels 8 and 9?  Do you really want to present your code fragments as being "better"?

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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


Had to check that myself (I doubt anyone memorizes the precedence table!):

int main()
{
    printf("%X\n", 0x0A & 0x0F == 0x0A);
    printf("%X\n", (0x0A & 0x0F) == 0x0A);
}

 

That's a very easily encountered "gotcha" I guess!

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

Had to check that myself  

I momentarily thought about checking it, then thought nah...haste makes waste when you are trying to be quick.   I wonder how many variations of operator precedence there are amongst all the "common" languages.  There's sure to be a comparison chart somewhere.  I get students who go parenthesis crazy to the point where statements become unreadable.

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

avrcandies wrote:
I get students who go parenthesis crazy

Nothing crazy about using a NECESSARY pair, is there?  As I implied, if you were unsure why didn't you put them in, if nothing else to make the snippet clearer?

 

So, is everyone commenting on OP's coding style, or is there some causation that has been found?  For example, I found a causation in the "better" presented code fragment.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Not sure why portb=0 is scattered all over the place to make thing  harder to read....if it is none of the choices, then set portb=0.  Or it might be allowable to set it at the beginning, regardless & possibly be overriden by one of the choices.

As mentioned, you should read the ports once & make decisions off that reading, otherwise can get logically impossible results, if the port changes midstream.  Occasionally you may want it the other way, but it should be intentional. 

 

 in simulation work and on circuit board not work

wonderful description! 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

Personally I'd vote for:

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

    Portb=0;
    ddrb=0xff;
    while (1)
    {
        pins = PIND & 0x3F;
        swithc(pins) {
            case 0b00011:
                PORTB = 0b00001011;
                break;
            case 0b00001:
                PORTB = 0b00000011;
                break;
            case 0b00101:
                PORTB = 0b00000010;
                break;
            case 0b00111:
                PORTB = 0b00000100;
                break;
            case 0b00011:
                PORTB = 0b00011001;
                break;
            case 0b000001:
                PORTB = 0b00010001;
                break;
            case 0b001110:
                PORTB = 0b00010000;
                break;
            case 0b001110:
                PORTB = 0b00010000;
                break;
            default:
                PORTB = 0;
    }
}

which could well be wrong because the existing code is all over the place and very confused.

 

For example how can you have some states that consider pind.5 and some don't ??

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

clawson wrote:
For example how can you have some states that consider pind.5 and some don't ??

I guess we need to create that Karnaugh map...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.