Download presentation
Presentation is loading. Please wait.
1
Intro to AVR ATtiny2313 CS423 Dick Steflik
2
AVR ATtiny2313
3
2313 Features RISC, 120 instructions, most executable in one clock cycle, 32x8 general purpose registers, up to 20 MIPS at 20 Mhz Memory - 2Kbytes Flash, 128 Bytes EEPROM, 128 bytes SRAM Peripherals Features – 1-8bit timer, 1- 16 bit timer, 4- PWM channels, On-chip analog comparitor, watchdog timer, Universal Serial Interface, Full Duplex USART 18 programmable I/O lines Operating Voltage – 2.7 – 5.5VDC In System Programmable via SPI (Serial Peripheral Interface)
4
Basic Pin Descriptions VCC – Digital Supply Voltage Gnd – ground Port A (PA2..PA0) – 3 bit, bi-directional I/O with selectable internal pullups Port B (PB7..PB0) – 8 bit, bi-directional I/O with selectable internal pullups Port D (PD6-PD0) - 7 bit, bi-directional I/O with selectable internal pullups Reset – system reset – active low XTAL1 – external crystal input (alt. PA0) XTAL2 – external crystal output (alt. PA1)
5
Serial Peripheral Interface Bus SPI is used by all Atmel microcontrollers for loading the flash program memory (many other OEMs also) Easily implemented in hardware Faster than other methods (I2C, SMBUS) Master-slave methodology Half or Full Duplex operation
6
SPI with 2 slaves SPI MasterSPI Slave 1 SCLK MISO MOSI SS1 SCLK MOSI MISO SS SPI Slave 2 SCLK MOSI MISO SS SS2
7
AVR Programming AVR ProgrammerATtiny2313 SCLK MISO MOSI SCLK (19) MOSI (17) MISO (18) PC PPT RS232 USB AVRDUDE RESET (1) GND GND (10) GND VCC (20) VCC
8
API Applications Flash, EEPROM, MMC and SD cards Sensors Temperature Pressure (touch screens) LCD Panels Communications (802.15 (ZigBee), CAN, Ethernet....) Control – D/A, A/D, Digital Pots, position encoders
10
/* Blinker Demo */ /* Include useful pre-defined functions */ #include // Defines pins, ports, etc to make programs easier to read #define F_CPU 100000UL // Sets up the default speed for delay.h #include int main(){ DDRD = _BV(PD4); /* enable output on port D, pin 4 */ while(1){ PORTD = _BV(PD4); _delay_ms(1000); PORTD &= ~_BV(PD4); _delay_ms(1000); } return(0); }
11
Interrupts 10x0000ResetExternal Pin, POR, BOR,Watchdog Reset 20x0001INT0External Interrupt Request 0 30x0002INT1External Interrupt Request 1 40x0003TIMER1 CAPTTimer/Counter1 Capture Event 50x0004TIMER1 COMPATimer/Counter1 Compare Match A 60x0005TIMER1 OVFTimer/Counter1 Overflow 70x0006TIMER0 OVFTimer/Counter0 Overflow 80x0007USART0,RXUSART0 Receive complete 90x0008USART0 UDREUSART0 Data Register Empty 100x0009USART0 RXUSART0 Transmit Complete 110x000AANALOG COMPAnalog Comparitor 120x000BPCINTPin Change Interrupt 130x000CTIMER1 COMPBTimer/Counter1 Compare Match B 140x000DTIMER0 COMPATimer/Counter0 Compare Match A 150x000ETIMER0 COMPBTimer/Counter0 Compare Match B 160x000FUSI STARTUSI Start Condition 170x0010USI OVERFLOWUSI Overflow 180x0011EE READYEEPROM Ready 190x0012WDT OVERFLOWWatchdog Timer Overflow
12
ISR Macro #include Defines the beginning of your Interrupt Servicing Routine Places the starting address of the ISR code into the interrupt vector ISR(SIG_INT0) { cli(); //disable interrupts. sei(); // enable interrupts } places address of the body if the ISR into 0x0001
13
Programmable Interrupts INT0 - Pin 6 INT1 – Pin 7 PCINT – Pins 12-19 PCMSK – Pin Change Mask Register Which pins contribute to the pin change interrupt 4 different pin changes can be detected Pin goes low Any logical change Falling edge Rising edge
14
Interrupt Sense Control Interrupt 1 Sense Control ISC11ISC10Description 0 0Low level on INT1 0 1Any logical change on INT1 1 0Falling edge on INT1 1 1Rising Edge on INT1 Interrupt 0 Sense Control ISC01ISC00Description 0 0Low level on INT0 0 1Any logical change on INT0 1 0Falling edge on INT0 1 1Rising Edge on INT0
15
MCU Control Register Defines which of the four states will activate the interrupt ex. MCUCR = (1<<ISC01) | (1<<ISC00) Interrupt on pin INT0 falling edge
16
Example #include int main(void) { // set Pin 6 (PD02) as the interrupt pin PCMSK |= (1<<PIND2); // interrupt on INT0 falling edge MCUCR = (1<<ISC01) | (1 << ISC00); // turn on interrupts GIMSK |= (1<<INT0); // wait for interrupt while (1) {... };
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.