Selasa, 24 April 2012

CARA MEMUTAR MOTOR SERVO

TUGAS Alg. & Pemrog. Kasus Elektro #


#include <mega8.h>
#include <delay.h>
// Declare your global variables here
void servo(int derajat) {
OCR1A=((derajat+90)*10+600)/4;
}
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=Out Func1=Out Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=0 State1=0 State0=T
PORTB=0×00;
DDRB=0×06;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 250.000 kHz
// Mode: Fast PWM top=ICR1
// OC1A output: Non-Inv.
// OC1B output: Non-Inv.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0xA2;
TCCR1B=0x1B;
TCNT1H=0×00;
TCNT1L=0×00;
ICR1H=0×00;
ICR1L=0×00;
OCR1AH=0×00;
OCR1AL=0×00;
OCR1BH=0×00;
OCR1BL=0×00;
ICR1=4999;
while (1) {
// Place your code here
int i;
servo(-90);
delay_ms(1000);
servo(0);
delay_ms(1000);
servo(90);
delay_ms(1000);
servo(-90);
delay_ms(1000);
for (i=-90; i<90; i++) {
servo(i);
delay_ms(50);
}
for (i=90; i>-90; i–) {
servo(i);
delay_ms(50);
}
}
}

nama : umargani
kelas :3ibo1 {listrik}
npm : 13409101