From c to pbp


Closed Thread
Results 1 to 13 of 13

Thread: From c to pbp

Hybrid View

  1. #1
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302

    Default From c to pbp

    How to change this code to picbasic pro.Also i want to use xtal 4MHZ
    Code:
    #include <16f84a.h>
    #fuses HS,NOWDT,PROTECT,PUT
    #use delay(clock=20000000) //one instruction=0.2us
    //////////////////////////// HS1YWN /////////////////////////////////
    
    void main()
    {
     int ltime;
     SET_TRIS_B(0x00);
      for (ltime=0;ltime<50;ltime++)
      {
        output_high(PIN_B7);
        delay_ms(50);
        output_low(PIN_B7);
        delay_ms(50);
      }
    
      while (TRUE)
      {
        output_b(0x01);
        delay_cycles(59);
        output_b(0x02);
        delay_cycles(59);
        output_b(0x41);
        delay_cycles(59);
        output_b(0x42);
        delay_cycles(59);
      }
    }
    /////////////////////// the end !! ////////////////////////////////////////

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default

    Here you go, 'unverified' code.
    Code:
    @ device PIC16f84, HS, NOWDT, PROTECT, PUT
    
    ltime  var  word
    PIN_B7 var PORTB.7
    
       TRISB = 0
       for ltime = 0 to 50
          PIN_B7 = 1
          pause 50
          PIN_B7 = 0
          pause 50
       next
    
       while (1)
          PORTB = 1
          pause_us(59)
          PORTB = 2
          pause_us(59)
          PORTB = $41
          pause_us(59)
          PORTB = $42
          pause_us(59)
       wend
    /////////////////////// the end !! ////////////////////////////////////////

  3. #3
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Default

    That was very nice of you, Jerson, to take the time to do that. I think I agree with your conversion - while I have no prior knowledge of C, I'm studying Java at the moment and starting to many similarities between them.

  4. #4
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Jerson View Post
    Here you go, 'unverified' code.
    Code:
    @ device PIC16f84, HS, NOWDT, PROTECT, PUT
    
    ltime  var  word
    PIN_B7 var PORTB.7
    
       TRISB = 0
       for ltime = 0 to 50
          PIN_B7 = 1
          pause 50
          PIN_B7 = 0
          pause 50
       next
    
       while (1)
          PORTB = 1
          pause_us(59)
          PORTB = 2
          pause_us(59)
          PORTB = $41
          pause_us(59)
          PORTB = $42
          pause_us(59)
       wend
    /////////////////////// the end !! ////////////////////////////////////////
    Thank you.I will try.

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    If you're going to convert this to produce the same timing at 4MHz, you'll
    need to use an assembler delay routine.

    At 20MHz, like the original C version, delay_cycles(59); gives you a delay of
    59 * 200nS instruction cycles. 59 * 200nS = 11.8uS.

    PAUSEUS at 4MHz is limited to a minimum delay period of 24uS, and with an
    instruction time of 1uS at 4MHz, you're still going to be off by a minimum of
    200nS.

    12uS is about as close as you can get to the original 11.8uS delay period.

    Code:
    '  For 4MHz use XT_OSC
       @ DEVICE PIC16F84A, XT_OSC,WDT_OFF,PROTECT_OFF,PWRT_ON
    
       DEFINE OSC 4
       ltime VAR BYTE
    
       GOTO Main
       
    PAUSE12:  ' CALL to here = 2uS  
    ASM
        GOTO $+1 ; 2uS
        GOTO $+1 ; 2uS
        GOTO $+1 ; 2uS
        GOTO $+1 ; 2uS
        RETURN   ; 2uS (12uS total delay time)
    ENDASM
    
    Main:
       TRISB = 0
       FOR ltime = 0 TO 49 ' 50 loops total
        PORTB.7 = 1
        PAUSE 50
        PORTB.7 = 0
        PAUSE 50
       NEXT ltime
    
       WHILE (1)
        PORTB = 1
        CALL PAUSE12
        PORTB = 2
        CALL PAUSE12
        PORTB = $41
        CALL PAUSE12
        PORTB = $42
        CALL PAUSE12
       WEND
    
       END
    This would give you very close to the same program & timing. The difference
    is the delay between port updates in the WHILE loop are 12uS VS 11.8uS.
    Last edited by Bruce; - 22nd July 2007 at 15:34.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Thank you.
    I want to test this code with Attached Image.
    At port.0 and port.1 must have 38khz and at port.6 must have 19khz
    Attached Images Attached Images  
    Last edited by savnik; - 22nd July 2007 at 16:19.

  7. #7
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by savnik View Post
    Thank you.
    I want to test this code with Attached Image.
    At port.0 and port.1 must have 38khz and at port.6 must have 19khz
    You may get the code to work but I dont see how that schematic is going to work if you are trying to build a stereo encoder for an FM transmitter.

    Both audio inputs are labelled as {RIGHT} sorry...R IN L IN {end of edit} instead of right and left and the circuit appears to just chop both inputs up at a rate of 38kHz. Presumably the PIC is outputing the two 38kHz signals out of phase otherwise you may as well use the same signal !!!

    FM broadcasts were designed to be Mono compatable so have a mono audio signal (L+R) with a difference signal (L-R) carried on a 38kHz subcarrier.

    The 19kHz carrier is to operate the pilot indicator in the receiver and switch on the demux to regenerate the original Left and Right signals from Mono + Side.

    http://www.irational.org/sic/radio/tech.html#Stereo

    gives a block schematic of a stereo encoder which is totally different from what your schematic seems to do.
    Last edited by keithdoxey; - 22nd July 2007 at 16:50. Reason: Looked at picture again and saw Mono in not just right!
    Keith

    www.diyha.co.uk
    www.kat5.tv

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. PBP, ASM and LST files
    By HenrikOlsson in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th January 2010, 13:43
  3. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  4. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30
  5. PBP / XP Crash
    By pondindustrial in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 27th November 2005, 03:16

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