08. Embedded Programming

Data Sheet

ATtiny44A(I used this for FabISP and Original PCB)
ISP header
Original PCB
  • PA0~PA7PORTA, 8bit
  • PB0~PB3PORTB, 4bit
  • PA0TX
  • PA1RX
  • NecessaryMISO,MOSI,VCC,GND,SCK,RESET
  • PA2, PA32*2 PIN header
  • PA7button
  • PB2LED

FabISP

coding

blink.c (program to Control a LED with switch)

#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>

#define output(directions,pin) (directions |= pin) // set port direction for output
#define set(port,pin) (port |= pin) // set port pin
#define clear(port,pin) (port &= (~pin)) // clear port pin
#define pin_test(pins,pin) (pins & pin) // test for port pin
#define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set
#define position_delay() _delay_ms(1000)

#define LED_port PORTB
#define LED_direction DDRB
#define LED_pin (1 << PB2)
#define buttonPin PINA7
#define loop_count 30

int main(void){
    CLKPR = (1 << CLKPCE);
    CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0);
    output(LED_direction, LED_pin);
    clear(LED_port, LED_pin);
	while(1){
        if (bit_is_clear(PINA, buttonPin)) //If button is pushed (PA7 == 1)
       {
		   set(LED_port, LED_pin);
       } else {
           clear(LED_port, LED_pin);
       }
    }
    return 0;
}

writing

First, I tried to write the program with FabISP. This model was valentin model. I had error after put "sudo make -f blink.make program-usbtiny". The error was caused by USB connection between FabISP and PC. So, I made FabISP of valentin again. But, I had same error again. As a result, I tried to Neil's FabISP using microUSB connecter.
Soldering
Set up FabISP, then wrote the program
Writing process. I succeeded writing code.

result

I think writing code with a C language is more difficult than Arduino because there are many function I don't know yet.