HELP! HSER issues from old to new


+ Reply to Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262

    Default HELP! HSER issues from old to new

    I had a couple of projects sending serial data to LCD's and that still works as far as i can tell, I don't have the displays to check. i also have a VB.net program that sends a single byte to a chip and that chip displays it on a parallel LCD, note that should still work too. my problem is I am using a 8pin chip with no LCD, all I have is a LED to see if i'm getting data on the chip. I am also using the software "realterm" as a temporary interface till the VB program is written. i have tried for 4 hours now and its still not working, many configurations and such so I will state what I need and hopefully someone can insert missing code or provide links etc... Project: Use a 12F1572 to read a 16 bit analog pin, send that 16bit data to the PC, then wait for response. PC will take number do some math, etc.. and then send a byte back to the chip to tell the chip to turn on a output pin to drive a LED or FET. heres my basic layout of code define OSC 4 DEFINE ADC_BITS 16 ' A/D number of bits DEFINE ADC_CLOCK 3 ' Uses A/D internal RC clock DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us define HSER_BAUD 9600 DEFINE HSER_BITS 8 DEFINE HSER_CLROERR 1 DEFINE HSER_RCSTA 90h DEFINE HSER_TXSTA 20h DEFINE HSER_SPBRG 25 DEFINE HSER_SPBRGH 0 A VAR WORD 'Stores 16 Bit Analog Reading B VAR byte 'Temp Holder Switch VAR PORTA.5 'Controls External FET or LED on pin 2 Switch = 0 mainloop: ADCIN 2, A 'Grab analog input from Pin 3 Hserout [A] ' Send char out serial port pause 100 HSERIN [B] if B = 5 then switch = 1 else switch = 0 pause 100 goto mainloop ' Do it all over again
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  2. #2
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262

    Default Re: HELP! HSER issues from old to new

    Ok I found a way around to get my code to show up right, I could really use some help getting this to work.
    I have a project that needs this interface and I want to get it running by the 28th before I get back home.

    Code:
    define OSC 4
    
    DEFINE ADC_BITS 16 ' A/D number of bits
    DEFINE ADC_CLOCK 3 ' Uses A/D internal RC clock
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us
    
    define HSER_BAUD 9600
    DEFINE HSER_BITS 8
    DEFINE HSER_CLROERR 1
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_SPBRG 25
    DEFINE HSER_SPBRGH 0
    
    A VAR WORD 'Stores 16 Bit Analog Reading
    B VAR byte 'Temp Holder
    Switch VAR PORTA.5 'Controls External FET or LED on pin 2
    Switch = 0
    
    mainloop: 
    ADCIN 2, A   'Grab analog input from Pin 3
    
    Hserout [A]		' Send char out serial port
    pause 100
    
    HSERIN [B]
    if B = 5 then switch = 1 else switch = 0	
    pause 100
    
    goto mainloop		' Do it all over again
    Attached Files Attached Files
    Last edited by wdmagic; - 23rd October 2015 at 01:10.
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,817

    Default Re: HELP! HSER issues from old to new

    Hi WD,
    I am not sure which part you are having trouble with, and am presently unable to work on HSER*** but I played with your code using a 16F690 demo board and debug and pretty well got it to function, accuracy notwithstanding . . .
    Code:
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _CP_OFF
    ; DEFINE LOADER_USER 1   ' Boot-Loader is being used
    DEFINE OSC 4          ' Change to your chip
    DEFINE DEBUG_MODE  0         ' Debug sending True serial data
    DEFINE DEBUG_REG_PORTA       ' Debug Port = PortA as required by PICKIT2 serial Monitor
    DEFINE DEBUG_BIT 0           ' Debug.bit = PortA.0
    DEFINE DEBUG_BAUD 9600       ' Default baud rate = 9600
    DEFINE DEBUGIN_REG PORTA     ' Debug Port = PortA as required by PICKIT2 serial Monitor 
    DEFINE DEBUGIN_BIT 1         ' Debugin bit PortA.1
    DEFINE DEBUGIN_BAUD 9600     ' Default baud rate = 9600
    DEFINE DEBUGIN_MODE 0        ' Debugin receiving data true = 0 inverted = 1
    
    ;DEFINE HSER_BAUD	9600	' override the default of 2400
    ANSEL  = 0                   ' 
    ANSELH = 0       
    ADCON0 = %00001011
    led	VAR portc.1		' change if needed				
    
    TrisC = %00000000
    TrisA = %00000010
    A VAR word 'Stores 16 Bit Analog Reading
    B0 VAR byte 'Temp Holder
    a=0
    b0=0
    Switch VAR byte
    ;portC = %00000000
    mainloop: 
    ADCIN 2, A   'Grab analog input from RA2
    
    ;
    pause 100
    
    Debugin [B0]
        IF B0 = "5" THEN
             led = 1
             Debug " high fives"
             
        else
            led = 0
            Debug " still low"
            
     
    	
    pause 100
    Debug B0		' Send char out serial port
    endif
    A = a + 48
    debug A
    
    goto mainloop		' Do it all over again
    Maybe something useful in there.
    JS
    Last edited by Archangel; - 23rd October 2015 at 03:44.
    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.

  4. #4
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262

    Default Re: HELP! HSER issues from old to new

    that didnt help unfortunatly. I did get some stuff to work, as it seems I forgot my TRIS statement which always causes problems
    however here is my updated code
    Code:
    Include "12F1572.bas"
    DEFINE OSC 20
    
    DEFINE ADC_BITS 16 ' A/D number of bits
    DEFINE ADC_CLOCK 3 ' Uses A/D internal RC clock
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us
    
    define HSER_BAUD 9600
    DEFINE HSER_BITS 8
    DEFINE HSER_CLROERR 1
    
    ADCON0.7 = 0
    TRISA = 0
    
    A VAR WORD 'Stores 16 Bit Analog Reading
    B VAR byte 'Temp Holder
    
    mainloop: 
    ADCIN 3, A   'Grab analog input from pin3
    porta.2 = 0
    Hserout [a,13,10]		' Send char out serial port
    pause 250
    porta.2 = 1
    pause 250
    goto mainloop		' Do it all over again
    now if i chage
    Code:
    Hserout [a,13,10]
    to
    Code:
    Hserout ["help",13,10]
    then i get help on the computer.
    still at a loss here, I'm missing something
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,104

    Default Re: HELP! HSER issues from old to new

    I think you are sending out the binary value of a and not the converted to ascii value.

    your HSEROUT should be something like this:

    Code:
    HSEROUT [dec5 a,13,10]
    or

    Code:
    HSEROUT [#a,13,10]
    Ioannis

  6. #6
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262

    Default Re: HELP! HSER issues from old to new

    ok that worked a lot better. However I don't thing my justify bits is working as my results are all from 512 to 64k not from 0 - 1024

    here is my adjusted code

    Code:
    Include "12F1572.bas"
    DEFINE OSC 20
    
    DEFINE ADC_BITS 10 ' A/D number of bits
    DEFINE ADC_CLOCK 1 ' Uses A/D internal RC clock
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us
    
    define HSER_BAUD 9600
    DEFINE HSER_BITS 8
    DEFINE HSER_CLROERR 1
    
    ADCON0.7 = 0
    TRISA = %00000100
    ANSELA = %00000100      
    
    A VAR word 'Stores 10 Bit Analog Reading
    mainloop: 
    ADCIN 2, A   'Grab analog input from pin3
    pause 50
    Hserout [#A,13,10]		' Send char out serial port
    pause 500
    goto mainloop		' Do it all over again
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,104

    Default Re: HELP! HSER issues from old to new

    What if you comment out the line ADCON0.7 ?

    Ioannis

  8. #8

    Default Re: HELP! HSER issues from old to new

    However I don't thing my justify bits is working as my results are all from 512 to 64k not from 0 - 1024
    In that pic, the ADFM 'justify' bit is in ADCON1.7

  9. #9
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262

    Default Re: HELP! HSER issues from old to new

    ok remarking out - didnt work
    ADCON1.7 = 0 - didnt work
    ADCON1.7 = 1 - WORKED!

    OK so now we are sending to the computer what we need. Now to get the part to receive from the PC a Byte.

    Heres my modified code, its been reworked several times stuff moved round Ill make notes at bottom of what its doing.

    Code:
    Include "12F1572.bas"
    DEFINE OSC 20
    
    DEFINE ADC_BITS 10 ' A/D number of bits
    DEFINE ADC_CLOCK 1 ' Uses A/D internal RC clock
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us
    
    define HSER_BAUD 9600
    DEFINE HSER_BITS 8
    DEFINE HSER_CLROERR 1
    
    ADCON1.7 = 1
    TRISA = %00000100
    ANSELA = %00000100      
    
    A VAR word 'Stores 10 Bit Analog Reading
    B var byte
    
    mainloop: 
    b = 0
    porta.4 = 1
    pause 250 
    porta.4 = 0
    HSERIN 250, test,[B] : Pause 50 
    goto mainloop		' Do it all over again
    
    test:
    ADCIN 2, A   'Grab analog input from pin3
    pause 250
    Hserout [#A,13,10]		' Send char out serial port
    porta.4 = 1
    pause 1000
    porta.4 = 0
    goto mainloop
    ok, it goes in blinks the led quick and starts the line of code for hserin then it jumps to the test loop runs the adc and sends to the pc and the led continues to blink at 1 sec intervals, it never does the quick led blink of the main loop when test loop led duration is longer. and im not sure if I have the HSERIN coded right, it was taken from other code I had working last year with another chip. the weird thing is, if I change the mainloop led to 1000 and the test loop to 250, it still blinks at the 1 sec rate????
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,104

    Default Re: HELP! HSER issues from old to new

    If it does not do the fast blink, that may imply that there is data on the Serial port. Even one character is enough to exit from the HSERIN loop.

    Maybe it is better to have a different LED port for the mainloop and another for the test loop.

    Ioannis

  11. #11
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262

    Default Re: HELP! HSER issues from old to new

    yes that would be good, but I have no pins left

    1 +
    2 Serial
    3 Serial
    4 Analog IN
    5 Clock
    6 LED
    7 Digital input only/MCLR (unused)
    8 -

    Can I use a led going from b+ to LED to 7 and use the chip to sink the LED current?
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  12. #12
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,104

    Default Re: HELP! HSER issues from old to new

    No, you cannot because this pin for the 12F1572 is only input.

    Ioannis

Similar Threads

  1. Need help with HSER on the 16F747
    By allanb in forum Serial
    Replies: 2
    Last Post: - 18th September 2013, 04:28
  2. HSER baudrate
    By pedja089 in forum Serial
    Replies: 14
    Last Post: - 7th August 2011, 19:46
  3. HSER Problems
    By Kaldurenik in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 15th October 2007, 08:33
  4. HSER with interrupts
    By ronjodu in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 25th February 2007, 20:19
  5. Hser-rx test
    By nicjo in forum Serial
    Replies: 0
    Last Post: - 26th November 2006, 09:53

Posting Permissions

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