Mcu-notes-01
From wikipost
Jump to navigationJump to search
Presentation Notes for the Microcontroller Introduction at Westlakes Amateur Radio Club
Data sheets
- Datasheets Link to various datasheets
Hardware setup:
- connection diagram
- batch/script files
- avrdude
Avrdude program script
- Windows
@echo off set PROJECT=blinkled set SPEED=16000000UL set PORT=\\.\USBSER000 set GCC_DEVICE=attiny85 set PGM_DEVICE=t85 set PGM_PROTO=avrispv2 set GCC_OPTIMISATION=-Os set AVRTOOLS=C:\winavr-20100110\bin echo compile program avr-gcc -g %GCC_OPTIMISATION% -Wall -mcall-prologues -DF_CPU=%SPEED% -mmcu=%GCC_DEVICE% -c -o %PROJECT%.o %PROJECT%.c echo create object file avr-gcc -g %GCC_OPTIMISATION% -Wall -mcall-prologues -DF_CPU=%SPEED% -mmcu=%GCC_DEVICE% %PROJECT%.o -o %PROJECT%.obj echo convert object file to hex file avr-objcopy -R .eeprom -O ihex %PROJECT%.obj %PROJECT%.hex echo write program to chip avrdude -F -c %PGM_PROTO% -P %PORT% -p %PGM_DEVICE% -U flash:w:%PROJECT%.hex echo avr-list output: echo ---------------- %AVRTOOLS%\avr-size -C --mcu=%GCC_DEVICE% %PROJECT%.obj > %PROJECT%_avr-size.txt type %PROJECT%_avr-size.txt pause
- Linux
Demo Programs for the ATtiny85:
- Blink led
/* Demo program: blinkled.c This program continously loops, bringing PB4 high and low with one-second intervals. ATtiny85 +--- ---+ (RST) PB5 -|1 |_| 8|- VCC PB3 -|2 7|- PB2 (SCK) +---|<|------ PB4 -|3 6|- PB1 (MISO) | led +-- GND -|4 5|- PB0 (MOSI) | | +-------+ +--/\/\/--+ 1k Pololu programming cable pinout (top view) +---+ ---------------- gnd |o o| rst ribbon cable mosi |o o| sck -----red-------- vdd |o o| miso +---+ NOTE: The T85 must be externally powered with 5V (4.5V does NOT work!) A t85 driving a standard 2x16 LCD without backlit LED on draws about 8.5mA so with 100mA to spare on a USB port you could consider grabbing 5V from the Pololu programmer. The 5V pin on the programmer is labeled: 'VBUS (+5V)' */ #include <avr/io.h> #include <util/delay.h> #define LED PB4 // Define ext led pin on PB4 #define OUTPUT 0 #define INPUT 1 #define LOW 0 #define HIGH 1 void pinMode(int pin,int state) { if (state == OUTPUT) { (DDRB |= (1 << pin)); } else { (DDRB &= ~(1 << pin)); } } void digitalWrite(int pin, int state) { // make sure port is set to output DDRB |= (1 << pin); if (state == HIGH) { (PORTB |= (1 << pin)); } else { (PORTB &= ~(1 << pin)); } } int main( void ) { pinMode(LED,OUTPUT); // Set output direction on LED while ( 1 ) { digitalWrite (LED,HIGH); _delay_ms(1000); digitalWrite (LED,LOW); _delay_ms(1000); } return 0; }
- Read push button state
- Analog to Digital
- PWM (pulse width modulation)
Web links:
(AVR)
- http://www.atmel.com/products/microcontrollers/avr/default.aspx Atmel 8 and 32-bit microcontrollers
- http://www.pololu.com/catalog/product/1300 Pololu, a basic USB-based AVR ISP Programmer
- http://winavr.sourceforge.net/ WinAVR, AVR-GCC for Windows
- http://www.nongnu.org/avrdude/ AVRdude, ROM downloader/updater
- http://www.engbedded.com/fusecalc AVR Fuse Byte calculator
- http://www.rickety.us/2010/03/arduino-avr-high-voltage-serial-programmer/ ATtiny fuse byte resetter
- http://www.arduino.cc/ Arduino, prototyping platform
- http://www.avrfreaks.net/ AVRfreaks, forum for Atmel microcontrollers
(Other)
- http://www.raspberrypi.org/ Raspberry Pi, ARM-based Single Board Computer (SBC)
- http://www.sparkfun.com/ Sparkfun, USA-based electronics store
- http://littlebirdelectronics.com/ Littlebird Electronics, reseller (and more) for Sparkfun products
- http://www.robotgear.com.au RobotGear, reseller (and more) for Sparkfun products and Pololu programmer
- http://www.diptrace.com/ Diptrace, printed circuit board (PCB) design software
- http://oshpark.com/ OSH Park (previously dorkbotpdx), inexpensive manufacturer for low-volume PCB prototyping
- http://www.gabotronics.com/development-boards/xmega-xprotolab.htm XprotoLab, a tiny oscilloscope and wave form generator (AWG)