Discussion in "AVR Discussion Forum" started by    qesper    Nov 24, 2013.
Sun Nov 24 2013, 01:23 am
#1
Hi everybody,i have some difficulties with an avr project i have to do.If anyone can help me I would be grateful.
AVR Studio 4 & ISiS Proteus v7.8 SP2,Microprocessor: ATmega16
This is the input: SW1 -PB7.
This are the outputs : LED1 - PA7,LED2-PA6,LED3-PA5,LED4-PA4.
LED 5-PC7,LED 6-PC6,LED7-PC5,LED8-PC4.
When i click run i need the code to do this:
turn on LED1&LED2(both at the same time )about 1sec then turn off LED1&Led2,turn on LED3&LED4(both) about 1 sec then turn off....turn LED7&LED8 on (both) about 1 sec then turn them off.
Then when i press the SW1 button on the schematic (the input SW1 on the port PB7) to do the exact cycle but from LED7,8 to LED 1,2 (turn on then turn off) ,always 2 leds working!!.

I tried to make the right code but it i don't know where are the mistakes,or if i put the needed code for this type of led pattern.
I will attach what i did on my own here to get some orientation on the subject but i would like,if anyone knows the code to post it here.
Thanks for your time.


[ Edited Sun Nov 24 2013, 01:25 am ]
Thu Nov 28 2013, 05:28 am
#2
ok from what I understood, you want to run that pattern when sw1 is pressed. right?
I really cant understand what are you trying with the code. can you comment your code explaining what you're doing in timer ISR? I believe timer is only used for delay purpose, is it correct?
Thu Nov 28 2013, 08:37 pm
#3


ok from what I understood, you want to run that pattern when sw1 is pressed. right?
I really cant understand what are you trying with the code. can you comment your code explaining what you're doing in timer ISR? I believe timer is only used for delay purpose, is it correct?

Ajay Bhargav


Yes i need a delay of 1 sec between two leds on (ex:LED1&LED2 ON wait a sec then LED3&LED4 ON ,,,,etc and then from LED7&LED8 to....LED1&LED2)
I need this pattern to run when SW1 is not pressed: LED1&LED2 ON, turn them off after a sec then -LED3&LED4 ON turn them off after a sec ....etc
And another pattern when SW1 is pressed to do this:LED7&LED8 ON, turn them off after a sec then -LED5&LED6 ON turn them off after a sec ....etc


[ Edited Thu Nov 28 2013, 08:38 pm ]
Mon Dec 02 2013, 01:07 am
#4
ok... You dont need ISR for that purpose. you want to enable two LEDs at the same time.. so when SW1 is pressed shift right and if not pressed shift left e.g.

//use a variable to store previous state
// e.g led_state
// initially set to 3 for LED1 and LED2 turn on
if (SW1) {
    LED = led_state;
    // sw1 not pressed, shift left
    led_state <<= 2;
    if (led_state == 0)
        led_state = 0x3; //init to 3 again if its 0
} else {
    LED = led_state;
    // sw1 pressed, shift right
    led_state >
>
= 2;
    if (led_state == 0)
        led_state = 0xC0; //so that LED7 and LED8 turns on.
}
delay_1sec(); //give a 1 sec delay.. put whole thing in a while(1) loop

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

gtaletrzua
Fri May 03 2024, 10:55 am
Clydehet
Wed May 01 2024, 06:44 pm
Davidoried
Wed May 01 2024, 06:11 pm
KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am