On Sunday 09 February 2003 01:50 am, you wrote: Comments interspersed with code > I am trying to read the temperature from a DS1620 and send this to a > PC using the serial port, I know the serial portion of the code works > I have already tested that. I am having trouble reading from the > DS1620 and I wondered if anyone had any ideas on what I am doing > wrong. Thanks. > > ;******************************************************************* > ;Temperature > ;******************************************************************* > > LIST P=3D16F628, R=3DDEC ; Use the PIC16F628 and decimal > system > > #include "P16F628.INC" ; Include header file > > __config _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & > _PWRTE_ON & _BODEN_ON > > CBLOCK 0x20 ; Declare variable addresses starting > at 0x20 > dataL > tempw > count > Delay_i > Long_Delay_i > tmp > ENDC > > #define DQ PORTB, 4 > #define CLK PORTB, 5 > #define RST PORTB, 6 > > ORG 0x000 ; Program starts at 0x000 > ; > ; -------------------------------- > ; SET ANALOG/DIGITAL INPUTS PORT A > ; -------------------------------- > ; > movlw 0x07 > movwf CMCON ; CMCON=3D7 set comperators off > ; > ; ---------------- > ; INITIALIZE PORTS > ; ---------------- > ; > movlw 0x0 ; 00000000 > movwf PORTA > > movlw 0x4 ; 00000100 > movwf PORTB > > bsf STATUS,RP0 ; RAM PAGE 1 > > movlw 0xFF > movwf TRISA ; 11111111 Are all the PORTA pins connected to something? =20 > movlw 0x12 ; 00010010 > movwf TRISB > > ; ------------------------------------ > ; SET BAUD RATE TO COMMUNICATE WITH PC > ; ------------------------------------ > ; Boot Baud Rate =3D 9600, No Parity, 1 Stop Bit > ; > movlw 0x19 ; 0x19=3D9600 bps (0x0C=3D19200 bps) > movwf SPBRG > movlw 0x24 ; brgh =3D high (2) > movwf TXSTA ; enable Async Transmission, set > brgh > > bcf STATUS,RP0 ; RAM PAGE 0 > > movlw 0x90 ; enable Async Reception > movwf RCSTA > ; > ; ------------------------------------ > ; PROVIDE A SETTLING TIME FOR START UP > ; ------------------------------------ > ; > bcf RST > clrf dataL > settle decfsz dataL,F > goto settle > > movf RCREG,W > movf RCREG,W > movf RCREG,W ; flush receive buffer > ; > ; --------- > ; MAIN LOOP > ; --------- > ; > loop > call receive ; wait for a char > > bsf RST > call Delay > movlw 0x0C > call sendDS > > movlw 0x03 > call sendDS > > movlw 0xEE > call sendDS > call Delay > > movlw 0xAA > call sendDS > call Delay > call receiveDS > bcf RST > call send > movlw 0x0D > call send > movlw 0x0A > call send > > > goto loop > > ; > ; ------------------------------------------- > ; RECEIVE CHARACTER FROM RS232 AND STORE IN W > ; ------------------------------------------- > ; This routine does not return until a character is received. > ; > receive btfss PIR1,RCIF ; (5) check for received data > goto receive > > movf RCREG,W ; save received data in W > return > ; > ; ------------------------------------------------------------- > ; SEND CHARACTER IN W VIA RS232 AND WAIT UNTIL FINISHED SENDING > ; ------------------------------------------------------------- > ; > send movwf TXREG ; send data in W > > TransWt bsf STATUS,RP0 ; RAM PAGE 1 > WtHere btfss TXSTA,TRMT ; (1) transmission is complete if > hi goto WtHere > > bcf STATUS,RP0 ; RAM PAGE 0 > return > ; > ; -------------- > ; SEND TO DS1620 > ; -------------- > ; > sendDS > movwf tempw > movlw 8 > movwf count > bsf STATUS,RP0 ;register page 1 > bcf DQ ; Set data for output. > bcf STATUS,RP0 ;register page 0 This is not cool at all. Though this may work to access the TRISB=20 register, it's not at all clear. > sendloop > bcf CLK > btfsc tempw, 0 > bsf DQ > btfss tempw, 0 > bcf DQ > rrf tempw, f > bsf CLK > decfsz count > goto sendloop > return > > ; > ; ------------------- > ; RECEIVE FROM DS1620 > ; ------------------- > ; > receiveDS > movlw 8 > movwf count > bsf STATUS,RP0 ;register page 1 > bsf DQ ; Set data for input. > bcf STATUS,RP0 ;register page 0 > receiveloop > bcf CLK > rlf tempw Shouldn't the above line be "rlf tempw, F"? It looks like you are=20 dropping all your received bits. IIRC, the default destination is W > btfsc DQ > bsf tempw, 0 > btfss DQ > bcf tempw, 0 > bsf CLK > decfsz count > goto receiveloop > movf tempw, w > return > > Delay > movlw 0xff > movwf Delay_i > L1 nop > decfsz Delay_i, f > goto L1 > return > > Long_Delay > movwf tmp > movlw 0xff > movwf Long_Delay_i > L2 call Delay > decfsz Long_Delay_i, f > goto L2 > movf tmp,w > return > > END michael -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body