PDA

View Full Version : Serin with 16F876



RuudNL
- 18th January 2021, 18:15
I am trying to read the serial (RS232) input on LEDs, connected to PORTB of the 16F876.
(Later this will be part of a larger application, I need both PORTB and PORTC as outputs.)
I am using an FTDI USB cable for the serial input.
I can see on an oscilloscope that serial information is indeed generated, but no display on the LEDs.
Probably I am overlooking something obvious(!), but I even can't get this simple test setup working.
I am sending 8 bits, no parity, 9600 Baud.
This is the code I am testing:



'* * * * * * * * * * * * * * * * * * * * * * * *
'* PORTA.0 = Serial input
'* PORTB = Outputs to LEDs + 1 K.ohm resitors
'* /MCRL to +5 V through 4.7 K.ohm resistor
'* Oscillator 20 MHz.
'* 16F876
'* * * * * * * * * * * * * * * * * * * * * * * *

TRISA= %00000001 ' PORTA.0 = Input
TRISB= %00000000 ' PORTB = Outputs
ADCON1=7 ' Digital mode
DEFINE OSC 20 ' 20 MHZ OSC.

Value var byte ' Value from port

PORTB = 0 ' Start with all LEDs off

again:
Serin PORTA.0, 6, Value ' 9600 Baud, inverted
' Serin PORTA.0, 2, Value ' 9600 Baud, normal
PORTB = Value
goto again


Where do I go wrong?
(Just to check, I tried 'normal' and 'inverted' mode.)

richard
- 19th January 2021, 10:34
its all guesswork with no config word setting offered;

it's more than likely the osc won't function reliably @20mhz with the default pbp xt osc config

can you even flash a led ?

RuudNL
- 19th January 2021, 12:05
No idea what was wrong, but now it works.
(It may have been the FTDI USB to serial cable.)