; ------------------------------------------------------ ; serial.asm ; ; Serial routines for the progger project. Tx/Rx ; at 9600 bps, 8N1 ; ; (c) 2001 L. Hollevoet ; ------------------------------------------------------ ; Revision history: ; ------------------------------------------------------ ; $Log: serial.asm,v $ ; Revision 1.3 2002/01/10 13:47:27 hollevo ; Receive routine has been speed optimized ; ; Revision 1.2 2002/01/02 13:12:17 hollevo ; Changed comment ; ; Revision 1.1.1.1 2001/11/29 15:36:28 hollevo ; Initial import ; ; ------------------------------------------------------ ; ----- _dump_hex -------------------------------------------------- ; Dumps W in HEX to the serial port ; ------------------------------------------------------------------ _dump_hex movwf htemp swapf htemp, W andlw 0x0f sublw 0x09 btfss STATUS, C goto _d_h_big swapf htemp, W andlw 0x0f addlw 0x30 goto _d_h_send _d_h_big swapf htemp, W andlw 0x0f addlw 0x57 _d_h_send call _send movf htemp, W andlw 0x0f sublw 0x09 btfss STATUS, C goto _d_h_big1 movf htemp, W andlw 0x0f addlw 0x30 goto _d_h_send1 _d_h_big1 movf htemp, W andlw 0x0f addlw 0x57 _d_h_send1 call _send movlw ' ' call _send return ; ----- _get_hex --------------------------------------------------- ; Read 2 chars as hex value into register pointed to by W ; ------------------------------------------------------------------ _get_hex clrf RxChar movwf FSR _g_h_lp movf RxChar, F btfsc STATUS, Z goto _g_h_lp ; nog irq disablen tijdens deze routine call _conv_hex movwf INDF _get_hex2 movf RxChar, F btfsc STATUS, Z goto _get_hex2 swapf INDF, F andlw 0xF0 call _conv_hex addwf INDF, F return ; ----- _conv_hex -------------------------------------------------- ; Convert char in RxChar to hex in W, clear RxChar ; ------------------------------------------------------------------ _conv_hex movf RxChar, W sublw 0x40 btfss STATUS, C goto _c_h_big movf RxChar, W addlw 0xd0 goto _c_h_end _c_h_big movf RxChar, W andlw 0xDF ; Convert to uppercase addlw 0xC9 _c_h_end clrf RxChar return ; ----- _send_lf --------------------------------------------------- ; Send lf to host ; ------------------------------------------------------------------ _send_lf movlw 0x0d call _send movlw 0x0a call _send return ; ----- _recv ------------------------------------------------------ ; ; FUNCTION: Receives a byte and puts it in RxChar (9600, 8N1) ; ; USES: _serDelay ; ; FALLS INTO: _serDelay ; ------------------------------------------------------------------ _recv movlw 8 movwf rCounter call _serHalfDelay ; Check if we have still a start bit (avoid fake triggers ; due to glitches) btfsc PORTB, RxD return ;bcf flags, 0 ; Clear error flag ; We are now half the LSB of the byte _rloop call _serDelay btfsc PORTB, RxD goto _rstore1 bcf STATUS, C goto _rstoredone _rstore1 bsf STATUS, C _rstoredone rrf RxChar, F decfsz rCounter, F goto _rloop ;btfss PORTB, RxD ; Check for stop bit, if none... ;bsf flags, 0 ; .. set the error flag return ; ----- _send ------------------------------------------------------ ; ; FUNCTION: Transmits the byte that is in W register 9600, 8N1 ; ; USES: _serDelay ; ; FALLS INTO: _serDelay ; ---------------------------------- _send movwf TxChar movlw 8 movwf sCounter bcf PORTB, TxD ; send the startbit call _serDelay ; delay _loop bcf STATUS, C rrf TxChar, F btfss STATUS, C goto _zendNul bsf PORTB, TxD goto _wait _zendNul bcf PORTB, TxD _wait call _serDelay decfsz sCounter, F goto _loop _eos bsf PORTB, TxD ; send the stopbit ; hier geen return, er is nog een senddelay nodig voor stopbit ! ; --------------------- ; Serial send delay ; --------------------- _serDelay movlw serDelay movwf sDelayReg _serlus decfsz sDelayReg, F goto _serlus return ; --------------------- ; Serial half delay ; --------------------- _serHalfDelay movlw serHalfDelay movwf rDelayReg _serHlus decfsz rDelayReg, F goto _serHlus return ; --------------------- ; 10 ms delay ; --------------------- _delay_10m movlw d'100' movwf dly10cntr _dly10_lp call _serDelay decfsz dly10cntr, F goto _dly10_lp return