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

Thread Starter

!!Miss.EE!!

Joined Oct 17, 2007
38
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 ??? :(....
Rich (BB code):
#include <avr/io.h>
//#include <util/delay.h>

void main()
{

	DDRA  = 0xFF;
	DDRB  = 0xFF;
	unsigned int i;
	unsigned int j;

		PORTA = 0xFF;
		PORTB = 0xFF;

	while (1){
				
			for(i=0;i<=7;i++){

			switch(i){

				case 0:

					PORTA = 0xFE;
			
					//_delay_ms(500);

	    			PORTA = 0xFF;

					//_delay_ms(500);

					break;
				.
				.				
				.
				.
				.
				.
But before I gave up to that codes I used this one but it wouldn't work ??!!:confused:
Rich (BB code):
#include <avr/io.h>
//#include <util/delay.h>

void main()
{

	DDRA  = 0xFF;
	DDRB  = 0xFF;
	signed int i;
	signed int j;
	

	while (1){
				
		PORTA = 0xFF;
		PORTB = 0xFF;

		PORTA = PORTA<<1;

		//_delay_ms(500);

		PORTA = 0xFF;

		//_delay_ms(500);
			
			for(i=6;i>1;i--){

			PINC = 0x7F>>i

			//_delay_ms(500);

	    	PORTA = 0xFF;

			//_delay_ms(500);

	}	
		PORTB = PORTB<<1;

		//_delay_ms(500);

		PORTB = 0xFF;

		//_delay_ms(500);

			for(j=6;j>1;j--){

			PORTB = 0x7F>>j;

			//_delay_ms(500);

	    	PORTB = 0xFF;

			//_delay_ms(500);

			}
  }
}
Just to make things clear ; the question was mostly like:

5. Write a C program for the ATmega 169 ..
Writing a 0 turns on an LED
writing a 1 turns off an LED.
The program should start by turning on/off (Blinking) one led at a time, starting with LED0 and ending with LED15.
This process should repeat indefinitely.
some help please just to know more about it since I am new to this field :p

Regards
 
Last edited:

Thread Starter

!!Miss.EE!!

Joined Oct 17, 2007
38
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 ??!!
 

hgmjr

Joined Jan 28, 2005
9,027
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:

hgmjr

Joined Jan 28, 2005
9,027
Hello all :rolleyes:

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


But before I gave up to that codes I used this one but it wouldn't work ??!!:confused:
Rich (BB code):
#include <avr/io.h>
//#include <util/delay.h>
 
int main(void)
{
 
    DDRA  = 0xFF;
    DDRB  = 0xFF;
    unsigned char i;
    unsigned char j;
 
 
    while (1){
 
        PORTA = 0xFF;
        PORTB = 0xFF;
 
        PORTA = PORTA<<1;
 
        //_delay_ms(500);
 
        PORTA = 0xFF;
 
        //_delay_ms(500);
 
            for(i=1;i<=7;i++){
 
            PORTA = PORTA & ~(0x01<<i); /* Fixed my initial oops... */
 
            //_delay_ms(500);
 
            PORTA = 0xFF;
 
            //_delay_ms(500);
 
    }    
        PORTB = PORTB<<1;
 
        //_delay_ms(500);
 
        PORTB = 0xFF;
 
        //_delay_ms(500);
 
            for(j=1;j<=7;j++){
 
            PORTB = PORTB & ~(0x01<<j);  /* Fixed my initial oops...   */
 
            //_delay_ms(500);
 
            PORTB = 0xFF;
 
            //_delay_ms(500);
 
            }
  }
 
 return(0);   
 
}
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
Try the changes that I have indicated in red.

hgmjr
 
Last edited:

Thread Starter

!!Miss.EE!!

Joined Oct 17, 2007
38
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
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 :

Writing a 0 turns on an LED
writing a 1 turns off an LED.
The program should start by turning on/off (Blinking) one led at a time, starting with LED0 and ending with LED15.
This process should repeat indefinitely.

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

Regards;
 

Thread Starter

!!Miss.EE!!

Joined Oct 17, 2007
38
Did you take a look at the changes I suggested in the earlier reply?

hgmjr
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 ; :)
 

hgmjr

Joined Jan 28, 2005
9,027
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
 

hgmjr

Joined Jan 28, 2005
9,027
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
 

hgmjr

Joined Jan 28, 2005
9,027
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:
Top