adiishamz
Newbie level 5
i have to make a C programme for atmega32L which enables me to communicate with sim300DZ and respond accordingly to the load circuit which will be attached to output of atmega32L. but i am not very good at C programming and i have designed a program which switches ON and OFF 2 LEDs. can you anyone please help me how to make this program according to my requirement?
1. #include <avr/io.h>
2. #include <util/delay.h>
3.
4. // This program will turn the LEDs on for 100ms,
5. // then off for 200ms, endlessly.
6.
7. int main(void)
8. {
9. // Set Port B pins for 3 and 4 as outputs
10. // PORTB bit 3 = physical pin #2 on the ATTINY45
11. // PORTB bit 4 = physical pin #3 on the ATTINY45
12.
13. DDRB = 0x18; // In binary this is 0001 1000 (note that is bit 3 and 4)
14. // AVR-GCC also would accept 0b00011000, by the way.
15.
16. // Set up a forever loop using your favorite C-style 'for' loop
17. for ( ; 1==1 ; ) // loop while 1 equals 1
18. {
19. // Set Port B pins for 3 and 4 as HIGH (i.e. turn the LEDs on)
20. PORTB = 0x18; // If we wanted only PB4 on, it'd be PORTB=0x10
21.
22. // Use a function (defined in delay.h) to pause 100 milliseconds
23. _delay_ms(100);
24.
25. // Set PORTB to be all LOWs (i.e. turn the LEDs off)
26. PORTB = 0x00;
27.
28. // Delay for a 200ms
29. _delay_ms(200);
30. }
31.
32. return 1;
33. }
1. #include <avr/io.h>
2. #include <util/delay.h>
3.
4. // This program will turn the LEDs on for 100ms,
5. // then off for 200ms, endlessly.
6.
7. int main(void)
8. {
9. // Set Port B pins for 3 and 4 as outputs
10. // PORTB bit 3 = physical pin #2 on the ATTINY45
11. // PORTB bit 4 = physical pin #3 on the ATTINY45
12.
13. DDRB = 0x18; // In binary this is 0001 1000 (note that is bit 3 and 4)
14. // AVR-GCC also would accept 0b00011000, by the way.
15.
16. // Set up a forever loop using your favorite C-style 'for' loop
17. for ( ; 1==1 ; ) // loop while 1 equals 1
18. {
19. // Set Port B pins for 3 and 4 as HIGH (i.e. turn the LEDs on)
20. PORTB = 0x18; // If we wanted only PB4 on, it'd be PORTB=0x10
21.
22. // Use a function (defined in delay.h) to pause 100 milliseconds
23. _delay_ms(100);
24.
25. // Set PORTB to be all LOWs (i.e. turn the LEDs off)
26. PORTB = 0x00;
27.
28. // Delay for a 200ms
29. _delay_ms(200);
30. }
31.
32. return 1;
33. }