;**********************************************************************
; *
; Filename: serial.asm *
; Date: *
; File Version: *
; *
; Author: Burt E Ratliff *
; Company: *
; *
; *
;**********************************************************************
; *
; Files Required: P12F508.INC *
; *
;**********************************************************************
; *
; Notes: *
; *
;**********************************************************************
list p=12F508 ; list directive to define processor
#include <p12F508.inc> ; processor specific variable definitions
__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC
; pin assignments
#define RX GPIO,0 ; transmit pin on GP0
;***** VARIABLE DEFINITIONS
UDATA
buffer res 1
counter res 1
Count res 1
RXdata res 1
datarecved res 1
test_byte res 1
;**********************************************************************
; Internal RC calibration value is placed at location 0x1FF by Microchip
; as a movlw k, where the k is a literal value.
RESET CODE 0x000 ; effective reset vector
movwf OSCCAL ; update OSCCAL with factory cal value
goto init ; jump to main program
init
movlw b'00000001' ; set I/O
tris GPIO
Start call Rcv_RS232 ; gets the data from the rx pin
call LED ; If we get data then lets turn on a led
goto Start ;No data come back and keep looking
LED
movlw 0x31 ; loads test_byte wit hex 31
movwf test_byte
movf test_byte,W ; moves to W
subwf datarecved,W ; this should have 0x31
btfss STATUS,Z ; if this is 0
goto Led_on ; led is on if 0
goto Led_off ; led is off if 1
Led_on
bsf GPIO,5
return ; returns to start to loop for new data
Led_off
bcf GPIO,5
return
Rcv_RS232 BTFSC RX ;wait for start bit
GOTO Rcv_RS232
CALL Start_Delay ;do half bit time delay
BTFSC RX ;check still in start bit
GOTO Rcv_RS232
MOVLW 0x08 ;set up to read 8 bits
MOVWF counter
CLRF RXdata
Next_RcvBit CALL Bit_Delay
BTFSS RX
BCF STATUS , C
BTFSC RX
BSF STATUS , C
RRF RXdata , f
DECFSZ counter , f ;test if all done
GOTO RXdata
CALL Bit_Delay
MOVF datarecved, W
return
Start_Delay MOVLW 0x0C
MOVWF Count
Start_Wait NOP
DECFSZ Count , f
GOTO Start_Wait
RETURN
Bit_Delay MOVLW 0x18
MOVWF Count
Bit_Wait NOP
DECFSZ Count , f
GOTO Bit_Wait
RETURN
;End of serial routines
end