Monkeyman87
New Member
I have a really strange thing going on with my project. My project is an accelerometer that is interfaced with a PIC MCU which sends data to my PC. My problem is this: The PIC sends data values to the PC starting with decimal 255. From then on it sends a lesser value or greater value corresponding to the acceleration. Less is 255 and under and greater is 0 and greater. It is supposed to send a decimal value 127 corresponding to 0 g acceleration and send a greater or lesser value corresponding to greater or lesser acceleration since o g is 2.5v and the a/d is set to use vdd ref. This program worked great originally, then I modified a few things - changed the delay interval and added a collect/stop collect switch on gpio 2. I have included the code below and I would appreciate it if someone could tell me where I made a mistake. I have gone over the code again and again and I can't find the problem. Sorry, the code didn't wrap very well.
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Accelerometer Project Code ;;
;; By: Sam Bixler ;;
;; Date: 9-02-04 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
INCLUDE "P12F675.INC"
__CONFIG 0X3184
cblock 0x20
Xmit_Byte ;holds byte to xmit
Rcv_Byte ;holds received byte
Bit_Cntr ;bit counter for RS232
Delay_Count ;delay loop counter
D1 ;another delay loop counter
D2 ;another delay loop counter
endc
ORG 0X00
START MOVLW 0X07 ;TURN OFF COMPARATOR
MOVWF CMCON
CLRF GPIO
BSF STATUS, RP0 ;BANK 1
MOVLW B'00010010' MOVWF ANSEL ;ANALOG INPUT ON GPIO, 1 , SET FOSC
MOVLW B'11111110'
MOVWF TRISIO ;GPIO, 0 IS OUTPUT FOR SERIAL TX
BCF STATUS, RP0 ;BANK 2
MOVLW B'00000101'
MOVWF ADCON0 ;TURN ON A/D, SELECT CHANNEL 1
BSF GPIO, 0 ;MARK STATE TX
MAIN BTFSS GPIO, 2
;CHECK IF READY TO START DATA AQUISITION AND SEND
GOTO MAIN
BSF ADCON0, GO ;START CONVERSION
ADTEST BTFSS PIR1, ADIF
GOTO ADTEST
BCF PIR1, ADIF
CALL Delay MOVF ADRESH, W;MOVE THE MSBs OF A/D TO W
CALL XMIT_RS232 ;TX DATA TO PC
GOTO MAIN ;DO IT AGAIN
;Serial routines
XMIT_RS232 MOVWF Xmit_Byte ;MOVE W TO Xmit_Byte
MOVLW 0x08 ;SET 8 BITS OUT
MOVWF Bit_Cntr
BCF GPIO, 0
CALL Bit_Delay
Ser_Loop RRF Xmit_Byte , f ;SEND ONE BIT
BTFSS STATUS , C
BCF GPIO, 0
BTFSC STATUS , C
BSF GPIO, 0
CALL Bit_Delay
DECFSZ Bit_Cntr , f ;TEST IF ALL DONE
GOTO Ser_Loop
BSF GPIO, 0
CALL Bit_Delay
CLRF Xmit_Byte
RETURN
Start_Delay MOVLW 0x0C
MOVWF Delay_Count
Start_Wait NOP
DECFSZ Delay_Count , f
GOTO Start_Wait
RETURN
Bit_Delay MOVLW 0x18
MOVWF Delay_Count
Bit_Wait NOP
DECFSZ Delay_Count , f
GOTO Bit_Wait
RETURN
; Time Delay = 0.0500030s Osc = 4 MHz
Delay
movlw d'65'
movwf D1
movlw d'238'
movwf D2
loop decfsz D2, f
goto loop
decfsz D1, f
goto loop
return
RETLW 0X00
END