add base info, pwm, i2c
This commit is contained in:
commit
c1d7fc0434
22
info.txt
Normal file
22
info.txt
Normal file
@ -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/
|
BIN
mega pinout.jpg
Normal file
BIN
mega pinout.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 217 KiB |
42
program PWM.c
Normal file
42
program PWM.c
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#define F_CPU 16000000UL //частота работы микроконтроллера
|
||||||
|
#include <util/delay.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
37
program i2c (2-wire).c
Normal file
37
program i2c (2-wire).c
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// Wire Peripheral Receiver
|
||||||
|
// by Nicholas Zambetti <http://www.zambetti.com>
|
||||||
|
// 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 <Wire.h>
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
BIN
~WRL1150.tmp
Normal file
BIN
~WRL1150.tmp
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user