'PIC16c84 Serial Data'
Is it possible to get the PIC16c84 to output serial data directly?
I've been trying it, and it seems to send out the 20 higher than the ASCII
character I send, but that isn't consistant. I've tried the Parallax,
and Microchip source.
I have TX connected to a pin on port A, and i've tried -5v on all of the
pins (It doesn't send anything without it). I have it hooked up to a dumb
terminal, and all of the settings are correct. Does anybody have any
ideas what's wrong, or any working tested source for the PIC16c84?
id John Philip Bodger
Philip, you wrote:-
> Is it possible to get the PIC16c84 to output serial data directly?
>I've been trying it, and it seems to send out the 20 higher than the ASCII
>character I send, but that isn't consistant. I've tried the Parallax,
>and Microchip source.
>I have TX connected to a pin on port A, and i've tried -5v on all of the
>pins (It doesn't send anything without it). I have it hooked up to a dumb
>terminal, and all of the settings are correct. Does anybody have any
>ideas what's wrong, or any working tested source for the PIC16c84?
Check this out, it's taken directly from a working program. It's written for
Parallax's PASMX compiler. Sorry I don't have it in standard Mchip code but
it might give you an idea of where you're going wrong. I don't use a
negative power source and it works just fine connecting to an ordinary PC
clone via 2 meters of cable.
Also, remember that RA.4 is an open collector output and won't work properly
without some external support components.
All the best.
;Serial RS232 via a 22K input resistor routines.
;Can freely use volatile registers: TempC, TempD, TempE, HexDec, R0;
;as this all runs with interrupts disabled.
SerialTest call SavePorts
setb RP0 ;Select Page 1
mov !RB,#11111101b ;all but RB.1 are inputs
clrb RP0 ;Select Page 0
clrb SerOut ;'MARK' RS232 logic 1 = -0v.
:test jb SerIn,:skip ;if input high then RS232 not connected.
call RXbyte ;get command letter into TempE.
cjne TempE,#'T',:rx ;Should we transmit config values ?
call RXbyte ;get address of byte to transmit
mov FSR,TempE ;address of indirect source in RAM
mov TempE,INDIRECT ;load TempE with the byte to send
call TXbyte ;transmit one byte
:rx cjne TempE,#'R',:test ;Should we receive new config values ?
call RXbyte ;get address of byte to receive
mov FSR,TempE ;save address
call RXbyte ;receive one byte of data
mov INDIRECT,TempE ;store the received byte in RAM
setb KeyFlag.Config ;indicate EEPROM needs updating.
:skip clrb Options.Lockout ;Clear Lockout indicator normally.
sb LockInput ;if input high then not locked out.
setb Options.Lockout ;if input low then indicate lockout.
;Receive a single byte into TempE.
RXbyte jnb SerIn,RXbyte ;Detect start bit = +5v.
call HalfBitDelay ;wait half a bit.
jnb SerIn,RXbyte ;if start bit bad, go back and wait.
mov TempD,#8 ;Set counter to receive 8 bits.
clr TempE ;Clear received byte to get ready for new one.
:rxbit call BitDelay ;wait one bit time.
movb C,/SerIn ;put inverted bit into carry.
rr TempE ;rotate bit in Carry into receive byte.
djnz TempD,:rxbit ;keep going for 8 bits.
call BitDelay ;position into middle of stop bit.
ret ;return with byte in TempE.
;Transmit a single byte from TempE.
TXbyte mov TempD,#8 ;Eight bits in the byte
call BitDelay ;send start bit = +ve voltage.
:txbit rr TempE ;rotate bits right into carry, 0 first.
movb SerOut,/C ;output inverted bit
djnz TempD,:txbit ;round the loop for 8 bits worth.
clrb SerOut ;stop bit = -ve voltage.
call BitDelay ;one stop bit for 8N1.
;Bit time delay = 8 + 4 * n, where n=bit delay number.
;calculate as = 4/1843200 * (4 * n + 8) seconds.
BitDelay mov TempC,#46 ;2400 baud with 1.8432MHz clock.
DelayLoop nop ;delay 1 clock
djnz TempC,DelayLoop ;total loop = 4 clocks
;Half a bit delay at start.
;Time wasted = 9 + 4 * n, where n=~1/2 bit delay number.
;calculate as = 4/1843200 * (4 * n + 9) seconds.
HalfBitDelay mov TempC,#22 ;2400 baud with 1.8432MHz clock.
More... (looser matching)
- Last day of these posts
- In 1996
, 1997 only
- New search...