Ok, Ive made a really basic version to save you looking through hundreds of lines of code. It uses the power LED to show the output (inverted) and the status LED to show the value sent by serial. My laptop sends 1 and 0 alternately.
In this example grounding the input pin makes the power LED light up as expected. When i send the alternating serial values then the status LED toggles as it should. When ground the input _and_ send serial data then the status light never comes on. Something i didnt notice before is that if the status light is already on then grounding the input turns it off. That would suggest that the grounding causes a blank byte to appear in the UART buffer.Code:'^Define_Chip: PIC16F87 'Define the oscillator (20MHz) DEFINE OSC 20 'Set the tris registers TRISA=%00001000 TRISB=%11000101 CMCON=7 CVRCON=0 CCP1CON=0 'Serial port settings RCSTA.7=1 'Enable the serial port RCSTA.4=1 'Enable synchronous mode TXSTA.5=1 'Enable transmit TXSTA.2=1 'Enable high baud rate 'SPBRG=10 'Baud: 115200, Error: -1.36% SPBRG=64 'Baud: 19200, Error: 0.16% bTemp VAR BYTE 'Define output pins pSmoke1 VAR PORTA.2 pSmoke2 VAR PORTA.4 pSmoke3 VAR PORTB.1 pSmoke4 VAR PORTB.3 pPower VAR PORTA.0 pStatus VAR PORTA.1 pData VAR PORTB.4 'Switches between Master and Slave 'Define input pins iSmoke1 VAR PORTA.3 iSmoke2 VAR PORTB.0 iSmoke3 VAR PORTB.7 iSmoke4 VAR PORTB.6 'Check that input pins are set to inputs INPUT iSmoke1 INPUT iSmoke2 INPUT iSmoke3 INPUT iSmoke4 'Make sure all of the outputs are off LOW pSmoke1 LOW pSmoke2 LOW pSmoke3 LOW pSmoke4 LOW pPower LOW pStatus LOW pData 'BEGIN: Main loop loop: 'Check if serial data has arrived IF PIR1.5=1 THEN bTemp=RCREG pStatus=bTemp.0 ENDIF pPower=~iSmoke4 GOTO loop




Bookmarks