Log in

View Full Version : serout pic16f84 different than pic16f818



jjohannson
- 10th March 2007, 01:38
I'm trying to get my pic 16f818 to transmit characters to a serial LCD. When I use the same code on f84 chip it works fine. However, when I try it on a f818 it sends a different character. I used a logic analyzer to check out what's going on. It looks as if the start bit is longer on the f84. I thought by default it sent data 8N1 not matter what chip your using. Is there any defines I don't know about? Thanks for any help.
code:

INCLUDE "BS2DEFS.BAS"

@ DEVICE INTRC_OSC_NOCLKOUT,MCLR_OFF
DEFINE OSC 4
OSCCON=$60
ADCON1=6
HIGH PORTB.0
sleep 2

low PORTA.2

begin:

serout PORTB.0,N2400,[12]
SLEEP 2

HIGH PORTB.0
SEROUT2 PORTB.0,N2400, [68]

SLEEP 2
LOW PORTA.2
goto begin

skimask
- 10th March 2007, 02:53
Page 140 of the PBP manual has your answer...

jjohannson
- 11th March 2007, 00:11
I checked out the manual on 140. The only thing I did was define CHAR_PACING but that didn't work. I didn't see any more information. However, I found that holding the SEROUT pin high for 820us just before the SEROUT call works. I got this value by analyzing timing from the F84 chip compared the F818 chip and noticed the first high level change on the F84 chip lasted 820us longer that the first high level change on the F818 chip. Seems a little strange to me or else I'm still missing something. I'm trying to use the SEROUT command not the SEROUT2

Archangel
- 11th March 2007, 02:48
I'm trying to get my pic 16f818 to transmit characters to a serial LCD. When I use the same code on f84 chip it works fine. However, when I try it on a f818 it sends a different character. I used a logic analyzer to check out what's going on. It looks as if the start bit is longer on the f84. I thought by default it sent data 8N1 not matter what chip your using. Is there any defines I don't know about? Thanks for any help.



INCLUDE "BS2DEFS.BAS"

@ DEVICE INTRC_OSC_NOCLKOUT,MCLR_OFF
DEFINE OSC 4
OSCCON=$60
ADCON1=6
<font color=red>HIGH PORTB.0</font color>
sleep 2

low PORTA.2

begin:

serout PORTB.0,N2400,[12]
SLEEP 2

<font color=red>HIGH PORTB.0</font color>
SEROUT2 PORTB.0,N2400, [68]

SLEEP 2
LOW PORTA.2
goto begin

<font color=blue><b>You are calling on your serial output pin to go high.
What's that about? Also you have used serout AND serout2, so yes you are using serout2, I suspect that's why skimask directed you to page 140. I am curious about the high portB.o command though. I would be inclined to eliminate it and do something like this</font color>

SEROUT PortB.0,N2400,[254,128,"68"]
I am really curious as to why you would use INCLUDE "BS2DEFS.BAS" instead of INCLUDE "modedefs.bas" since you are using PICs and not Stamps.
JS

mister_e
- 11th March 2007, 10:27
Joe it's perfectly usual to set the Serial pin to it's normal state. When you start the PIC and just set the TRIS register, you couldn't know at which level they will be.

Here there's no TRIS setting, but HIGH take care of it. Too bad, it will need LOW instead for Inverted mode.

Do a simple test with that Code, monitor the PORTB.0 level before the SEROUT, and after the SEROUT. There's chance it will be different, thus this may 'fart' the First data you send.

Another thing, this PIC have a nice OSCCON register that allow you to know when the internal OSC is stable. You should wait until it is stable unless you may again screw the baudrate.

Again, it use a internal OSC which are usually pretty poor for any reliable serial communication. At least you should tune it by changing the OSCTUNE register value. Why it worked with a F84... because of the EXTERNAL osc.

If you have only 1 serial output, There's no advantage to use SEROUT, you should try DEBUG.

PBP SLEEP use the WatchdogTimer, and you don't have it enable in your config fuses. So i doubt it may work UNLESS you haven't comment the PBP default in the PBP .INC file. WhyNot using PAUSE instead?

For safety sake, you should wait at little bit after you set the SerialPinIdle level, let's say 50mSec

try this untested one


ASM
DEVICE PIC16F818, INTRC_OSC ,MCLR_OFF ,LVP_OFF
DEVICE PIC16F818, WDT_ON ,PWRT_ON ,BOD_ON
DEVICE PIC16F818, DEBUG_OFF ,CCPMX_OFF
DEVICE PIC16F818, CPD_OFF ,WRT_OFF ,PROTECT_OFF
ENDASM

'
' Internal OSC config
' ====================
OSCCON=$60 ' Internal OSC=4MHZ
WHILE OSCCON.2=0 : WEND ' wait until frequency is stable

'
' I/O config
' ==========
TRISB=0 ' PORTB=out
TRISA=0 ' PORTA=out

ADCON1=6 ' disable ADCs

'
' Softare Serial comm setup
' =========================
DEFINE DEBUG_REG PORTB ' Debug pin port
DEFINE DEBUG_BIT 0 ' Debug pin bit
DEFINE DEBUG_BAUD 2400 ' Debug baud rate
DEFINE DEBUG_MODE 1 ' Debug mode: 0 = True, 1 = Inverted
DEFINE DEBUG_PACING 1000 ' Debug character pacing in us


'
' Program Start
' =============


'
' Hardware init
' =============
PORTA=0 ' clear PORTA
PORTB=0 ' clear PORTB
pause 50 ' safe statup delay

Start:
debug "Text or data, or whatever else written in PBP manual"
PAUSE 250
GOTO START

Archangel
- 11th March 2007, 20:06
Steve,
All the code and text above the <font color=blue><b>blue text, is the other guys</font color></b> I was just trying to get explanation as to why the high port command, Thank you for the explanation, it will help my applications later. <b>Interestingly enough I tried out debug last night for the first time!</b> I have never used internal osc. on a project, and taking your warnings I likely will never use it to serial communicate. Frankly, what is training? Benefitting from the experience of others. Albert Einstein said," all knowlege is trial and error ". Very interesting to learn about pic's ability to wait for internal osc to stabalize.


OSCCON=$60 ' Internal OSC=4MHZ
WHILE OSCCON.2=0 : WEND ' wait until frequency is stable

Thank You again
JS

jjohannson
- 12th March 2007, 19:27
I've decided to heed your advice and use an external oscillator. Works great now without having to put in timing delays and such.