;===================== ; Flash Writer Ver.1 ; flash.asm .include "1200def.inc" .def wait_count = r22 ; .def temp = r23 ;tempolary .def _count5ms = r21 ; .def _sreg = r25 ;status-saving during interrupt rouchine .def _temp = r24 ;tempolary during interrupt rouchine ;---constant value .equ INTERVAL = 156 ;period of rotation (5ms,1/256) .equ T_TIMER = 256 - INTERVAL ;interval timer start count .equ STD_TIME = 5 ;standard interval time[ms] .equ CLK_PORT = PORTD ;bit No. of clock out .equ CLK_BIT = 6 ;bit No. of clock out .equ SW_PORT = PIND ;bit No. of switch .equ SW_BIT = 5 ;bit No. of switch .equ LED_PORT = PORTD ;bit No. of LED .equ LED_BIT = 3 ;bit No. of LED .equ RES_IN_PORT = PIND ;bit No. of reset inport .equ RES_IN_BIT = 2 ;bit No. of reset inport .equ RES_OUT_PORT = PORTD ;bit No. of reset outport .equ RES_OUT_BIT = 1 ;bit No. of reset outport .equ SHDN_PORT = PORTD ;bit No. of shut down 12V .equ SHDN_BIT = 0 ;bit No. of shut down 12V .cseg ;--- interrupt vector .org 0 rjmp reset ;reset rjmp reset ;external intterupt INT0 rjmp timer ;timer counter over flow rjmp reset ;analog comparater intterupt .cseg ;--- reset start reset: ;--- init I/O port ldi temp, 0b00000000 out DDRB, temp ldi temp, 0b11111111 out PORTB, temp ldi temp, 0b10110101 out PORTD, temp ldi temp, 0b01001011 out DDRD, temp ldi temp, 0b10110101 out PORTD, temp ;--- init interrupt ldi temp, 0b00000100 ;set 1/256 div. timer pre scaler out TCCR0, temp ldi temp, 0b00000010 ;enable timer over flow interrupt out TIMSK, temp ;--- init variable ldi temp, T_TIMER ;init timer count out TCNT0, temp sei ;enable interrupt ;--- main main: cbi RES_OUT_PORT, RES_OUT_BIT ;reset HiZ mov wait_count, _count5ms ldi temp, 20/STD_TIME + 1 add wait_count, temp sub temp, temp wait_res_turn_H: sbic RES_IN_PORT, RES_IN_BIT rjmp res_turn_H cp wait_count, _count5ms brne wait_res_turn_H ldi temp, 1 ;set 20ms past flag rjmp wait_res_turn_H res_turn_H: sbi RES_OUT_PORT, RES_OUT_BIT sbrc temp, 0 rjmp res_L_past_20ms ldi wait_count, 20/STD_TIME + 1 rcall wait res_L_past_20ms: cbi SHDN_PORT, SHDN_BIT ;12V on ldi wait_count, 5/STD_TIME + 1 rcall wait cbi RES_OUT_PORT, RES_OUT_BIT wait_res_is_H: sbis RES_IN_PORT, RES_IN_BIT rjmp wait_res_is_H ldi wait_count, 5/STD_TIME + 1 rcall wait sbi LED_PORT, LED_BIT ;LED on wait_sw_on: sbic SW_PORT, SW_BIT rjmp wait_sw_on ldi wait_count, 10/STD_TIME + 1 ;chataring free rcall wait sbic SW_PORT, SW_BIT rjmp wait_sw_on ldi wait_count, 10/STD_TIME + 1 rcall wait sbi RES_OUT_PORT, RES_OUT_BIT ;RES L ldi wait_count, 5/STD_TIME + 1 rcall wait sbi SHDN_PORT, SHDN_BIT ;12V off ldi wait_count, 50/STD_TIME + 1 rcall wait cbi LED_PORT, LED_BIT ;LED off loop: rjmp loop ;--- wait wait: mov temp, _count5ms add temp, wait_count wait_loop: cp temp, _count5ms brne wait_loop ret ;--- interval timer interrupt timer: in _sreg, SREG ;save SREG ldi _temp, T_TIMER ;init timer count out TCNT0, _temp inc _count5ms out SREG, _sreg ;load SREG reti ;return from interrupt ;--- end