1 .def srbyte = r12 ;byty for search rom algorithm
2 .def writelow = r13; marker for send low
3 .def zero =r14; always zero
4 .def smode=r15; if 1 then send
8 .def bitp = r19 ; bit counter ... shift...
11 .def bytep = r23 ;byte counter
12 #define spmcrval param
15 .equ OWM_READ_ROM_COMMAND=0 ; 0 wegen schnellen test ist dieser wert 0! Daturch wird die Sprungdabelle nicht verwendet
16 .equ OWM_SLEEP=1 ; Warten auf Reset
18 .equ OWM_SEARCH_ROM_S=3 ;send bit
19 .equ OWM_SEARCH_ROM_R=4 ;resive master
20 .equ OWM_READ_COMMAND=5
21 .equ OWM_WRITE_SCRATCHPAD=6
22 .equ OWM_READ_SCRATCHPAD=7
23 .equ OWM_PROGRAMM_PAGE=8
24 .equ OWM_RECALL_FLASH=9
32 ;.equ SRAM_START = 0x60
54 ;---------------------------------------------------
56 ;---------------------------------------------------
62 rjmp start ; Reset-Vector
94 ldi temp,(1<<CS01) //1us
96 ldi temp, HIGH(RAMEND) ; HIGH-Byte der obersten RAM-Adresse
98 ldi temp, LOW(RAMEND) ; LOW-Byte der obersten RAM-Adresse
106 ldi ZL,low(pro_owid*2)
107 ldi ZH,high(pro_owid*2)
111 pro_copy_loop: ;copy ID on SRAM for better handling
118 owwl ;wait for line goes low (polling)
119 sbrs writelow,0 ;test of zero send
120 rjmp pro_loop1 ;no ? goes next
121 sbi OW_DDR,OW_PIN ;yes pull line to low
122 ldi param,50 ;wait for 50 us
124 clr writelow ;reset write low indecator
125 cbi OW_DDR,OW_PIN ;release line
126 owwh ;wait for line is high (it can takes some time cause of the capacity of line)
128 tst smode ;smode=1 for slave sends to master
135 breq pro_loop_end ; now reading ... do nothing
136 pro_loop_send1: ;prebare next bit
137 sbrs rwbyte ,0; if bit 0 set in rwbyte then skip next command
144 ldi param,15 ;wait 15us
148 sbic OW_PINN,OW_PIN ;test line
151 brne pro_loop_end ;no handle need
154 brne pro_loop_send ; Nach dem Gelesen byte koennte gesendet werden muessen....
158 pro_loop_end_test_reset:
159 sbic OW_PINN,OW_PIN //leitung wieder high
163 brlo pro_loop_end_test_reset
173 sbic OW_PINN,OW_PIN //leitung wieder high
178 //leitung wieder high
192 ldi mode,OWM_READ_ROM_COMMAND
193 //Wait for all other devices presents impuls finished
201 ldi ZL,low(pro_stable)
202 ldi ZH,high(pro_stable)
209 rjmp pro_read_rom_command
212 rjmp pro_search_rom_s
213 rjmp pro_search_rom_r
214 rjmp pro_read_command
215 rjmp pro_write_scratchpad
216 rjmp pro_read_scratchpad
217 rjmp pro_programm_page
218 rjmp pro_recall_flash
220 pro_read_rom_command:
224 ldi mode,OWM_READ_COMMAND
229 ldi XL,low(sowid) ;init sram pointer
233 rjmp pro_serchrom_next_bit
237 // rcall pro_owidinit
238 ldi XL,low(sowid) ;init sram pointer
240 ldi mode,OWM_MATCH_ROM
249 breq pro_match_rom_next
254 breq pro_match_rom_found
257 ldi mode,OWM_READ_COMMAND
264 ldi mode,OWM_WRITE_SCRATCHPAD
265 ldi XL,low(scratchpad) ;init sram pointer
266 ldi XH,high(scratchpad)
271 ldi mode,OWM_READ_SCRATCHPAD
272 ldi XL,low(scratchpad) ;init sram pointer
273 ldi XH,high(scratchpad)
281 ldi mode,OWM_RECALL_FLASH
282 ldi XL,low(scratchpad) ;init sram pointer
283 ldi XH,high(scratchpad)
289 rjmp pro_programm_page
303 ldi temp, (0<<EEPM1)|(0<<EEPM0)
316 pro_write_scratchpad:
318 cpi XL,SRAM_START+8+66
319 brlo pro_write_scratchpad_next
322 pro_write_scratchpad_next:
327 cpi XL,SRAM_START+8+66
328 brlo pro_read_scratchpad_next
332 pro_read_scratchpad_next:
338 .equ PAGESIZEB = PAGESIZE*2;PAGESIZEB is page size in BYTES, not words
339 // .org SMALLBOOTSTART
341 ;transfer data from RAM to Flash page buffer
342 ldi bytep, PAGESIZEB ;init loop variable
343 ldi YL,low(scratchpad) ;init sram pointer
344 ldi YH,high(scratchpad)
348 ldi spmcrval, (1<<PGERS) + (1<<SPMEN)
353 ldi spmcrval, (1<<SPMEN)
356 subi bytep, 2;use subi for PAGESIZEB<=256
359 subi ZL, low(PAGESIZEB) ;restore pointer
360 sbci ZH, high(PAGESIZEB) ;not required for PAGESIZEB<=256
361 ldi spmcrval, (1<<PGWRT) + (1<<SPMEN)
363 ;read back and check, optional
365 subi YL, low(PAGESIZEB) ;restore pointer
366 sbci YH, high(PAGESIZEB)
372 subi bytep, 2;use subi for PAGESIZEB<=256
377 ;input: spmcrval determines SPM action
378 ;disable interrupts if enabled, store status
381 ;check for previous SPM complete
389 ;restore SREG (to enable interrupts if originally enabled)
401 cpi XL,SRAM_START+8+2
402 brlo pro_out_bitp1;pro_recall_flash_next
408 cpi XL,SRAM_START+8+66
409 brne pro_recall_flash_cl
413 pro_out_read_command:
414 ldi mode,OWM_READ_COMMAND
423 pro_serchrom_next_bit:
427 ror temp2 ;first bit in C
428 rol rwbyte ;C in first bit
431 ldi mode,OWM_SEARCH_ROM_R ;next mod Resive
437 lsr srbyte ;shift in C lowest bit
438 ror temp2 ; shift in temp2 as highest bit
439 andi rwbyte,0x80 ; clear other bits
441 breq pro_search_rom_s_goon
444 pro_search_rom_s_goon:
448 brne pro_serchrom_next_bit ;prepare next bit
450 andi temp2,0x40 ;;end
451 brne pro_search_rom_found
454 rjmp pro_serchrom_next_bit
456 pro_search_rom_found:
457 ldi mode,OWM_READ_COMMAND
462 ldi mode,OWM_SEARCH_ROM_S
463 ldi bitp,0 ;go to searchrom_s after bit get
466 pro_owid: .DB 0xA3, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xFA