Serout problem


Closed Thread
Results 1 to 40 of 95

Thread: Serout problem

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    Cambridge UK
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    Hi,

    I am having a couple of problems with the above code. I changed it so that I could run it on two 16f628 chips, this works with out any problems.
    Happy that I could tx and rx I wanted to tx using a 12f675 chip and rx on a 16f628.

    Changing the tx code for a 12f675 and compiling it gave no errors. The leds flash ok and when I put an led on the serout pin I see the data. When I tx the code to the rx 16f628 via a tx the rx wont respond. I then hardwired the 12f675 to the 16f628 removing the tx/rx, it still wont work.
    Can someone please check my code or suggest why it wont work.
    Here is the code;

    @ DEVICE PIC12F675, INTRC_OSC_NOCLKOUT
    ' System Clock Options (Internal)
    @ DEVICE PIC12F675, WDT_ON
    ' Watchdog Timer
    @ DEVICE PIC12F675, PWRT_ON
    ' Power-On Timer
    @ DEVICE PIC12F675, MCLR_OFF
    ' Master Clear Options (Internal)
    @ DEVICE PIC12F675, BOD_OFF
    ' Brown-Out Detect
    @ DEVICE PIC12F675, CPD_OFF
    ' Data Memory Code Protect
    @ DEVICE PIC12F675, PROTECT_ON

    'PICBASIC PROGRAM

    ANSEL = 0
    CMCON = 7
    TRISIO =%001000


    INCLUDE "modedefs.bas"


    txout VAR GPIO.4 : Output txout : dataout VAR BYTE
    ledcount VAR BYTE
    led1 VAR GPIO.0 : Output led1 : led2 VAR GPIO.1 : Output led2
    led3 VAR GPIO.2 : Output led3 : led4 VAR GPIO.5 : Output led4
    key VAR GPIO.3 : Input key 'push button on gpio.3
    '1K-10K resistor from portb.0 to ground (pulldown)
    'push button is wired between portb.0 and +5v
    'initial LED check
    led1 = 1 : Pause 500 : led1 = 0 : led2 = 1 : Pause 500 : led2 = 0
    led3 = 1 : Pause 500 : led3 = 0 : led4 = 1 : Pause 500 : led4 = 0

    mainloop:

    IF key = 0 Then 'button not pressed
    GoTo mainloop
    EndIF
    IF key = 1 Then
    Pause 50 'wait 50ms for switch to debounce then check again
    IF key = 1 Then 'if it's still pressed, then increment the count
    ledcount = ledcount + 1
    dataout = $55 '($55 = manchester encoded $0)
    'train the receiver by sending 5 each of the $55's, may need more
    'just copy the line below to make it send out more characters
    SerOut txout, n2400, [ dataout, dataout, dataout, dataout, dataout ]
    EndIF
    EndIF

    IF ledcount = 0 Then 'all leds off
    dataout = $66 'manchester encoded $5, use because $0 is reserved
    SerOut txout, n2400, [ dataout ]
    'may have to send data more than once depending on how well the receiver
    'can capture the data. Shouldn't have a problem sending it once
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 0
    EndIF

    IF ledcount = 1 Then '1st led on
    dataout = $56 'manchester encoded $1
    SerOut txout, n2400, [ dataout ]
    led1 = 1 : led2 = 0 : led3 = 0 : led4 = 0
    EndIF

    IF ledcount = 2 Then '2nd led on and so on and so on down the line....
    dataout = $59 'manchester encoded $2
    SerOut txout, n2400, [ dataout ]
    led1 = 0 : led2 = 1 : led3 = 0 : led4 = 0
    EndIF

    IF ledcount = 3 Then
    dataout = $5a 'manchester encoded $3
    SerOut txout, n2400, [ dataout ]
    led1 = 0 : led2 = 0 : led3 = 1 : led4 = 0
    EndIF

    IF ledcount = 4 Then
    dataout = $65 'manchester encoded $4
    SerOut txout, n2400, [ dataout ]
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 1
    EndIF

    IF ledcount = 5 Then 'reset led count, roll it back to 0
    ledcount = 0 'and turn leds off since count is back to 0
    dataout = $66 'manchester encoded $5 (same thing as ledcount = 0 above)
    SerOut txout, n2400, [ dataout ]
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 0
    EndIF

    GoTo mainloop

    End

    I am using the two 16f628's with internal clock selected with no problem

    thanks Nick
    Last edited by Agent36; - 24th February 2007 at 19:29.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    The internal clock on the 12F675 is probably too far off (i.e. 12F675 transmitting at 2350 baud, 16F628 receiving at 2400 baud, something like that).
    Try slowing down the baud rate or moving the OSCCAL value on the 12F675 around a bit and see what happens.

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


    Did you find this post helpful? Yes | No

    Default

    If the calibration data is still intact, you try to add
    Code:
    DEFINE OSCCAL_1K 1
    Before ANSEL=0
    Steve

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

  4. #4
    Join Date
    Nov 2005
    Location
    Cambridge UK
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    Hi,
    thanks for the replys, I thought it might be something to do with the internal osc. Tried the program code on a 16f819 worked fine.
    So i got a brand new 12f675, checked the osc cal and band gap values, loaded the code and rechecked them. I did this because I have had other timing issues with these 12f675's. Some of which were down to me I think.
    I like to stick with an 8 pin chip because I aim to fit the board into a keyfob, so space is tight.
    First I will try the soloutions you have offered.

    Thanks for your time.

    Nick

  5. #5
    Join Date
    Nov 2005
    Location
    Cambridge UK
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    Hi,

    Thanks for the info regarding the DEFINE OSCCAL_1K 1
    Adding that to the program code has solved my little problem.

    I have found referances about this define in the pbp manual, for some reason I thought that DEFINE OSC 4mhz was correct.

    I assume that DEFINE OSCCAL_1K 1 means

    org 0
    movwf OSCCAL

    Thanks for your time........Nick

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. Strange SerOut Problem
    By masosi in forum mel PIC BASIC Pro
    Replies: 39
    Last Post: - 23rd April 2007, 06:06
  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