EMBEDDED PROGRAMMING
- Read a microcontroller data sheet
- Program your board to do something, with as many different programming languages and programming environments as possible
- Optionally, experiment with other architectures
to accomplish this assignment i used hello board i created in week6 (Electronics Design)
Read a microcontroller data sheet
what I have read in data sheet is all about the High Performance, Low Power AVR® 8-bit Microcontroller(), that are convenient for running simple programs. The ATtiny45 and ATtiny85 have eight legs and are almost identical, except that the ATtiny85 has twice the memory of the ATtiny45 and can therefore hold more complex programs. The ATtiny45 and ATtiny85 have 8-legs and more inputs and outputs.
The ATtiny45 or 85 is a great option for running simple Arduino programs: it’s small, cheap and relatively easy to use. It does, however, have some limitations relative to the ATmega328P on an Arduino Uno. There are fewer pins, meaning you can’t connect as many components. There’s less flash memory (4KB or 8KB instead of 32KB), meaning your programs can’t be as big. There’s less RAM (256 or 512 bytes instead of 2KB), meaning you can’t store as much data. And there’s no hardware serial port or I2C port (Wire library), making communication trickier. some data funded on datasheet
Parameter | Value |
Program Memory Type | Flash |
Program Memory (KB) | 4 |
CPU Speed (MIPS) | 20 |
RAM Bytes | 256 |
Data EEPROM (bytes) | 256 |
Digital Communication Peripherals | 1-SPI, 1-I2C |
Capture/Compare/PWM Peripherals | 5PWM |
Comparators | 1 |
Temperature Range (C) | -40 to 85 |
Operating Voltage Range (V) | 1.8 to 5.5 |
Pin Count | 8 |
Cap Touch Channels | 3 |
for programing at the first time i used Arduino IDE 1.6.7 so by default ATtiny we need to add ATtiny board in ardunio board manager, here there is the procedures
Coding
for programing this hello world i used arduino pin library as we saw in data sheet or Eagle design
the arduino code i used: mostly for blinking by refering to data sheet and the code witten by Neil Gershenfeld about hello.ftdi.16E5.blink.c where i referd to write this code by reading data sheet it easy acces port register, in easy way instead of using arduino libray to describe the number of pin by writting this code also save the memory of the chip used to store data.
#include <avr/io.h> #include <inttypes.h> #include <util/delay.h> #define F_CPU 8000000UL /* am using internal 8MHz crystal oscillator */ #define LED_PORT PORTB /* PORTx - register for LED output */ #define LED_DDR DDRB /* LED data direction register */ #define BLINK_TIME 100 /* time to wait after a led change state */ #define BLINK_TIMEE 1000 /* time to wait after a led change state */ #define BLINK_TIMEEE 500 /* time to wait after a led change state */ int main(void) { LED_DDR |= (1 << LED_BIT); // set LED pin as output while(1) { LED_PORT |= (1 << LED_BIT); // turn LED on _delay_ms(BLINK_TIME); // wait BLINK_TIME milliseconds LED_PORT &= ~(1 << LED_BIT); // turn LED off _delay_ms(BLINK_TIME); // wait BLINK_TIME milliseconds LED_PORT |= (1 << LED_BIT); // turn LED on _delay_ms(BLINK_TIMEE); // wait BLINK_TIME milliseconds LED_PORT &= ~(1 << LED_BIT); // turn LED off _delay_ms(BLINK_TIMEE); // wait BLINK_TIME milliseconds LED_PORT |= (1 << LED_BIT); // turn LED on _delay_ms(BLINK_TIMEEE); // wait BLINK_TIME milliseconds LED_PORT &= ~(1 << LED_BIT); // turn LED off _delay_ms(BLINK_TIMEEE); // wait BLINK_TIME milliseconds } // The led is going to brick according to the above sequence }
pinMode()
digitalWrite()
digitalRead()
analogRead()
analogWrite()()
micros())
delayMicroseconds()
millis()
Delayt()
pulseIn()
shiftOut()
let use some of those arduino command to program our board
const int buttonPin = A3; // the number of the pushbutton pin const int ledPin = A1; // the number of the LED pin // Variables will change: int ledState = HIGH; // the current state of the output pin int buttonState; // the current reading from the input pin int lastButtonState = LOW; // the previous reading from the input pin // the following variables are unsigned long's because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int. unsigned long lastDebounceTime = 0; // the last time the output pin was toggled unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers void setup() { pinMode(buttonPin, INPUT); pinMode(ledPin, OUTPUT); // set initial LED state digitalWrite(ledPin, ledState); } void loop() { // read the state of the switch into a local variable: int reading = digitalRead(buttonPin); // check to see if you just pressed the button // (i.e. the input went from LOW to HIGH), and you've waited // long enough since the last press to ignore any noise: // If the switch changed, due to noise or pressing: if (reading != lastButtonState) { // reset the debouncing timer lastDebounceTime = millis(); } if ((millis() - lastDebounceTime) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state: // if the button state has changed: if (reading != buttonState) { buttonState = reading; // only toggle the LED if the new button state is HIGH if (buttonState == HIGH) { ledState = !ledState; } } } // set the LED: digitalWrite(ledPin, ledState); // save the reading. Next time through the loop, // it'll be the lastButtonState: lastButtonState = reading; }if this above code seems to be complex dowm here you can the one i write my self both they work same
const int buttonPin = A2; const int ledPin = A1; int ledState = LOW; boolean buttonState = LOW; int pressed=0; void setup() { pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT); } void loop() { if(debounceButton(buttonState) == HIGH && buttonState == LOW) { pressed++; buttonState = HIGH; } else if(debounceButton(buttonState) == LOW && buttonState == HIGH) { buttonState = LOW; } if(pressed == 10) { digitalWrite(ledPin,HIGH); } } boolean debounceButton(boolean state) { boolean stateNow = digitalRead(buttonPin); if(state!=stateNow) { delay(10); stateNow = digitalRead(buttonPin); } return stateNow; }