Menu

RS232, prob , code example

Help
J Olson
2009-04-11
2013-05-30
  • J Olson

    J Olson - 2009-04-11

    I get the expected 3 char but they are gibberrish.
    If I change the values then the gibberish changes.
    I can also add or delete ser sends and I get the expected amount of bytes but always junk.

    I have tried a lot of the examples but this one was the only one that came close to doing anything.

    I have triple checked my cables and connections.
    Here is the code I am using.

    Any help would be great.

    'Chip model
    #chip 16F946, 8
    #config WDT_OFF, MCLRE_OFF, OSC=INTRC_OSC_NOCLKOUT, PWRTE_ON, CP_OFF

         ADOff                ' ADc Off
        set OPTION_REG.7 off        ' Set pullups ON
        WPUB = b'11111111'        ' Set ALL pullups ON B
        CMCON0 = b'00000111'        ' Turn Compatorators OFF
        CMCON1 = 0            '
        LCDCON = 0        ' Turn LCD POWER MODULE OFF
        LVDCON = 0        ' Turn LOW VOLTAGE MONITOR OFF
        LCDSE0 = 0            ' Set LCD to I/O pin
        LCDSE1 = 0            ' Set LCD to I/O pin
        LCDSE2 = 0            ' Set LCD to I/O pin
        LCDSE3 = 0            ' Set LCD to I/O pin
        LCDSE4 = 0            ' Set LCD to I/O pin
        LCDSE5 = 0            ' Set LCD to I/O pin
        ANSEL = 0            ' Set AN out to I/O not ANALOG
       

    '------------------------------> INPUTS <--------------------------

    ' PORT.6 is my TX pin and PORT.7 is my RX

    #define LED PORTD.6              ' LED (Active Hi)
       
    #define SendAHigh Set PORTC.6 ON
    #define SendALow Set PORTC.6 OFF

    dir PortC.6 out
    dir PortC.7 in

       
    InitSer 1, r9600, 1+WaitForStart, 8, 1, none, normal

    wait 2 sec

    repeat 4
        gosub BLINK_LED
       
    end repeat

    main:
      
       
            
            SerSend 1, h'20'    ' Space (ascii)
            Wait 100 ms
            
            SerSend 1, h'4D'        ' M (ascii)
            Wait 100 ms

        SerSend 1, h'7A'        ' z (ascii)
            Wait 100 ms

        gosub BLINK_LED

    goto main

    '************************** LED ROUTINES ********************************

    BLINK_LED:

       dir led out

       SET led ON
       wait 150 ms
       SET led OFF
       wait 150 ms

       dir led in

       return

    '
    '
    '
       end

     
    • J Olson

      J Olson - 2009-04-11

      This one (standard gcb ser. calls) still doesn't work for some reason.

      I went and retried the "Usart lean" version .h again.
      And it works! Very strange as it didn't the first time.
      Must of fat fingered something or had a bad path, or gremlins.

      This rocks, I was beating head againt the fence again why this would not work when everyone else was getting it working.

      Works flawless on a 16F946 at all bauds using a max233.

      Sweet!

      Mz

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.