Close

Small progress: switch interface

A project log for Minimalist A-go-go

A project inside Attiny. I will not step out for larger one till I complete it.

kodera2tkodera2t 03/19/2016 at 08:260 Comments

I just added one switch, which changes LED blinking interval by the following source...

.def R_TEMP1	=R17
.def R_TEMP2	=R18
.def R_TEMP3	=R19
.def R_TEMP4	=R20
.def sw_cond	=R21
.equ led_p	= 3
.equ sw_in	= 4
.equ	SUB_COUNT = 8
	RJMP MAIN

MAIN:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	LDI R_TEMP1, 4 ; prescaler of timer0 setting
	OUT TCCR0B, R_TEMP1; clock of CPU divided by 5= 1024,4=256,3=64
; real frequency of blink will be (MPU clock)/256/precsaler value
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	LDI R_TEMP1, 1<<PUD
	OUT MCUCR, R_TEMP1
	LDI R_TEMP1, (1<<led_p) ;seting PORTB for output
	OUT DDRB, R_TEMP1;seting led_p for output
	LDI R_TEMP2, (1<<led_p)|(1<<sw_in);led_p=PB3 on, sw_in=pullup
    OUT PORTB, R_TEMP2

LOOPPOINT:
	SBI PINB, led_p; flip led on and off
	IN R_TEMP3, PINB ; reading state of portb
	ANDI R_TEMP3, (1<<sw_in) ; checking sw status
	BRNE ANOTHER; if sw_in not equal 1, jump to ANOTHER
	LDI sw_cond, 0; putting sw_cond to zero if sw_in is zero
	RJMP POINT
ANOTHER:
	LDI sw_cond, 1; putting sw_cond to 1 if sw_in is one
POINT:
	RCALL DELAY2
	SBI PINB, led_p ; flip led on and off
	RCALL	DELAY2; calling subroutine delay
	RJMP LOOPPOINT ;jump to LOOPPOINT

DELAY2:	; subroutine DELAY
	LDI R_TEMP4, 1
	ANDI sw_cond, 1 ; checking current sw condition
	BRNE COUNTER2 ; if switch is zero, jump to COUNTER2
	LDI R_TEMP4, SUB_COUNT
COUNTER2:
	IN R_TEMP1, TIFR0; loading current state (TIFR0) of TIMER0
	ANDI	R_TEMP1, 1<<TOV0; checking overflow flag TOV0
	BREQ	COUNTER2 ; if counter is not overflow, jump to COUNTER2
	LDI	R_TEMP1, 1<<TOV0 ; writing 1 to TOV0 leads to reset of TIMER0
	OUT	TIFR0, R_TEMP1
	LDI R_TEMP3, 1
	SUB R_TEMP4, R_TEMP3 ; decrease 1 to SUB_COUNT number
	BRNE COUNTER2 ; if count by sub_count is finished, ret,else to counter2
	RET

This source provides 227 bytes .hex file. Still I have much room for programming on ATtiny13..


Discussions