Senso:
Here it is in assembly language, just the bare silicon. It assembles to 60 bytes.; This is an assembly language version of the Arduino 'Blinky' sketch
;
.nolist
.include "m168def.inc"
.list
.equ fclk = 16000000 ; system clock frequency
; register usage
.def temp = R16 ; temporary storage
.equ led_port = PORTB ; led connection
.equ led_num = PORTB5
.equ led_ddr = DDRB
; ***************************************************************************
.org 0x0000
start:
; initialize the stack pointer to the highest RAM address
ldi temp,low(RAMEND)
out SPL,temp
ldi temp,high(RAMEND)
out SPH,temp
; configure the microprocessor pin for the led
sbi lED_ddr, lED_num ; output
loop:
sbi led_port, led_num ; turn LED on
ldi YL, low(1000) ; keep the led on for 1 second (1000 mS)
ldi YH, high(1000)
call delayYx1mS
cbi led_port, led_num ; turn LED off
ldi YL, low(1000) ; keep the led off for 1 second (1000 mS)
ldi YH, high(1000)
call delayYx1mS
rjmp loop
; ============================== Time Delay Subroutines =====================
delayYx1mS:
; this subroutine provides a delay of (YH:YL) x 1 mS
; the 16-bit register provides for a delay of up to 65.535 Seconds
; enter with: (YH:YL) = delay data
call delay1mS ; delay for 1 mS
sbiw YH:YL, 1 ; update the the delay counter
brne delayYx1mS ; counter is not zero
; arrive here when delay counter is zero (total delay period is finished)
ret
; ---------------------------------------------------------------------------
delay1mS:
; this subroutine provides a delay of 1 mS
; it chews up fclk/1000 clock cycles (including the 'call')
push YL ; [2] preserve registers
push YH ; [2]
ldi YL, low (((fclk/1000)-18)/4) ; [1] delay counter
ldi YH, high(((fclk/1000)-18)/4) ; [1]
delay1mS_01:
sbiw YH:YL, 1 ; [2] update the the delay counter
brne delay1mS_01 ; [2] delay counter is not zero
; arrive here when delay counter is zero
pop YH ; [2] restore registers
pop YL ; [2]
ret ; [4]
; ============================== End of Time Delay Subroutines ==============
This really isn't much different than your C version (aside from having to write the delay routine).
If the instructions in the loop are changed to to toggle the LED, rather than explicitly turn it on and off, it reduces to 50 bytes but you lose the ability to have different on/off times.loop:
sbi led_pin, led_num ; toggle led
ldi YL, low(1000) ; keep the led on or off for 1 second (1000 mS)
ldi YH, high(1000)
call delayYx1mS
rjmp loop
Don