8th EMBEDDED PROGRAMING
step1: BOARD DESIGN

This week our assignment is to use the board we designed in the 6th week to do something. According the datasheet, Attiny44 is a AVR Micro-controller which contains 4K Bytes of In-System Programmable Program Memory Flash.

 

 

Pin Configurations of Attiny44

Pin Configurations of ISP

step2: Embeded Programming

I connect the board with FabISP. FabISP works as a programmer. Then programming by Cygwin64

Sample code : blink.c ( A program for one LED Control with switch)

    #include

        #include

        #include

 

        #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 pin, I/O,

        #define LED_port PORTB

        #define LED_direction DDRB

        #define LED_pin (1 << PB2)

 

        int main(void){

            //clock

            CLKPR = (1 << CLKPCE);

            CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0);

 

            //LED

            output(LED_direction, LED_pin); //Pin OUTPUT指定

            clear(LED_port, LED_pin); //clear pinport LOW

 

            //loop

           while(1){

               set(LED_port, LED_pin);

               _delay_ms(2000); //2000ms

               clear(LED_port, LED_pin);

               _delay_ms(500); //500ms

           }

        }

 

I've never did a computer program before, so started with Neil's program and Guidance program, and I learned:

 

I can use the # include and # define each time by copy and paste. Then, int main can be used as function defined by # define

 

Write the programs that need to be process every time in while(1){   }

 

set(LED_port,LED_pin);

LED→ON

clear(LED_port,LED_pin);

LED→OFF

_delay_ms_();

Can be specified as mm seconds to wait

 

Then I made a program, when I press the button, the LED will be light.

 

 

EMAIL: 626919025@qq.com    HOMEPAGE: www.li-shang.cc