I'm having trouble with a PIC16F883. It seems as if I'm losing information.
The PIC is connected to an ancient Pentium 1 laptop via the parallel port. I use 4 bits to write to the status register of the pp (&379). This works fine.
The problem arise on the second nibble that's needs to be sent. At this time it seems as if my storage has been cleared.
I load a register (called dataByte - in the H'70' space - available to all pages) with a byte. I then move this data to another byte (sndDataBt - also in the H'70' space) for swapping.
The byte is then sent in 2 parts to PORTC(4-7), each time indicating ready and waiting for signal from pc that it's ready/complete.
Code:
.
.
.
MOVLW B'11111111'
MOVWF dataByte
CALL SEND_BYTE
SEND_BYTE
BTFSC SNDSTRT ;Part of reset procedure... ignore
RETURN
MOVF dataByte,W ;Read the data to be sent into W
MOVWF sndDataBt ;Store in another place.
SWAPF sndDataBt,F ;Swap nibbles
BANKSEL PORTC
MOVLW B'00001111' ;Clear upper 4 bits of PORTC, but leave
ANDWF PORTC,F ;lower 4 bits unchanged.
MOVLW B'11110000' ;Read upper 4 bits of data into W,
ANDWF sndDataBt,W ;ignoring lower 4 bits.
IORWF PORTC,F ;Set PORTC(4-7) = MSB nibble of data
;(actually LSB, swapf'd)
BCF SREDY ;Set ready to send data indicator. (change in value
;indicates setting...)
BTFSS SNDD ;Wait for PC to set indicator
GOTO $-1
;MOVLW B'11111111' ;Testing attempt to force all high
;MOVWF dataByte ;
MOVLW B'00001111' ;Clear PORTC(4-7)
ANDWF PORTC,F ;
MOVLW B'11110000' ;
ANDWF dataByte,W ;Read MSB nibble from data (should be unchanged,
IORWF PORTC,F ;but at this point it's cleared)
BSF SREDY ;Set ready to send data indicator
RETURN ;All data sent.
Tests I have done:
The code above sets all the bits in dataByte to 1 - I expect that on the pc. For some reason I recieve zeroes in the MSB (second) nibble.
When I set all the bits again - in the commented out code - I do get all the one's. Somewhere along the line the dataByte register seem to have been cleared and I have been pulling out my hair trying to find put how.
I have tested each bit of dataByte seperately and setting the bits of PORTC - not worked.
I have slapped in NOP's, thinking that maybe transmission is faster than the pp can handle - not worked.
I have changed my chip...
Any help/suggtestions are highly appreciated.
Running at 20MHz, using crystal.
PORTC is buffered via LM324 to parallel port.
PORTC,1 is used as PWM
PORTC,2 is used as input for testing - to hold a status for manual continue
PORTC,3 is output indicator to pp
Thanks.
Rinus.
The PIC is connected to an ancient Pentium 1 laptop via the parallel port. I use 4 bits to write to the status register of the pp (&379). This works fine.
The problem arise on the second nibble that's needs to be sent. At this time it seems as if my storage has been cleared.
I load a register (called dataByte - in the H'70' space - available to all pages) with a byte. I then move this data to another byte (sndDataBt - also in the H'70' space) for swapping.
The byte is then sent in 2 parts to PORTC(4-7), each time indicating ready and waiting for signal from pc that it's ready/complete.
Code:
.
.
.
MOVLW B'11111111'
MOVWF dataByte
CALL SEND_BYTE
SEND_BYTE
BTFSC SNDSTRT ;Part of reset procedure... ignore
RETURN
MOVF dataByte,W ;Read the data to be sent into W
MOVWF sndDataBt ;Store in another place.
SWAPF sndDataBt,F ;Swap nibbles
BANKSEL PORTC
MOVLW B'00001111' ;Clear upper 4 bits of PORTC, but leave
ANDWF PORTC,F ;lower 4 bits unchanged.
MOVLW B'11110000' ;Read upper 4 bits of data into W,
ANDWF sndDataBt,W ;ignoring lower 4 bits.
IORWF PORTC,F ;Set PORTC(4-7) = MSB nibble of data
;(actually LSB, swapf'd)
BCF SREDY ;Set ready to send data indicator. (change in value
;indicates setting...)
BTFSS SNDD ;Wait for PC to set indicator
GOTO $-1
;MOVLW B'11111111' ;Testing attempt to force all high
;MOVWF dataByte ;
MOVLW B'00001111' ;Clear PORTC(4-7)
ANDWF PORTC,F ;
MOVLW B'11110000' ;
ANDWF dataByte,W ;Read MSB nibble from data (should be unchanged,
IORWF PORTC,F ;but at this point it's cleared)
BSF SREDY ;Set ready to send data indicator
RETURN ;All data sent.
Tests I have done:
The code above sets all the bits in dataByte to 1 - I expect that on the pc. For some reason I recieve zeroes in the MSB (second) nibble.
When I set all the bits again - in the commented out code - I do get all the one's. Somewhere along the line the dataByte register seem to have been cleared and I have been pulling out my hair trying to find put how.
I have tested each bit of dataByte seperately and setting the bits of PORTC - not worked.
I have slapped in NOP's, thinking that maybe transmission is faster than the pp can handle - not worked.
I have changed my chip...
Any help/suggtestions are highly appreciated.
Running at 20MHz, using crystal.
PORTC is buffered via LM324 to parallel port.
PORTC,1 is used as PWM
PORTC,2 is used as input for testing - to hold a status for manual continue
PORTC,3 is output indicator to pp
Thanks.
Rinus.