PIC12F1840 & serout2
+ Reply to Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    78

    Default PIC12F1840 & serout2

    Hi,
    Anyone used the PIC12F1840 with serout2? Any tricks to it? I can't get anything out.

    Regards,

    Troy

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,258

    Default Re: PIC12F1840 & serout2

    Can't say I've used that specific command with that specific part but apart from the usual stuff* I don't see why it shouldn't work.

    * Where the usual stuff would be:
    Correct oscillator configuration.
    Analog functions on pin(s) in question turned off.

    The 12F1840 does have an EUSART, use that instead - if you can.

    If you need further help post the code.

    /Henrik.

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    1,702

    Default Re: PIC12F1840 & serout2

    there may be a clue in the manual

    SEROUT2 is not supported on 12-bit core PIC MCUs due to RAM and stack constraints.
    '
    This is more entertaining than Free to Air TV

  4. #4
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    78

    Default Re: PIC12F1840 & serout2

    Damn, I can't believe I missed that. Thanks for the answer Richard. I only need a really slow baud rate so I might try the old serout. Failing that, it'll have to be the EUSART although my experience with the EUSART on the PIC18F14K50 is it chewed up a quite a bit of juice when enabled...

    Cheers,

    Troy

  5. #5
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    78

    Default Re: PIC12F1840 & serout2

    Ummm... now reading p10 of the datasheet "This family of devices contain an enhanced mid-range 8-bit CPU core". So, I'm guessing it's not 12 bit?

    Troy

  6. #6
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    78

    Default Re: PIC12F1840 & serout2

    Okay, the EUSART seems to work fine and doesn't appear to consume any noticable extra power for this chip so hardware serials comms it is.

    Troy

  7. #7
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    78

    Default Re: PIC12F1840 & serout2

    So, it's probably worth adding as a reference for anyone looking at using this particular processor (12F1840) with PBP that you can't send serial comms in any software mode - debug, serout or serout2. Well, you can probably send numeric characters and ascii codes (eg: carraige return and line feed) reliably, but alphabetic characters don't send correctly - that is, they get transmitted reliably (consistent) but there's an offset added to their value so they come through as gobbledygook.

    Troy

  8. #8
    Join Date
    Jun 2005
    Location
    Perth, West Australia
    Posts
    85

    Default Re: PIC12F1840 & serout2

    Further to this thread...

    I'm exeriencing weird behaviour with a 12F1840 running identical code (obviously different configs) as old faithful 12F683 - which works flawlessly. Serout2 works fine in both cases

    but no response for Serin2 on the newer chip. Debug same results.

    Post #3 mentions 12bit core but I believe both the above are 14bit core, correct me if I'm wrong.

    This works:
    Code:
    '*********************************************************************************
    '*  Name    : 12F683 Serin2 Test.pbp                 *** Working ***             *
    '*  Author  : WJ Sherwood                                                        *
    '*  Date    : 14Jul19                                                            *
    '*  Device  : 12F683                                                             *
    '*          :                                                                    *
    '*  Notes   : This program for testing serial menu system code                   *
    '*          :                                                                    *
    '*********************************************************************************
    '
    '===================================================================================================
    '        CONFIGURE DEVICE
    '===================================================================================================
    #CONFIG
        __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOD_ON
    #ENDCONFIG
    
    ' Connections as follows:
    '    ****12F683 PIC*****	Comments
    '           GP0     (pin 7) Serout to laptop at 2400.
    ' 	   	    GP1     (pin 6) Serin from laptop at 2400. 
    '      	    GP2     (pin 5) 
    ' MCLR   	GP3     (pin 4) Input pin.  Pullup 10k.
    '      	    GP4     (pin 3)                                             
    '      	    GP5     (pin 2) 
    ' Vss     	Ground  (pin 8)
    ' Vdd     	5 volts (pin 1)
    '
    '===================================================================================================
    ' Constants
    '===================================================================================================
    B24     CON    16780  ' Baudmode for 2400,8,N,1 inverted.
    
    ' Alias pins
    S_out       var     GPIO.0     ' Serial output via 1k pin 13.
    S_in        var     GPIO.1     ' Serial input via 22k pin 12.
    
    ' Allocate variables
    DatIn       var 	byte   ' Serial Input from user.
    Counter     var     word   ' Indicator of traffic.
    secs        var 	byte   ' Seconds.
    mins        var 	byte   ' Minutes.
    hrs         var 	byte   ' Hours.
    
        Clear                       ' Reset all variables.
    
        Include "modedefs.bas" 
       
    '    DEFINE DEBUG_REG GPIO       ' Debug pin port (F1840).
    '    DEFINE DEBUG_BIT 0          ' Debug pin.
    '    DEFINE DEBUG_BAUD 2400     ' Debug baud rate.
    '    DEFINE DEBUG_MODE 1         ' Debug mode: 0 = True, 1 = Inverted
    ''    DEFINE DEBUG_MODE 0         ' Debug mode: 0 = True, 1 = Inverted - using 2N7000 to invert/amplify.
    ''    DEFINE DEBUG_PACING 1000    ' Debug character pacing in us
    ''    DEFINE DEBUGIN_BIT 2        ' Input pin.
    
        DEFINE  OSC 4               ' Adjust to suit design.
    '    OPTION_REG.7 = 0            ' Enable weak pullups.
        OPTION_REG.7 = 1            ' Disable weak pullups.
        ADCON0 = 0                  ' No ADC.
        ANSEL = 0                   ' No ADC.
    
        OSCCON  = %01101000         ' Internal 4MHz osc.
        CMCON0 = 7                  ' Comparators off
    	TRISIO = %000010            ' Known state.
        GPIO = %000000              ' All pins 0 on boot.
    
    'GPIO.0 = 1                     ' True.
        GPIO.0 = 0                  ' Inverted. Place serial line in resting state.
        Pause 500 					' Short wait for things to settle.
    
    '=========================================================================================================
    ' Subroutines here in the first page...         
    '===================================================================================================
    
    
             
    '===================================================================================================
    ' Program area...
    '===================================================================================================
    loopy:   ' Time waster.
        serout2 S_out,B24,["Looping (? for Menu) ", dec5 Counter,13]
        Counter = Counter+1                 ' Increment to show process is running.
        Serin2 S_in,B24,1000,loopy,[DatIn]  ' Check serial in line for "?"
        if DatIn="?" then Terminal          ' Run terminal routine.
        Goto loopy                          ' Do it forever.
    
    Terminal:
    GPIO.0 = 0                     ' Inverted. Prep serial out line for resting state.
        serout2 s_out,B24,[10,13,10,"Set: (T)ime (D)ate (A)larms e(X)it",10,13,"> "]    ' Send menu to user.
    GPIO.1 = 0                      ' Prep serial in line for resting state.
        Serin2 S_in,B24,10000,loopy,[DatIn]	' Look for instruction within 10 seconds. 
      DatIn = DatIn & $0DF          ' Convert to uppercase. 
        IF DatIn = "T" THEN T_ime   ' Jump to Time setting menu. 
        IF DatIn = "D" THEN D_ate   ' Jump to Date setting menu.
        IF DatIn = "A" THEN A_larm  ' Jump to Alarm setting menu.
        IF DatIn = "X" THEN         ' Add extra line space below.
            serout2 s_out,B24,[10,13,10]    ' Add some space between text.
            goto loopy              ' Then exit.
        endif     
        goto Terminal				' Unrecognized entry; try again. 
    
    T_ime:
    GPIO.0 = 0                      ' Inverted. Prep serial out line for resting state - else corrupt chars.
        serout2 s_out,B24,["Send Time as hhmmss",10,13,"> "]    ' Send menu to user.
        Serin2 S_in,B24,10000,Terminal,[dec2 hrs,dec2 mins,dec2 secs]	' Get new values.
        Serout2 s_out,B24,[10,13,"New Time ",dec2 hrs,":",dec2 mins,":",dec2 secs," - okay y/n?",10,13,10]   ' Confirmation.
        goto Okay
      
    D_ate:
    GPIO.0 = 0                      ' Inverted. Prep serial out line for resting state - else corrupt chars.
        serout2 s_out,B24,["At D_ate",10,13]    ' Send menu to user.
        goto Terminal
      
    A_larm:
    GPIO.0 = 0                      ' Inverted. Prep serial out line for resting state - else corrupt chars.
        serout2 s_out,B24,["At A_larm",10,13]    ' Send menu to user.
        goto Terminal
      
    Okay:  ' Got here from T_ime menu.
        Serin2 S_in,B24,10000,Terminal,[DatIn]	' Answer back within 10 seconds.
        if DatIn <> "y" then Terminal           ' Other than yes, abort.
        serout2 s_out,B24,["Time data good",10,13]    ' Feedback to user.
        Goto Terminal				            ' Send menu again.
    This does not:
    Code:
    '*********************************************************************************
    '*  Name    : 12LF1840 Serin2 Test.pbp                  *** NON Working ***      *
    '*  Author  : WJ Sherwood                                                        *
    '*  Date    : 14Jul19                                                            *
    '*  Device  : 12LF1840                                                           *
    '*          :                                                                    *
    '*  Notes   : This program for testing serial menu system code                   *
    '*          : LatA.x in place of PortA.x no difference, LF & F versions same.    *
    '*          :                                                                    *
    '*********************************************************************************
    '
    '===================================================================================================
    '        CONFIGURE DEVICE
    '===================================================================================================
    #CONFIG ; 12LF1840           
        __config _CONFIG1, _FOSC_INTOSC & _MCLRE_ON & _CP_OFF & _CPD_OFF & _WDTE_OFF & _PWRTE_ON    ; WDT off for test.
    ;    __config _CONFIG2, _PLLEN_ON & _LVP_OFF    ; PLL always on regardless of OSCON.7
        __config _CONFIG2, _PLLEN_OFF & _LVP_OFF    ; PLL determined by OSCON.7 if disabled in config.
    #ENDCONFIG
    '
    '#CONFIG ; from http://www.picbasic.co.uk/forum/showthread.php?t=20229
    'cfg1 = _FOSC_INTOSC           ; INTOSC oscillator: I/O function on CLKIN pin
    'cfg1&= _WDTE_OFF              ; WDT disabled
    'cfg1&= _PWRTE_ON              ; PWRT enabled
    'cfg1&= _MCLRE_ON              ; MCLR/VPP pin function is MCLR
    'cfg1&= _CP_OFF                ; Program memory code protection is disabled
    'cfg1&= _CPD_OFF               ; Data memory code protection is disabled
    'cfg1&= _BOREN_ON              ; Brown-out Reset enabled
    'cfg1&= _CLKOUTEN_OFF          ; CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
    'cfg1&= _IESO_OFF              ; Internal/External Switchover mode is disabled
    'cfg1&= _FCMEN_ON              ; Fail-Safe Clock Monitor is enabled
    '  __CONFIG _CONFIG1, cfg1
    
    'cfg2 = _WRT_OFF               ; Write protection off
    'cfg2&= _PLLEN_OFF             ; 4x PLL disabled (PLL determined by OSCON.7 if disabled here).
    'cfg2&= _STVREN_OFF            ; Stack Overflow or Underflow will not cause a Reset
    'cfg2&= _BORV_19               ; Brown-out Reset Voltage (Vbor), low trip point selected.
    'cfg2&= _LVP_OFF               ; High-voltage on MCLR/VPP must be used for programming.
    '  __CONFIG _CONFIG2, cfg2
    '#ENDCONFIG
    
    ' Connections as follows:
    '    ****12LF1840 PIC*****	Comments
    '           RA0     (pin 7) Serout to laptop at 2400.
    ' 	   	    RA1     (pin 6) Serin from laptop at 2400. 
    '      	    RA2     (pin 5) 
    ' MCLR   	RA3     (pin 4) Input pin.  Pullup 10k.
    '      	    RA4     (pin 3) 
    '      	    RA5     (pin 2) 
    ' Vss     	Ground  (pin 8)
    ' Vdd     	5 volts (pin 1)
    '
    '===================================================================================================
    ' Constants
    '===================================================================================================
    B24     CON    16780  ' Baudmode for 2400,8,N,1 inverted.
    
    ' Alias pins
    S_out       var     PortA.0     ' Serial output via 1k pin 13.
    S_in        var     PortA.1     ' Serial input via 22k pin 12.
    
    ' Allocate variables
    DatIn       var 	byte   ' Serial Input from user.
    Counter     var     word   ' Indicator of traffic.
    secs        var 	byte   ' Seconds.
    mins        var 	byte   ' Minutes.
    hrs         var 	byte   ' Hours.
    
        Clear                       ' Reset all variables.
    
        Include "modedefs.bas" 
       
    '    DEFINE DEBUG_REG PORTA      ' Debug pin port (F1840).
    '    DEFINE DEBUG_BIT 0          ' Debug pin.
    '    DEFINE DEBUG_BAUD 2400      ' Debug baud rate.
    '    DEFINE DEBUG_MODE 1         ' Debug mode: 0 = True, 1 = Inverted
    ''    DEFINE DEBUG_MODE 0         ' Debug mode: 0 = True, 1 = Inverted - using 2N7000 to invert/amplify.
    '    DEFINE DEBUG_PACING 1000    ' Debug character pacing in us
    '    DEFINE DEBUGIN_BIT 1        ' Input pin.
    
        DEFINE  OSC 4               ' Adjust to suit design.
    '    OPTION_REG.7 = 0            ' Enable weak pullups.
        OPTION_REG.7 = 1            ' Disable weak pullups.
        ADCON0 = 0                  ' No ADC.
        WPUA = %00000000            ' Pull-ups disable.
        OSCCON  = %01101000         ' Internal 4MHz osc, no x4 PLL.
        OSCTUNE	= %00000000         ' Internal osc Adjustment.
    
        WHILE !OSCSTAT.3            ' Wait for stable Osc...
        WEND
        
        TRISA = %000010             ' Set I/O (F1840).
        PORTA = %000000             ' All pins 0 on boot (F1840).
    
    'latA.0 = 1                      ' True.
    latA.0 = 0                      ' Inverted. Place serial line in resting state.
        Pause 500 					' Short wait for things to settle.
    
    '===================================================================================================
    ' Subroutines here in the first page...         
    '===================================================================================================
    
    
             
    '===================================================================================================
    ' Program area...
    '===================================================================================================
    loopy:   ' Time waster.
        serout2 S_out,B24,["Looping (? for Menu) ", dec5 Counter,13]
        Serin2 S_in,B24,1000,loopy,[DatIn]  ' Check serial in line for "?"
    '    serout S_out,B24,["Looping (? for Menu) ", dec5 Counter,13]
    '    Serin S_in,B24,1000,loopy,[DatIn]  ' Check serial in line for "?"
    '    debug "Looping (? for Menu) ", dec5 Counter,13
        Counter = Counter+1                 ' Increment to show process is running.
            serout2 s_out,B24,[10,13,10]    ' Add some space between text.
    '        serout s_out,B24,[10,13,10]    ' Add some space between text.
    '    debugin 1000,loopy,[DatIn]          ' Check serial in line for "?"
        if DatIn="?" then Terminal          ' Run terminal routine.
        Goto loopy                          ' Do it forever.
    
    Terminal:
    PortA.0 = 0                     ' Inverted. Prep serial out line for resting state.
    'LatA.0 = 0                      ' Inverted. Prep serial out line for resting state.
        serout2 s_out,B24,[10,13,10,"Set: (T)ime (D)ate (A)larms e(X)it",10,13,"> "]    ' Send menu to user.
    '    serout s_out,B24,[10,13,10,"Set: (T)ime (D)ate (A)larms e(X)it",10,13,"> "]    ' Send menu to user.
    '    debug "Set: (T)ime (D)ate (A)larms e(X)it",10,13,"> "    ' Send menu to user.
    PortA.1 = 0                     ' Prep serial in line for resting state.
    'LatA.1 = 0                     ' Prep serial in line for resting state.
        Serin2 S_in,B24,10000,loopy,[DatIn]	' Look for instruction within 10 seconds. 
    '    Serin S_in,B24,10000,loopy,[DatIn]	' Look for instruction within 10 seconds. 
    '    debugin 10000,loopy,[DatIn]	' Look for instruction within 10 seconds. 
      DatIn = DatIn & $0DF          ' Convert to uppercase. 
        IF DatIn = "T" THEN T_ime   ' Jump to Time setting menu. 
        IF DatIn = "D" THEN D_ate   ' Jump to Date setting menu.
        IF DatIn = "A" THEN A_larm  ' Jump to Alarm setting menu.
        IF DatIn = "X" THEN         ' Add extra line space below.
            serout2 s_out,B24,[10,13,10]    ' Add some space between text.
    '        serout s_out,B24,[10,13,10]    ' Add some space between text.
    '        debug 10,13,10          ' Add some space between text.
            goto loopy              ' Then exit.
        endif     
        goto Terminal				' Unrecognized entry; try again. 
    
    T_ime:
    PortA.0 = 0                      ' Inverted. Prep serial out line for resting state.
    'LatA.0 = 0                      ' Inverted. Prep serial out line for resting state.
        serout2 s_out,B24,["Send Time as hhmmss",10,13,"> "]    ' Send menu to user.
        Serin2 S_in,B24,10000,Terminal,[dec2 hrs,dec2 mins,dec2 secs]	' Get new values.
        Serout2 s_out,B24,[10,13,"New Time ",dec2 hrs,":",dec2 mins,":",dec2 secs," - okay y/n?",10,13,10]   ' Confirmation.
    '    serout s_out,B24,["Send Time as hhmmss",10,13,"> "]    ' Send menu to user.
    '    Serin S_in,B24,10000,Terminal,[dec2 hrs,dec2 mins,dec2 secs]	' Get new values.
    '    Serout s_out,B24,[10,13,"New Time ",dec2 hrs,":",dec2 mins,":",dec2 secs," - okay y/n?",10,13,10]   ' Confirmation.
    '    debug "Send Time as hhmmss",10,13,"> "    ' Send menu to user.
    '    debugin 10000,Terminal,[dec2 hrs,dec2 mins,dec2 secs]	' Get new values.
    '    debug "New Time ",dec2 hrs,":",dec2 mins,":",dec2 secs," - okay y/n?",10,13,10   ' Confirmation.
        goto Okay
      
    D_ate:
    PortA.0 = 0                      ' Inverted. Prep serial out line for resting state.
    'LatA.0 = 0                      ' Inverted. Prep serial out line for resting state.
        serout2 s_out,B24,["At D_ate",10,13]    ' Send menu to user.
    '    serout s_out,B24,["At D_ate",10,13]    ' Send menu to user.
    '    debug "At D_ate",10,13       ' Send menu to user.
        goto Terminal
      
    A_larm:
    PortA.0 = 0                      ' Inverted. Prep serial out line for resting state.
    'LatA.0 = 0                      ' Inverted. Prep serial out line for resting state.
        serout2 s_out,B24,["At A_larm",10,13]    ' Send menu to user.
    '    serout s_out,B24,["At A_larm",10,13]    ' Send menu to user.
    '    debug "At A_larm",10,13      ' Send menu to user.
        goto Terminal
      
    Okay:  ' Got here from T_ime menu.
        Serin2 S_in,B24,10000,Terminal,[DatIn]	' Answer back within 10 seconds.
    '    Serin S_in,B24,10000,Terminal,[DatIn]	' Answer back within 10 seconds.
    '    debugin 10000,Terminal,[DatIn]	' Answer back within 10 seconds.
        if DatIn <> "y" then Terminal   ' Other than yes, abort.
        serout2 s_out,B24,["Time data good",10,13]    ' Feedback to user.
    '    serout s_out,B24,["Time data good",10,13]    ' Feedback to user.
    '    debug "Time data good",10,13    ' Feedback to user.
        Goto Terminal				    ' Send menu again.
    Can anyone shed some light on why this is so and are there other PICs affected?

    I'm hoping it is a mistake on my part or is easily explained. If hardware comms is the only option it severely limits my uses for the only 8pin PIC with any gonads.

    Kind regards,
    Bill

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    1,702

    Default Re: PIC12F1840 & serout2

    ADCON0 = 0 ' No ADC.
    NAH more like

    ANSELA=0;SET PORT A DIGITAL


    and all these

    PortA.0 = 0

    are unnecessary other than the first one to set initial state
    This is more entertaining than Free to Air TV

  10. #10
    Join Date
    Jun 2005
    Location
    Perth, West Australia
    Posts
    85

    Default Re: PIC12F1840 & serout2

    Doh!

    Thanks Richard, put a star up against your name for today. RTFM indeed... although it did take some digging to find ANSELA in the data sheet, I've made some notes so this doesn't happen again.

    Regards from Perth,
    Bill

Similar Threads

  1. Replies: 2
    Last Post: - 4th February 2015, 17:06
  2. Replies: 5
    Last Post: - 17th May 2012, 10:14
  3. Replies: 8
    Last Post: - 11th July 2011, 20:20
  4. Comunication between 12F683 & 16F84A with serin2/serout2
    By kklim29 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 29th April 2010, 18:16
  5. ICD & PBP && how to get it to work
    By archendekta in forum mel PIC BASIC Pro
    Replies: 26
    Last Post: - 24th March 2010, 01:56

Members who have read this thread : 20

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