DEVICE SX28, OSCHS3, TURBO, STACKX, OPTIONX IRC_CAL IRC_SLOW FREQ 50000000 ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- 'inputpin var RB.0 'data from drive outputbyte var RC 'data to pc byteready var RB.2 'notify pc byte is ready pcack var RB.3 'pc saying it got the byte numstoredbits var byte '# of stored bits in shift reg storedata var byte 'actual stored data seenedge var bit 'seen an edge or are we idly? pending var byte 'swapped with wkpnd_b, RTCC or edge? validhigh var byte 'how many high bits have we seen in a row xmitbytes var byte inputpin var byte first var byte myrtcc var byte inxfernow var bit itseight var bit lastproc var byte lasthigh var byte sendme var byte unhandledbytes var byte WATCH seenedge,1,UDEC WATCH numstoredbits,8,UDEC WATCH storedata,8,UBIN WATCH xmitbytes,8,UDEC WATCH inputpin,1,UDEC WATCH pending.0,1,UBIN WATCH validhigh,8,UDEC WATCH inxfernow,1,UBIN WATCH itseight,1,UBIN WATCH myrtcc,8,UDEC WATCH lastproc,8,UDEC WATCH lasthigh,8,UDEC WATCH unhandledbytes,8,UDEC ' ------------------------------------------------------------------------- INTERRUPT NOCODE ' ------------------------------------------------------------------------- ASM SETB rb.1 MOV myrtcc, RTCC CLR FSR ISR_Start: 'a rollover here rtcc would be zero, and myrtcc should be 4 'if this was an edge, myrtcc would be much higher like 230 etc CJA myrtcc,#5,@processedge 'if myrtcc > 5 then processedge 'i dunno if Im keeping this here, doublecheck this 'wkpnd_b = 0 MODE $09 MOV !RB, #0 JNB seenedge,@goback 'if seenedge = 0 then goback 'are we idle? inc validhigh jb validhigh.2,@goidle 'if validhigh = 4 then goidle CLC 'make sure carry is 0 RL storedata 'shift left inc numstoredbits CJB numstoredbits,#8,@goback 'if numstoredbits < 8 then goback 'otherwise move storedata into sendme and tell main to send it to the pc MOV sendme,storedata 'sendme = storedata CLR numstoredbits 'numstoredbits = 0 CLR storedata 'storedata = 0 inc unhandledbytes 'isrready = 1 goback: CLRB rb.1 'for debugging MOV W, #156 '255-100 = 156 RETIW goidle: CLRB seenedge 'erase the edge we saw before CLR validhigh 'reset and start over CLRB RB.1 'for debugging MOV w,#188 '255-188=67 RETIW processedge: MODE $09 'clear pending edge MOV !RB,#0 MOV lastproc,myrtcc 'lastproc = myrtcc CLR RTCC 'sync to the edge! SETB seenedge 'we've now seen an edge! CLR validhigh SETB C 'make sure carry has a 1 to shift in RL storedata inc numstoredbits CJB numstoredbits,#8,@retfromedge 'if numstoredbits < 8 then retfromedge MOV sendme,storedata 'sendme = storedata CLR numstoredbits 'numstoredbits = 0 CLR storedata 'storedata = 0 inc unhandledbytes 'isrready = 1 retfromedge: CLRB RB.1 'for debugging MOV W,#155 'WAS 188, 150 = 2.68, 160 =2.54, 170=2.26 perfect RETIW ENDASM PROGRAM start_point ' Program Code ' ------------------------------------------------------------------------- start_point: 'setup port b TRIS_B=%11111001 'direction bits rb.0 input, rb.1 & rb.2 output ST_B = %11111110 'schmitt trigger for our drive input WKPND_B = 0 'clear pending interrupts WKED_B = %11111111 'set falling edge trigger WKEN_B = %11111110 'enable drive input interrupts PLP_B = %11111110 'enable pullups LVL_B = %00000000 'enable CMOS for port b 'setup port c TRIS_C=0 'enable port c for output PLP_C = %00000000 numstoredbits = 0 byteready = 0 seenedge = 0 pending = 0 validhigh = 0 storedata = 0 lastproc = 0 'xmitbytes = 128 ' turn on interrupts OPTION = $88 repeat: if unhandledbytes = 1 then xfernow if unhandledbytes = 2 then brcode if numstoredbits <> 4 then repeat 'if numstoredbits is not 4 byteready = 0 goto repeat xfernow: rb.1 = 1 'for debugging outputbyte = sendme 'put it on the port byteready = 1 'tell pc byte is ready dec unhandledbytes 'we have handled one more rb.1 = 0 'for debugging goto repeat brcode: BREAK goto goback