serout pic16f84 different than pic16f818


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Mar 2007
    Posts
    14

    Default serout pic16f84 different than pic16f818

    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

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Page 140 of the PBP manual has your answer...

  3. #3
    Join Date
    Mar 2007
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Fixed but not elegantly.

    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

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Quandry???

    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
    <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>
    Code:
     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
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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
    Code:
            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
    Last edited by mister_e; - 11th March 2007 at 10:32.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    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.
    Code:
    OSCCON=$60                  ' Internal OSC=4MHZ
    WHILE OSCCON.2=0 : WEND     ' wait until frequency is stable
    Thank You again
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  7. #7
    Join Date
    Mar 2007
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Thanks ya'll

    I've decided to heed your advice and use an external oscillator. Works great now without having to put in timing delays and such.

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 20:58
  2. Serout to serial servo
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 12th August 2009, 16:46
  3. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 17:11
  4. Keypad unlock (as in garage door possibly)
    By Fred in forum Code Examples
    Replies: 5
    Last Post: - 2nd April 2006, 04:26
  5. Replies: 11
    Last Post: - 13th July 2005, 19:26

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts