Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <stdint.h>
- #include <avr/interrupt.h>
- #include "HD44780.h"
- #define ADCIN_X PC0
- #define ADCIN_Y PC1
- #define FORWARD 1<<PC5
- #define BACKWARD 1<<PC4
- #define PWM 1<<PD5
- int main()
- {
- char wynik[4];//bufor
- LCD_Initalize(); //inicjalizacja LCD
- LCD_Clear();
- TCCR0A |= (1<<COM0B1) | (1<<WGM00);
- TCCR0B |= (1<<CS01);
- ICR1 = 1023;
- DDRD |= PWM;
- ADCSRA = (1<<ADEN) |(1<<ADPS0) |(1<<ADPS1) |(1<<ADPS2);
- ADMUX = (1<<REFS1) | (1<<REFS0) | (0<<MUX2) | (0<<MUX1) | (1<<MUX0);
- DDRC |= (FORWARD) | (BACKWARD);
- DDRC &=~ (1<<ADCIN_Y);
- while(1)
- {
- ADCSRA |= (1<<ADSC); //ADSC: uruchomienie pojedynczej konwersji
- while(ADCSRA & (1<<ADSC)); //czeka na zakończenie konwersji
- LCD_Clear();
- LCD_GoTo(0,0);
- itoa(ADC, wynik, 10);
- LCD_WriteText(wynik);
- LCD_GoTo(5,0);
- char oc[4];
- itoa(OCR0B, oc, 10);
- LCD_WriteText(oc);
- if (ADC<420)
- {
- PORTC &= ~FORWARD;
- PORTC |= BACKWARD;
- OCR0B = (255) - ((51*ADC)/88);
- }
- else if (ADC>460)
- {
- PORTC &= ~BACKWARD;
- PORTC |= FORWARD;
- OCR0B = -((1870/7) - ((17*ADC)/28));
- }
- else
- {
- PORTC &= ~BACKWARD;
- PORTC &= ~FORWARD;
- OCR0B = 0;
- }
- _delay_ms(10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement