//!\\ Check My Codes;PLEASE,,and tell me more//!\\

Discussion in 'Embedded Systems and Microcontrollers' started by !!Miss.EE!!, Mar 13, 2009.

  1. !!Miss.EE!!

    Thread Starter Active Member

    Oct 17, 2007
    38
    0
    Hello all :rolleyes:

    I had a H.W asked to make a 16 LED blink one at a time !!

    I already submitted my H.W but using a long way code plus it has some delay at first ??? :(....
    Code ( (Unknown Language)):
    1. #include <avr/io.h>
    2. //#include <util/delay.h>
    3.  
    4. void main()
    5. {
    6.  
    7.     DDRA  = 0xFF;
    8.     DDRB  = 0xFF;
    9.     unsigned int i;
    10.     unsigned int j;
    11.  
    12.         PORTA = 0xFF;
    13.         PORTB = 0xFF;
    14.  
    15.     while (1){
    16.                
    17.             for(i=0;i<=7;i++){
    18.  
    19.             switch(i){
    20.  
    21.                 case 0:
    22.  
    23.                     PORTA = 0xFE;
    24.            
    25.                     //_delay_ms(500);
    26.  
    27.                     PORTA = 0xFF;
    28.  
    29.                     //_delay_ms(500);
    30.  
    31.                     break;
    32.                 .
    33.                 .              
    34.                 .
    35.                 .
    36.                 .
    37.                 .
    38.  
    But before I gave up to that codes I used this one but it wouldn't work ??!!:confused:
    Code ( (Unknown Language)):
    1. #include <avr/io.h>
    2. //#include <util/delay.h>
    3.  
    4. void main()
    5. {
    6.  
    7.     DDRA  = 0xFF;
    8.     DDRB  = 0xFF;
    9.     signed int i;
    10.     signed int j;
    11.    
    12.  
    13.     while (1){
    14.                
    15.         PORTA = 0xFF;
    16.         PORTB = 0xFF;
    17.  
    18.         PORTA = PORTA<<1;
    19.  
    20.         //_delay_ms(500);
    21.  
    22.         PORTA = 0xFF;
    23.  
    24.         //_delay_ms(500);
    25.            
    26.             for(i=6;i>1;i--){
    27.  
    28.             PINC = 0x7F>>i
    29.  
    30.             //_delay_ms(500);
    31.  
    32.             PORTA = 0xFF;
    33.  
    34.             //_delay_ms(500);
    35.  
    36.     }  
    37.         PORTB = PORTB<<1;
    38.  
    39.         //_delay_ms(500);
    40.  
    41.         PORTB = 0xFF;
    42.  
    43.         //_delay_ms(500);
    44.  
    45.             for(j=6;j>1;j--){
    46.  
    47.             PORTB = 0x7F>>j;
    48.  
    49.             //_delay_ms(500);
    50.  
    51.             PORTB = 0xFF;
    52.  
    53.             //_delay_ms(500);
    54.  
    55.             }
    56.   }
    57. }
    Just to make things clear ; the question was mostly like:

    some help please just to know more about it since I am new to this field :p

    Regards
     
    Last edited: Mar 13, 2009
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Can you post your circuit so that we can see how you interfaced the AVR to the LEDs?

    hgmjr
     
  3. !!Miss.EE!!

    Thread Starter Active Member

    Oct 17, 2007
    38
    0
    Hi hgmjr ;

    it is only simulation and C language ...... we didn't use the AVR Kit yet ,

    actually we ordered it and waiting 4 it .....

    it is only pure C language using AVR Studio ...

    Can you help ??!!
     
  4. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    I see! So do you plan to use a low or a high on the output pins to turn the LEDs on?

    From your code it appears that your 16 LEDs are connected to PORTA and PORTB. Is that your intent?

    hgmjr
     
    Last edited: Mar 13, 2009
  5. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Try the changes that I have indicated in red.

    hgmjr
     
    Last edited: Mar 13, 2009
  6. !!Miss.EE!!

    Thread Starter Active Member

    Oct 17, 2007
    38
    0
    Dear hgmjr;

    I appreciate your replays :) I am really thankful ;)

    however what you gave me is the opposite way , well I mean :

    high (0xFF) is turning off all the LEDs
    low (0x00) is turning ON all the LEDs


    part of the question was :


    waiting for your replay , and sorry if i am annoying you !

    Regards;
     
  7. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Did you take a look at the changes I suggested in the earlier reply?

    hgmjr
     
  8. !!Miss.EE!!

    Thread Starter Active Member

    Oct 17, 2007
    38
    0
    Yes I tried it ,

    Only the FIRST LED Blinks in both ports, the other staid off during the loop no change on them .

    I tried to inverse the operation but it wouldn't work :mad:

    Regards ; :)
     
  9. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    It simulated correctly when I used WINAVR.

    Are you using WINAVR as your C compiler?

    hgmjr
     
  10. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    If you don't mind maybe you can post your updated code. Maybe I can spot another code flaw.

    hgmjr
     
  11. !!Miss.EE!!

    Thread Starter Active Member

    Oct 17, 2007
    38
    0
    It Is Atmel AVR studio 4!!
     
  12. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Actually AVRSTUDIO4 is the Integrated Development Environment and by itself it only allows programming in AVR Assembler. WINAVR is the C-language compiler that is a plug-in for AVRSTUDIO4.

    There are several other C-compilers and I was not sure which one you were using.

    I am sure which one you are using now.

    If you would post your updated source code I will take another look at it.

    hgmjr
     
  13. !!Miss.EE!!

    Thread Starter Active Member

    Oct 17, 2007
    38
    0
    HERE IS THE FILES
     
  14. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    You haven't noticed my suggested changes in the #5 reply in this post.

    I put my suggested changes in the insert. I used the red font to highlight the the lines that I suggested you could change to make the program work.

    hgmjr
     
  15. !!Miss.EE!!

    Thread Starter Active Member

    Oct 17, 2007
    38
    0
    ooh ooh sorry i though you wanted the original :p

    here is the file when i modified it as you suggested ;
     
  16. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    I found the problem.

    I accidently made an error in transcribing the changes.

    I wrote PORTA = PORTA & ~(0x01>>i); /* corrected error on the statement... */

    When I should have written PORTA = PORTA & ~(0x01<<i); /* corrected error on the statement... */

    I made the same error in the PORTB statement.

    Sorry,
    hgmjr
     
    Last edited: Mar 13, 2009
  17. !!Miss.EE!!

    Thread Starter Active Member

    Oct 17, 2007
    38
    0
    I think you mean "i" NOT "1"

    and yes it worked , I am really thankful ;)

    I own you one ,Really grateful

    Thanks A Bunch ;
     
  18. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    You are correct. It should be "i" not "1".


    hgmjr
     
Loading...