;************Equates
; *** Port B Declaration
ser_port equ PORTB
ser_out equ 0x06 ;Bank Select Issue
cs equ 0x03 ;ADC handshake lines
dataout equ 0x04
clk equ 0x05
; *** Port A Declaration
ser_port2 equ PORTA
ser_out2 equ 0x01
;***********************Program
org 0x0000
clrf PORTA
clrf PORTB
call main
main
call initialise
loop
call adc_value
movf adc_buffer,w ; store the ADC value into register
call Xmit_rs232 ; to transmit serial interface
goto loop
;******************* Initialise Routine
initialise
bsf STATUS,RP0 ;select bank 1
movlw b'01111000' ;set PORTA
movwf TRISA
movlw b'00010000' ;set portB
movwf TRISB
bcf STATUS,RP0 ;select bank 0
bsf PORTB,ser_out ;make B6 High
bsf PORTA,ser_out2
return
;****************** ADC Routine
adc_value
bcf PORTB,cs
clrf adc_buffer
movlw d'8'
movwf adc_count
loop2
btfsc PORTB,dataout
bsf STATUS,C
btfss PORTB,dataout
bcf STATUS,C
bsf PORTB,clk ;clock high
NOP
bcf PORTB,clk ;clock low
rlf adc_buffer,f
decfsz adc_count,f
goto loop2
bsf PORTB,cs
return
;**************** ADC Routine End
;************ RS 232(2) Transmit
Xmit_rs232
movwf Xmit_Byte ;move W to Xmit_Byte
movlw 0x08 set 8 bits out / bit_cntr is loaded
movwf Bit_Cntr
bcf ser_port2,ser_out2
call bit_delay
ser_loop2
rrf Xmit_Byte , f ;send one bit
btfss STATUS , C
bcf ser_port2,ser_out2
btfsc STATUS,C
bsf ser_port2,ser_out2
call bit_delay
decfsz Bit_Cntr,f ;test if all done
goto ser_loop2
bsf ser_port2,ser_out2 ;SEND STOP BIT
call bit_delay
return
bit_delay
movlw 0x18
movwf Delay_Count
bit_wait
nop
decfsz Delay_Count , f
goto bit_wait
return
end