i'm really trying hard to understand , have to forgive me.. sorry..
currently i'm trasmitting the 4 ascii data bytes and 2 for CRLF but from the calculation it seems that the more character i send, the less accurate my sampling data getting lesser.
anyway this is my current coding which can work to trasmit the converted ADC values into ASC11 and display in hyperterminal. the only thing is that a few modifications have to be made so that i can send up to 5k hertz waveform and i kinda lost.
list p=pic16f877, f=inhx8m
include <P16F877.INC>
__config _CP_OFF & _PWRTE_ON & _XT_OSC & _WDT_OFF & _BODEN_OFF & _LVP_OFF
ERRORLEVEL -302 ;Suppress bank warning
cblock h'20'
thirty
delaytime
digit0
digit1
digit2
digit3
resultlbyte
resulthbyte
count
temp
H_byte
L_byte
R0 ; RAM Assignments
R1
R2
endc
org 0x000
goto start
int org 0x004
goto int
start
call initial
CALL INITUSART
again
call delay
call startconv
call check
call result
call B2_BCD
call bcdsplit
call send
goto again
initial
MOVLW h'30'
MOVWF thirty
BCF STATUS,RP1
BSF STATUS,RP0
MOVLW b'00000001'
MOVWF TRISA
MOVLW b'00000000'
MOVWF TRISB
MOVLW b'00000000'
MOVWF TRISD
MOVLW b'10001110'
MOVWF ADCON1
BCF STATUS,RP1
BCF STATUS,RP0
MOVLW b'01000001'
MOVWF ADCON0
RETURN
INITUSART:
BSF STATUS,RP0
BCF TRISC,6 ; make rc6 an output
BSF TRISC,7 ; make rc7 as input
MOVLW .25 ; 9600,n,8,1
MOVWF SPBRG
BSF TXSTA,TXEN ; enable transmit
BSF TXSTA,BRGH ; select high baud rate
BCF STATUS,RP0
BSF RCSTA,SPEN ; enable serial port
BSF RCSTA,CREN ; enable continuous reception
BCF PIR1,RCIF ; clear rcif interrupt flag
BSF STATUS,RP0
MOVLW b'00000000'
MOVWF TRISB
BCF STATUS,RP0
RETURN
delay
MOVLW h'07'
MOVWF delaytime
run
DECFSZ delaytime,f ; 21micro second
goto run
startconv
BSF ADCON0,GO
RETURN
check
BTFSS PIR1,ADIF
goto check
; MOVLW b'00000001'
; MOVWF PORTC
BCF PIR1,ADIF
return
result
BCF STATUS,RP1
BSF STATUS,RP0
MOVF ADRESL,W
BCF STATUS,RP0
movwf PORTB
movwf L_byte
BCF STATUS,RP1
BCF STATUS,RP0
MOVF ADRESH,W
MOVWF PORTD
movwf H_byte
RETURN
B2_BCD
bcf STATUS,0 ; clear the carry bit
movlw .16
movwf count
clrf R0
clrf R1
clrf R2
loop16 rlf L_byte, f
rlf H_byte, f
rlf R2, f
rlf R1, f
rlf R0, f
;
decfsz count, f ; routine for bcd conversion
goto adjDEC
retlw 0
;
adjDEC movlw R2
movwf FSR
call adjBCD ; no bank switching, always
; ; indirect access for RAM
movlw R1
movwf FSR
call adjBCD
;
movlw R0
movwf FSR
call adjBCD
;
goto loop16
;
adjBCD movlw 3
addwf 0,W
movwf temp
btfsc temp,3 ; test if result > 7
movwf INDF
movlw 30
addwf 0,W
movwf temp
btfsc temp,7 ; test if result > 7
movwf INDF ; save as MSD
retlw 0
bcdsplit
movf R1,w ; bring the second digit!
andlw 0F0h ; mask the lower nibble.
movwf digit0 ; send to display routine variable.
swapf digit0,f ; after swaping!
movf R1,w ; bring first nibble
andlw 0Fh ; mask the upper nibble
movwf digit1 ; send to display routine variable.
movf R2,w ; bring the second digit!
andlw 0F0h ; mask the lower nibble.
movwf digit2 ; send to display routine variable.
swapf digit2,f ; after swaping!
movf R2,w ; Again bring the lowbyte
andlw 0Fh ; mask the upper nibble
movwf digit3 ; send it to display routine variable
return
send
MOVFW thirty
ADDWF digit0,w
CALL TXRDY
MOVFW thirty
ADDWF digit1,w
CALL TXRDY
MOVFW thirty
ADDWF digit2,w
CALL TXRDY
MOVFW thirty
ADDWF digit3,w
CALL TXRDY
MOVLW .13 ;crlf
CALL TXRDY
; MOVLW .10
; CALL TXRDY
TXRDY:
BTFSS PIR1,TXIF
GOTO TXRDY;busy,so loop
XMIT1:
MOVWF TXREG;send
RETURN
END