ATtiny: Rozdiel medzi revíziami
Zo stránky SensorWiki
Bez shrnutí editace |
Bez shrnutí editace |
||
Riadok 77: | Riadok 77: | ||
<tabs> | <tabs> | ||
<tab name="AVR C"><source lang="cpp"> | <tab name="AVR C"><source lang="cpp"> | ||
##define F_CPU 8000000UL // toto je lepsie vlozit do parametrov pre kompilator | |||
#include <avr/io.h> | #include <avr/io.h> | ||
#include <util/delay.h> | |||
#define LED1 PB2 // pripojena dioda | |||
#define LED1 | |||
int main(void) | int main(void) | ||
{ | { | ||
DDRB |= (1 << LED1); // set pin as OUTPUT | |||
while(1) | |||
{ | |||
PORTB |= (1<<LED1); // ... tak rozsviet LED, t.j. set PB5 na log. 1 | |||
_delay_ms(200); | |||
PORTB &= ~(1<<LED1); // zhasni LED, t.j. clear PB5 na log. 0 | |||
_delay_ms(2000); | |||
} | |||
} | } | ||
</source></tab> | </source></tab> |
Verzia z 17:06, 16. február 2023
Rychly zoznam projektov a stranok k programovaniu ATtiny (vid aj projekty DTV)
- Pighixxx Pinout diagram https://pighixxx.tumblr.com/image/93202369320
- ATtiny Core library for Arduino https://github.com/SpenceKonde/ATTinyCore
Strasne vela navodov je na strankach Roba Ulbrichta https://www.arduinoslovakia.eu/
Napriklad:
- Blik
- Tlacitko
- PWM na LEDky
- Generator zvukov
- ATtiny85 a displej TM1637
- 10-bitové PWM
- Jednoducha hracka
Nelineárna citlivosť ľudského oka
SparkFun
- ATtiny Guide
- Quick Reference Sheet - vytlacit na cvika
- RGB sviecka - blikajuce 3 RGB
- Detektor pretecenia vody na baterku CR3202 aj s modifikaciami programu
Technoblogy
- Zoznam
- Push-Button On/Off Switches
- Playing Notes on the ATtiny85
- I2C
- InfraRed Remote
Dalsie:
- Da sa programovat v Blockly cez simulator v TinkerCADe
- Vseobecne
- http://homemadehardware.com/guides/programming-an-attiny85/
- Vseobecne
- SPI Master aj Slave
- I2C Master aj Slave !!!
- RGB demo
- Power save rezimy su dobre opisane (aj s projektom na casovac s pipakom): http://www.technoblogy.com/show?KX0
- Sapien IR CTRL Palov projekt s USB aj IR
- RGB Led tutorial
Problemy
- Ked budu programovacie piny obsadene LED alebo tlacitkom tak moze byt problem, trocha sa tomu venuju tuto: https://www.kanda.com/avr-isp-circuits.html
- Alternativou moze byt UPDI Unified Program and Debug Interface (UPDI) programator, ktory pouziva len jeden pin - podobne ako DebugWire.
- Taky programator sa da spravit z Arduino Nano napr. https://daumemo.com/diy-updi-usb-programmer-which-can-be-made-with-cheap-hardware/
- Zakazat RESET (aby bol k dispozicii dalsi pin) nema zmysel, pretoze bez RESETu sa neda cip preprogramovat inak ako v HV programatore
Fuses
- Explain https://embedderslife.wordpress.com/2012/08/20/fuse-bits-arent-that-scary/
- https://sheepdogguides.com/arduino/attiny/fuses.htm
- https://leo.leung.xyz/wiki/ATtiny85
- http://eleccelerator.com/fusecalc/fusecalc.php?chip=attiny45&LOW=6A&LOCKBIT=FF
- https://www.engbedded.com/fusecalc/
Na koniec:
- https://github.com/MCUdude/MightyCore - moznost Arduino programovania pre ATmega16 a 32
Program na jednoduché blikanie LEDkou
##define F_CPU 8000000UL // toto je lepsie vlozit do parametrov pre kompilator
#include <avr/io.h>
#include <util/delay.h>
#define LED1 PB2 // pripojena dioda
int main(void)
{
DDRB |= (1 << LED1); // set pin as OUTPUT
while(1)
{
PORTB |= (1<<LED1); // ... tak rozsviet LED, t.j. set PB5 na log. 1
_delay_ms(200);
PORTB &= ~(1<<LED1); // zhasni LED, t.j. clear PB5 na log. 0
_delay_ms(2000);
}
}
#define LEDpin 4 //aby nekolidovalo s programatorom, takto sa da trvale nechat pripojeny
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LEDpin, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LEDpin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(LEDpin, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
/*
* LED Blink s periodou 100:1000 ms
* delay vygenerovane tu http://darcy.rsgc.on.ca/ACES/TEI4M/AVRdelay.html
* pre frekvenciu 8 MHz (ATtiny45, internal osc.)
*
* LED je pripojena na pin7 (PORTB.2)
*/
START: SBI DDRB,2 ; DDRB.2 = 1 (t.j. Output)
LOOP:
SBI PORTB,2 ; PORTB.2 = 1 (t.j. High, rozsviet LED)
; CALL DELAY ; UNSUPPORTED INSTRUCTION ON ATtiny!!!!
ldi r18, 5 ; 100ms SVIETI
ldi r19, 15
ldi r20, 242
L1: dec r20
brne L1
dec r19
brne L1
dec r18
brne L1
nop
CBI PORTB,2 ; PORTB.2 = 0 (t.j. Low, zhasni LED)
ldi r18, 41 ; jedna seunda nesvieti (vypocet pre 8MHz!!!)
ldi r19, 150
ldi r20, 128
L2: dec r20
brne L2
dec r19
brne L2
dec r18
brne L2
nop
RJMP LOOP ; Skok na zaciatok