commit c1d7fc043422a0eeba736c2a22263f63f7dd0d89 Author: Класс Date: Tue Apr 11 14:28:20 2023 +0300 add base info, pwm, i2c diff --git a/info.docx b/info.docx new file mode 100644 index 0000000..6cfe8f1 Binary files /dev/null and b/info.docx differ diff --git a/info.txt b/info.txt new file mode 100644 index 0000000..4197acc --- /dev/null +++ b/info.txt @@ -0,0 +1,22 @@ +существует 5 блоков +1 блок - опрашивание (пришла ли команда) +2 блок - TWI (I2C) +3 блок - работа с ШИМ (ВКЛ, частота, скважность) - 8-bit T/C0 + +Самый низкий уровень - блок 2-wire и блок 8-bit timer + +шим таймер: +изначальные регистры инициализация +до куда считать и когда сбрасывать +компаратор + +i2c +16000000UL + +Информация: +https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf +https://robotclass.ru/tutorials/pwm/ +https://3d-diy.ru/wiki/arduino-moduli/interfeys-peredachi-dannykh-i2c/ +https://smartep.ru/index.php?page=avr_c_examples#p12 +http://microsin.net/programming/avr/example-using-the-twi-i2c.html +https://forum.amperka.ru/threads/%D0%B0%D0%BF%D0%BF%D0%B0%D1%80%D0%B0%D1%82%D0%BD%D1%8B%D0%B9-i2c-%D0%B2-atmega328p.18806/ \ No newline at end of file diff --git a/mega pinout.jpg b/mega pinout.jpg new file mode 100644 index 0000000..62b6d08 Binary files /dev/null and b/mega pinout.jpg differ diff --git a/program PWM.c b/program PWM.c new file mode 100644 index 0000000..663f8bd --- /dev/null +++ b/program PWM.c @@ -0,0 +1,42 @@ +#define F_CPU 16000000UL //частота работы микроконтроллера +#include +#include +#include + + +void timer1_init(int frequency, int dutycycle){ + DDRD |= (1 << PORTD6); //OC1A (12) + DDRD |= (1 << PORTD5); //OC1B (11) + + TCCR1A = 0; + TCCR1B = 0; + TCNT1 = 0; + + // Не инверсный режим работы и OC0B + TCCR1A |= (1 << COM1A1) | (0 << COM1A0); + + //Fast PWM (Быстрый ШИМ) + TCCR1A |= (1 << WGM11) | (1 << WGM10); + TCCR1B |= (1 << WGM13) | (1 << WGM12); + + //Предделитель - 1024 + TCCR1B |= (1 << CS12) | (0 << CS11) | (1 << CS10); + + //Частота = Частота_мк / (Предделитель * OCR1A) + OCR1A = F_CPU / 1024 / frequency; + + //Скважность + OCR1B = OCR1A * dutycycle / 100; +} + +int main(void){ + + cli(); + timer1_init(); //после инициализации на выводе OC1B (11) будет ШИМ сигнал + sei(); + + while (1){ + } + + return 0; +} \ No newline at end of file diff --git a/program i2c (2-wire).c b/program i2c (2-wire).c new file mode 100644 index 0000000..5da77bc --- /dev/null +++ b/program i2c (2-wire).c @@ -0,0 +1,37 @@ +// Wire Peripheral Receiver +// by Nicholas Zambetti +// Demonstrates use of the Wire library +// Receives data as an I2C/TWI Peripheral device +// Refer to the "Wire Master Writer" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() +{ + Wire.begin(4); // join i2c bus with address #4 + Wire.onReceive(receiveEvent); // register event + Serial.begin(9600); // start serial for output +} + +void loop() +{ + delay(100); +} + +// function that executes whenever data is received from master +// this function is registered as an event, see setup() +void receiveEvent(int howMany) +{ + while(1 < Wire.available()) // loop through all but the last + { + char c = Wire.read(); // receive byte as a character + Serial.print(c); // print the character + } + int x = Wire.read(); // receive byte as an integer + Serial.println(x); // print the integer +} \ No newline at end of file diff --git a/~WRL1150.tmp b/~WRL1150.tmp new file mode 100644 index 0000000..9690cbd Binary files /dev/null and b/~WRL1150.tmp differ