From 2917ec4990958da6e4c5a5016132fe90a26c938b Mon Sep 17 00:00:00 2001 From: Werner Johansson Date: Sun, 9 Mar 2003 07:40:52 -0800 Subject: [PATCH] v0.6 - Some more LCD info and clean-up of the Unilink recovery code, some problems with master resetting :( Signed-off-by: Werner Johansson --- wj-uni.asm | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 184 insertions(+), 17 deletions(-) diff --git a/wj-uni.asm b/wj-uni.asm index 08ddc24..c6e4840 100644 --- a/wj-uni.asm +++ b/wj-uni.asm @@ -12,19 +12,21 @@ ;---------------------------------------------------------------- ; TODO ;---------------------------------------------------------------- -; Fix the DelayW routine so it actually delays W/10 ms... ; No checksum checking is done on incoming packets -; Investigate whether I actually have to save PCLATH in ISH, maybe save FSR? +; Investigate whether I actually have to save PCLATH in ISH, maybe save FSR? - Not saving any of them for now ; Move RS232 code into ISH ; Check Overrun errors from the UART ; Implement lots of other Unilink commands (Text display, time display etc.) ; Implement the Watchdog Timer (might be useful even though I haven't seen it hang yet..) +; Make the bit shift routine at the beginning of the ISR timeout if the clock suddenly stops (in the middle of a byte) +; (will keep it from hanging until the next bit gets clocked out, just ignore the faulty bits and carry on) ;---------------------------------------------------------------- ; HISTORY ;---------------------------------------------------------------- ; Version ; +; 0.6 Some more LCD info and clean-up of the Unilink recovery code, some problems with master resetting :( ; 0.5 Issues slave breaks seemingly without hickups (!) ; 0.4 Some fixups in the bootstrap code (I actually had to put the PIC in my PICSTART Plus programmer again :)) ; 0.3 Implementing more Unilink commands and RingIndicator control (to wake the computer from sleep) @@ -157,7 +159,8 @@ e_LEN equ 6fh Counter equ 70h DataCount equ 71h ; Temp storage for the bit counter used during bit shifts (Unilink TX/RX) DataStore equ 72h ; This is a kludge - +DisplayCounter equ 73h +UnilinkAttenuation equ 74h ; The amount of attenuation the volume control is currently set to IRQPCLATH equ 7dh ; ISH storage IRQSTATUS equ 7eh ; Needs to be located in a shared area accessible from all register banks IRQW equ 7fh ; @@ -626,6 +629,26 @@ IRQINTParse87PowerOn IRQINTParseNot87 +; Check for CMD1 = 90h (Display/DSP info, volume etc.) + movf UnilinkCMD1,w + xorlw 090h + bnz IRQINTParseNot90 + +; Check for 90 10 (Current Volume) + movf UnilinkCMD2,w + xorlw 010h + bnz IRQINTParseNot9010 + + movf UnilinkData1,w ; Store current volume setting + movwf UnilinkAttenuation + + goto IRQINTParseComplete ; Don't send any reply to this (clear the packet buffer though) + +IRQINTParseNot9010 + + +IRQINTParseNot90 + ; Check for CMD1 = f0h (Source Select) movf UnilinkCMD1,w xorlw 0f0h @@ -676,14 +699,14 @@ IRQNotINT btfss PIR1,TMR2IF ; Check if it's the TMR2 interrupt (0.5ms timing) goto IRQNotTMR2 ; No it's not, check the other sources + incf Counter,f ; Increment the general purpose counter (increments every 0.5ms) + ; Slave break opportunity detection here - the logic works as follows: ; Look for a data low period of at least 5 ms (10 loops) ; Look for a data high period of at least 2 ms (4 loops) ; If the Slave Break request bit has been set, issue a slave break by holding the data line low for 4ms (8 loops) ; If a bit would be received (CLK activates) the packet handler automatically clears out the SlaveBreakState, which means start all over -; incf Counter,f ; Increment the general purpose counter - btfsc SlaveBreakState,5 ; Check if already pulling the data line low goto IRQTMR2SlaveBreak @@ -721,7 +744,7 @@ IRQTMR2LowDataOK clrf SlaveBreakState - incf Counter,f +; incf Counter,f btfss DisplayStatus,7 ; Only do this if high bit is set goto IRQAfterTMR2 @@ -827,11 +850,25 @@ ClearUnilinkBuffer ; Here all other house keeping tasks are performed, like displaying info on the LCD.. Main - movlw high LookUp + movlw high LookUp ; Set the high PC bits to indicate data lookup page movwf PCLATH - movlw low StartUpText1 ; Show something on the LCD - call TxLCD16B + movlw 0ffh + movwf UnilinkAttenuation + + movlw 8 ; Display page timing (approx 8/sec) + movwf DisplayCounter + + bcf LCD_RS_BIT ; LCD Command mode + movlw 80h ; DisplayRam 0 + call TxLCDB + bsf LCD_RS_BIT + + movlw low DefaultText1 + movwf Icount + movlw 80 + movwf e_LEN + call TxLCD8BLoop ; Send 80 bytes to the LCD MainLoop @@ -870,6 +907,84 @@ MainLoop MainDontPrintCmd +; Default text (see data declarations for actual text) +; UnilinkID @ 11-12 +; UnilinkAttenuation @ 16-17 +; UnilinkSelected @ 53-54 +; DisplayStatus @ 62-63 + + bcf LCD_RS_BIT ; LCD Command mode + movlw 80h+11 ; DisplayRam 11 + call TxLCDB + bsf LCD_RS_BIT + + movf UnilinkID,w + call TxLCDHEX + + bcf LCD_RS_BIT ; LCD Command mode + movlw 80h+16 ; DisplayRam 16 + call TxLCDB + bsf LCD_RS_BIT + + movf UnilinkAttenuation,w + call TxLCDHEX + + bcf LCD_RS_BIT ; LCD Command mode + movlw 80h+40h+13 ; DisplayRam 53 + call TxLCDB + bsf LCD_RS_BIT + + movf UnilinkSelected,w + call TxLCDHEX + + bcf LCD_RS_BIT ; LCD Command mode + movlw 80h+40h+22 ; DisplayRam 62 + call TxLCDB + bsf LCD_RS_BIT + + movf DisplayStatus,w + call TxLCDHEX + +; This part handles display "scroll" by shifting one screen at a time + + btfss Counter,7 ; Test high bit + goto MainCounterLow + +; So bit is high, set high bit of displaycounter as well... + bsf DisplayCounter,7 + goto MainSkipScroll + +MainCounterLow +; OK, bit is low, now figure out whether it was high or low last time -> check high bit of DisplayCounter + btfss DisplayCounter,7 + goto MainSkipScroll + + bcf DisplayCounter,7 ; Clear the high bit to allow countdown to commence + movf Counter,w ; Load it + skpz + goto MainSkipScroll + decfsz DisplayCounter,f + goto MainSkipScroll + + movlw 8 + movwf DisplayCounter + + bcf LCD_RS_BIT ; LCD Command mode + movlw 18h ; Display shift Left + call TxLCDB ; Shift it 8 positions + call TxLCDB + call TxLCDB + call TxLCDB + call TxLCDB + call TxLCDB + call TxLCDB + call TxLCDB + bsf LCD_RS_BIT + +MainSkipScroll + +; Display scroll part ends here... + movf DataCount,w ; Load bit counter (if 0 then byte is available) skpz goto MainLoop @@ -1001,10 +1116,48 @@ LCDInit movlw 06h ; Auto Increment cursor position call TxLCDB - + + bsf LCD_RS_BIT ; Accept data + return ;---------------------------------------------------------------- +; TxLCDHEX +; Sends two characters hex to the LCD + +TxLCDHEX + +; Original binary to 2-digit hex conversion from piclist.com, modified to fit here + + movwf Icount + swapf Icount,w + andlw 0x0f + + addlw 6 + skpndc + addlw 'A'-('9'+1) + addlw '0'-6 + + xorwf Icount,w + xorwf Icount,f + xorwf Icount,w + + andlw 0x0f + + addlw 6 + skpndc + addlw 'A'-('9'+1) + addlw '0'-6 + + movwf e_LEN + movf Icount,w + call TxLCDB + movf e_LEN,w + call TxLCDB + + return + +;---------------------------------------------------------------- ; TxLCD16B ; Send a string to the LCD. @@ -1031,12 +1184,13 @@ TxLCD8B movlw 8 movwf e_LEN ; Move to e_LEN -Txm_lp movf Icount,w ; get the byte +TxLCD8BLoop + movf Icount,w ; get the byte call LookUp incf Icount,f ; ...else ++Icount (table index) call TxLCDB ; Send out the byte decfsz e_LEN,f - goto Txm_lp + goto TxLCD8BLoop return ;---------------------------------------------------------------- @@ -1067,6 +1221,7 @@ NotReady call TxLCD ; And send that one as well return + ;---------------------------------------------------------------- ; RxLCDB - recv a byte from the LCD @@ -1167,11 +1322,18 @@ DelayInner ; Data can be stored between 600 and 6ffh... org 600h -StartUpText1 - DT "----- WJ UniLink" -InfoText1 - DT "WJ UniLink " +; Default text +; UnilinkID @ 11-12 +; UnilinkAttenuation @ 16-17 +; UnilinkSelected @ 53-54 +; DisplayStatus @ 62-63 + +DefaultText1 + DT "----- WJ", "ID:xx Se", "xx dB at", "LCDPage3", "LCDPage4" + DT " Unilink", "lect:xx ", "t Dsp:xx", " Right 3", " Right 4" + + LookUp movwf PCL ; Go to it (this assumes PCLATH == 06h) @@ -1218,7 +1380,8 @@ Bootstrap movlw low BootStartText ; Send boot banner to the serial port call BootTXStr - movlw 0e8h ; Initialize timeout timer +; movlw 0e8h ; Initialize timeout timer (e8 is about 3 secs) + movlw 0fdh ; Initialize timeout timer (e8 is about 3 secs) movwf BootTimerL movwf BootTimerM movwf BootTimerH @@ -1391,10 +1554,14 @@ BootRXW1 BootRXHEXNibble call BootRXB ; Receive nibble + +; This code is from piclist.com, really neat! + addlw -'A' ; Convert from BCD to binary nibble skpc ; Test if if was 0-9 or A-F, skip if A-F addlw 'A' - 10 - '0' ; It was numeric '0' addlw 10 ; Add 10 (A get to be 0ah etc.) + return ;---------------------------------------------------------------------- -- 1.7.3