// ************************************* // *Etienne Cantin * // *Prog Pololu PWM * // *Version 1 Rev 2 * // *20 Mars 2017 * // ************************************* #define FOSC 20000000 // Clock Speed #define BAUD 115200 #define MYUBRR FOSC/16/BAUD -1 #define F_CPU 8000000UL // 20MHZ ext Clock Pololu, Maximum atMega328P #include "avr/io.h" #include #include "avr\interrupt.h" #include "ctype.h" //#include "fonctcom.h" #include #include #include #include #include "util/delay.h" //#include <> #include //*********************************Déclarations PWM Pololu*********************************** void delay (uint16_t ms); void PwmPololu(uint8_t select,double vitessePourc); unsigned char setBit(unsigned char port, unsigned char bitNo); unsigned char clearBit(unsigned char port, unsigned char bitNo); //*********************************Déclarations COMM Série*************************************** uint8_t dataIN; uint8_t test; uint8_t tempoRX; uint8_t dir; unsigned char car; char bufStr[40]; void comInit(); uint8_t rxChar(void); void txChar(uint8_t sendChar); const char* rxString(void); void txString(char *str); int main (void) { DDRB = 0x6F; DDRD = 0x04; DDRC|= (1<<5); // set PC5 as output comInit(); while (1) { //sei(); //delay(500); //test= rxChar(); //txChar('a'); /*if(test && 0x80) dir=1; else dir=0; test = test & 0x7F;*/ //PwmPololu(0,5); //txChar(0); sprintf(bufStr,"%s","test"); txString(bufStr); //PwmPololu(1,100); //txChar(rxChar()); delay(1000); for(int i=0;i<100;i++) { //PwmPololu(0,i); //delay(2); } } return 0; } unsigned char setBit(unsigned char port, unsigned char bitNo) { port = port | (1<> 8); UBRR0L = MYUBRR; //UCSR0A = (1<0) //vitessePourc += 1; //Gain pour valeur trop petite PORTB = setBit(PORTB, 3); //PORTD = setBit(PORTD, 3); //PORTD = setBit(PORTD, 5); PORTD = setBit(PORTD, 6); delay(vitessePourc); PORTB = clearBit(PORTB, 3); PORTD = clearBit(PORTD, 3); PORTD = clearBit(PORTD, 5); PORTD = clearBit(PORTD, 6); _delay_us(6000); //0-6ms = 0-100% } else if (select==1) { vitessePourc = (vitessePourc/50)*25; //PORTB = setBit(PORTB, 3); PORTD = setBit(PORTD, 3); PORTD = setBit(PORTD, 5); //PORTD = setBit(PORTD, 6); delay(vitessePourc); PORTB = clearBit(PORTB, 3); PORTD = clearBit(PORTD, 3); PORTD = clearBit(PORTD, 5); PORTD = clearBit(PORTD, 6); _delay_ms(50); } } void delay (uint16_t ms) { while(ms > 0) { ms--; _delay_us(990); } }