electronicsbaazar
Newbie level 1
- Joined
- Feb 27, 2013
- Messages
- 1
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,284
Code:
#include <avr/io.h>
#include <util/delay.h>
void main()
{
DDRA=0X00;
unsigned char i,x,temp,y;
//Configure TIMER1
TCCR1A|=(1<<COM1A1)|(1<<COM1B1)|(1<<WGM11); //NON Inverted PWM
TCCR1B|=(1<<WGM13)|(1<<WGM12)|(0<<CS11)|(1<<CS10); //PRESCALER=1 MODE 14(FAST PWM)
ICR1=19999; //fPWM=50Hz (Period = 20ms Standard).
DDRD|=(1<<PD4)|(1<<PD5); //PWM Pins as Out
while(1)
{
x=PINA&0b00001111;
if(x==0b00001111)
{
OCR1A=600; //45 degree
_delay_ms(200);
}
OCR1A=1050; //90 degree
_delay_ms(200);
OCR1A=1950; //135 degree
_delay_ms(200);
OCR1A=2400; //180 degree
_delay_ms(200);
OCR1A=600; //45 degree
_delay_ms(200);
OCR1A=1050; //90 degree
_delay_ms(200);
OCR1A=1950; //135 degree
_delay_ms(200);
OCR1A=2400; //180 degree
_delay_ms(200);
OCR1A=1950; //135 degree
_delay_ms(200);
}
}
work perfectly
Last edited by a moderator: