Tikiwiki seems to have a problem displaying this page properly. It seems to be upset by "<<" in the non-parse section.
I may have to move this to a file in the gallery.
--------
AVRASM ver. 2.1.9 E:\avr\mega8inkchip\RWchip.asm Sun Sep 28 10:56:20 2008 E:\avr\mega8inkchip\RWchip.asm(2): Including file 'E:\avr\mega8inkchip\m8def.inc' .list .CSEG ; working registers for the program. .def EEdata = r13 .def EEPending = r14 .def chipId = r15 .def temp = r16 .def counter1 = r17 ; counters for various routines. .def EEcount = r18 .def counter2 = r19 .def counter0 = r20 .def count = r21 ; Bit counter .def serbyte = r22 .def work1 = r23 .def EEindex = r24 .def SyncFlag = r25 .MACRO led1on cbi PORTC,PB2 ; LED ON .ENDMACRO .MACRO led1off sbi portc,PB2 ; LED OFF .ENDMACRO .MACRO led2on sbi PORTD,PB2 ; LED ON .ENDMACRO .MACRO led2off cbi portD,PB2 ; LED OFF .ENDMACRO ;Reset vector (must be the first code generated) 000000 c00b rjmp RESET ; Reset Handler 000001 9518 reti ; Ext Interrupt 0 Handler (not used) 000002 9518 reti ; Ext Interrupt 1 Handler (not used) 000003 9518 reti ; Timer1 Capture Handler 000004 9518 reti ; Timer1 Compare Handler 000005 9518 reti ; Timer1-B compare Handler (not used) 000006 9518 reti ; Timer1 Overflow Handler (not used) 000007 9518 reti ; Timer0 Overflow Handler 000008 9518 reti 000009 9518 reti 00000a 9518 reti 00000b 9518 reti ;----------------------------------------------------------------- ; code starts executing here on reset RESET: 00000c 98a4 cbi dataddr,data0bit; 00000d 98a5 cbi dataddr,data1bit; 00000e 98ac cbi dataport,data0bit; 00000f 98ad cbi dataport,data1bit; 000010 e50f ldi temp,LOW(RAMEND) ; set the stack pointer 000011 bf0d out SPL, temp 000012 e004 ldi temp,HIGH(RAMEND) 000013 bf0e out SPH, temp 000014 9aa2 sbi DDRC,PB2 ; Enable led driver. 000015 9a8a sbi DDRD,PB2 ; Enable led driver. 000016 9aaa led1off 000017 9892 led2off ; Work out chip ID from EEPROM data. 000018 e38f ldi EEindex,$3f // the ID bits are in eeprom cell x3f 000019 d0a3 rcall readee // read the eeprom. 00001a 9506 lsr temp // move the ID bit into the bottom 3 bits. 00001b 9506 lsr temp 00001c 9506 lsr temp 00001d 9506 lsr temp 00001e 7007 andi temp,7 // this shouldn't be needed. 00001f 2ef0 mov chipId,temp // mov the ID into another register where it stays forever. wait4sync: 000020 d094 rcall waitsyncPL // if sync is low wait. // led1on 000021 d063 rcall getnib // get the three ID bits and the R/W bit. 000022 2399 tst SyncFlag // see if sync went low before nib was recieved. 000023 f449 brne waitchip2 // sync was low back to start 000024 2d7f mov work1,chipId // get chip ID from low register to working register. 000025 1707 cp temp,work1 // compare - will be equal if ID matches and R/W = read mode. 000026 f411 brne notreadID // if not equal we jump to test for write mode. 000027 d035 dosend: rcall senddata // The ID etc match so we call the rountine to dump the EEPROM data to the printer. 000028 c004 rjmp waitchip2 // finished - possibly due to sync going low. Return to start. notreadID: // check for ID+write bit 000029 6078 ori work1,0x8 // add the write bit to our ID 00002a 1707 cp temp,work1 // compare again. 00002b f409 brne waitchip2 // if not equal go back to start 00002c d002 rcall data2eeprom // was equal so call write eeprom rountine. // rjmp waitchip2 // finished - possibly due to sync going low. Return to start. waitchip2: 00002d d08b rcall waitsyncNL // wait for sync to go low (if it isn't already) before looping back. 00002e cff1 rjmp wait4sync ;-------------------------------------------------------------------------------------------------------- ; Note the printer usually only writes a few bytes. The 32 byte write happens in the external chip writer. data2eeprom: // Stored data to the EEPROM till 32 bytes are stored or sync goes low. 00002f 98aa led1on 000030 24ee clr EEpending 000031 e280 ldi EEindex,$20 // This is where the data lives in the EEPROM. 000032 e220 ldi EEcount,$20 // This is the maximum number of bytes to store. // ldi EEcount,$3 // This is the maximum number of bytes to store. eewrtloop: getbyte: ; get byte from serial stream return type in temp or ff in temp if timeout etc 000033 2766 clr serbyte // clear sync flag register 000034 d03f rcall waitclkPE // wait for clk high edge, data bit in temp and sync flag returned 000035 2399 tst SyncFlag // test for sync low. 000036 f4a1 brne abortGB // if low return. 000037 20ee tst EEpending 000038 f019 breq notpending 000039 d01a rcall EEWrite // data byte was pending call EEPROM write rountine. 00003a 24ee clr EEpending 00003b 9583 inc EEindex // Inc index to next address notpending: 00003c 9566 lsr serbyte // shift the shifter 00003d 7100 andi temp,1<carry 0000ab f410 brcc OutLow // if carry clear jump to "output a low" 0000ac 9aac sbi dataport,data0bit // we are sending a one so set output pin high. 0000ad c001 rjmp DecOutCount // go to loop counting code. OutLow: 0000ae 98ac cbi dataport,data0bit // output a low - set pin low. DecOutCount: 0000af dfea rcall waitclkNE // wait for a clock edge or sync low. 0000b0 2399 tst SyncFlag // was sync low. 0000b1 f411 brne abort // yes it was low leave loop and return. 0000b2 953a dec counter2 // dec counter 0000b3 f7b1 brne OutLoop // if non-zero repeat loop 0000b4 9508 abort: ret // either the byte was sent or sync went low - return.
;-------------------------------------------------------------------------------------------------------- waitsyncPL: ; look for positive LEVEL of "sync" line - not the clock. 0000b5 b300 in temp,syncpin 0000b6 7400 andi temp,1<