Getting SERIN2 to work?


Closed Thread
Results 1 to 12 of 12

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    My hat's off to you Bob, I don't know where you found that, it's not in the manual that I can find . . . But it works! I've spent 1/2 the night trying to make it work some other way and NADA. You have earned your keep, fixing your own problem . . . Thanks for the lesson !
    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.

  2. #2
    Join Date
    Jan 2009
    Location
    Delaware
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Correction on resistor values TX and RX

    I looked at the resistors that I used successfully. My previous post was in error with regard to the resistor value used in the TX line from the PIC. I used a 10k, not a 1k. I don't know if a 1k will work in the TX line, but I know the 10k works.

    I still use the 1k in the RX line to the PIC, though.

    I am next going to install an RS232 converter to avoid all this resistor roulette!

    Best regards to all,
    Bob

  3. #3
    Join Date
    Feb 2006
    Posts
    21


    Did you find this post helpful? Yes | No

    Default Try Hserin Hserout

    Bob,

    I've used the ubiquitous MAX232 to a PC RS232 port with success in an automated tester using Hserin and Hserout. I'm jumping on on this cause I use the PIC16F876A also.
    The DB9 on this end is Female so you can use a standard male to female cable to the PC.
    Here's some syntax and I'll drop in the related schematic. I have it set at 4800 baud, but I'm sure it'll run much faster. I deleted a bunch of stuff from the diagram, but I left the ISP hookup, as well as the reset button.

    This bit of code will wait for *T from the PC, run the TECH subroutine, then after sending the A/D results, waits for 3 numbers, converts them into decimal, uses that for the PWM value, then waits for FN to go on it's way.
    The formating stuff in the HSEROUT code is to pad 0s cause the PC (running Labview) was looking for precisely 3 bytes at that point.

    Code:
    DEFINE OSC 8'  		        USE 8MHZ CRYSTAL OSC.			
    DEFINE ADC_BITS 10'	        +VREF= 2VDC 1 = .00195V OR ~ 2MV
    DEFINE ADC_SAMPLEUS 50'   SAMPLE TIME .1MS
    DEFINE CCP1_REG PORTC' 		Hpwm channel 1 pin port		
    DEFINE CCP1_BIT 2' 		    Hpwm channel 1 pin bit		 
    DEFINE CCP2_REG PORTC'		Hpwm channel 2 pin port		 
    DEFINE CCP2_BIT 1'		    Hpwm channel 2 pin bit		 
    DEFINE HSER_RCSTA 90h'	Set RECIEVE Enabled     
    DEFINE HSER_TXSTA 24h'	Set XMIT Enabled HS     
    DEFINE HSER_BAUD 4800'		IL1700 BAUD RATE		 
    DEFINE HSER_CLROERR 1'		CLEAR OVER RUN ERRORS		 
    DEFINE CHAR_PACING 1000'	CHAR PACING(uSEC) TO 1MS		 
    TRISA=%00001111'	SET UP PORTA I/O (1=IN,0=OUT)		 
    TRISB=%11001000'	SET UP PORTB I/O 			 
    TRISC=%10000000'	SET UP PORTC I/O			 
    ADCON1=%10100101'	USE PORTA.3 PIN5 AS VREF+ @ 2.0VDC 	 
    ADCON0=%01000000'	A/D OFF -- RIGHT JUSTIFY. 6MSB=0 ADRESH	
     HSERIN[WAIT("*"),BUNDONE]
            IF BUNDONE = "T" THEN GOTO TECH ' T FOR TECH
    
    TECH:'                  ****************  TECH ************
    '
    BLEDOUT = 0'		          TURN BLUE LED ON
    HPWM 1, BLUELVL, 5000'		    CCP1=BLUE SET CURRENT		
    ADCON0 = %01001101'	              BLUE ADC		
    ADCIN 1, BLUSNS'                             READ IT				
    BLEDOUT = 1'		          TURN BLUE OFF			
    RLEDOUT = 0'			   TURN RED ON
    HPWM 2, REDLVL, 5000'		   CCP2 =RED SET CURRENT	
    ADCON0=%01000001'		 RED A/D		
    ADCIN 0, REDSNS:REDSNS=REDSNS MIN 999	
    RLEDOUT = 1'			    TURN RED OFF
    'HPWM 1, 0, 5000'          STOP PWM 
    'HPWM 2, 0, 5000 
    IF BLUELVL <10 THEN
    HSEROUT["00",DEC BLUELVL]:GOTO RED1
    ENDIF
    IF BLUELVL <100 THEN
    HSEROUT["0",DEC BLUELVL]:GOTO RED1
    ELSE
    HSEROUT [DEC BLUELVL]
    ENDIF
    GOTO RED1
    RED1:
     IF REDLVL <10 THEN '           FORMATING
    HSEROUT["00",DEC REDLVL]:GOTO BLU1
    ENDIF
     IF REDLVL <100 THEN
    HSEROUT["0",DEC REDLVL]:GOTO BLU1
    ELSE
    HSEROUT [DEC REDLVL]
     ENDIF
    GOTO BLU1
    BLU1:
        IF BLUSNS <10 THEN
        HSEROUT["00",DEC BLUSNS]:GOTO RED2
        ENDIF
        IF BLUSNS <100 THEN
        HSEROUT["0",DEC BLUSNS]:GOTO RED2
        ELSE
        HSEROUT [DEC BLUSNS]
        ENDIF
    GOTO RED2
    RED2:
         IF REDSNS <10 THEN
        HSEROUT["00",DEC REDSNS]:GOTO WAITF
        ENDIF
        IF REDSNS <100 THEN
        HSEROUT["0",DEC REDSNS]:GOTO WAITF
        ELSE
        HSEROUT [DEC REDSNS]
         ENDIF
    GOTO WAITF
    WAITF:
    HSERIN [WAIT ("F"),EFF]
    IF EFF = "N" THEN 
    GOTO BEGIN
        ELSE
         GOTO BLULEDSET
          ENDIF
        GOTO TECH
    BLULEDSET:'----------------------SET BLUE--------------------------
    HSERIN [WAIT("@"),STR INCOM\3]
    INCOM[0] = (INCOM[0]-"0") '
    INCOM[1] = (INCOM[1]-"0") ' Convert to decimal
    INCOM[2] = (INCOM[2]-"0") 
    X = 0 '                     RESET THE VARIABLE             
    X = X + INCOM[0] * 100 
    X = X + INCOM[1] * 10 
    X = X + INCOM[2]
    BLUELVL = (X MIN 255)
    X = 0
        HPWM 1, BLUELVL, 5000'		   CCP1  AND SET CURRENT
    Then more of the same for the Red channel.
    I hope this helps, and I pasted everything correctly!

    Bron
    Attached Images Attached Images  
    The less you expect, the more you get.

Similar Threads

  1. GPS $GPRMC to PIC16F684. Need help with SERIN2
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th November 2009, 09:47
  2. SERIN2 digit parsing
    By skimask in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th January 2007, 23:15
  3. with 40 MHZ osc serin2 not work
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th August 2006, 22:56
  4. SEROUT2 and SERIN2 commands
    By bangunprayogi in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th August 2005, 09:03
  5. Pin RA4 doesn't work
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 15th July 2004, 12:03

Members who have read this thread : 2

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