pls help me convert C to PICBASIC


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Posts
    2

    Default pls help me convert C to PICBASIC

    please help me convert this C code to PICBASIC, it is using SPI protocol..

    Code:
    #define MaxSayisi 2
    
    void max6952_putchar(char reg,char data)
    {
    unsigned char dongu=1;
       PORTC.F0 = 0;
       for(dongu=1;dongu<=MaxSayisi;dongu++){
       SPI_WRITE(reg);
       SPI_WRITE(data);
    }
       PORTC.F0 = 1;
       PORTC.F0 = 0;
    
    }
    
    void MAX_6952_init(){
    
       max6952_putchar(0x04,0x01);  //Configuration
    
       max6952_putchar(0x01,0x0FF);
    
       max6952_putchar(0x02,0x0FF);
    
       max6952_putchar(0x03,0x01);
    
    }
    
    void main(){
    
       unsigned char dongu=1;
       char a[ ]="   ali raza  ";
       int i;
       TRISC=0B00011000;
       Spi_Init();
       MAX_6952_init();
       while(1)
       {
    
       for(i=0;i<=10;i++){
       max6952_putchar(0x20,a[i]);
       max6952_putchar(0x21,a[i+1]);
       max6952_putchar(0x22,a[i+2]);
       max6952_putchar(0x23,a[i+3]);
       delay_ms(500);
    }
    
    }
    
     }
    this i've done so far...
    Code:
    Device 16F877A
    XTAL = 20     
    ALL_DIGITAL = TRUE 
    Symbol CS = PORTC.4				' SPI eeprom CS line
    Symbol SCK = PORTC.3			' Clock pin
    Symbol SI = PORTC.5				' Data in pin
    Symbol SO = PORTC.5		
    Dim reg as BYTE
    Dim datas[10] as BYTE
    Dim dongu as BYTE
    
    MAX6952_Init:
        PORTC.0=0
    	FOR dongu = 1 to 2
    	Shout SI, SCK, MSBFIRST, [0x04]
    	Shout SI, SCK, MSBFIRST, [0x01] 
    	NEXT
    	PORTC.0=1
    	PORTC.0=0	
    	
    	PORTC.0=0
    	FOR dongu = 1 to 2
    	Shout SI, SCK, MSBFIRST, [0x01]
    	Shout SI, SCK, MSBFIRST, [0xFF] 
    	NEXT
    	PORTC.0=1
    	PORTC.0=0	
    	
    	PORTC.0=0
    	FOR dongu = 1 to 2
    	Shout SI, SCK, MSBFIRST, [0x02]
    	Shout SI, SCK, MSBFIRST, [0xFF] 
    	NEXT
    	PORTC.0=1
    	PORTC.0=0	
    	
    	PORTC.0=0
    	FOR dongu = 1 to 2
    	Shout SI, SCK, MSBFIRST, [0x03]
    	Shout SI, SCK, MSBFIRST, [0x01] 
    	NEXT
    	PORTC.0=1
    	PORTC.0=0	
    
    	Return
    max6952_putchar:
        PORTC.0=0
    	FOR dongu = 1 to 2
    	Shout SI, SCK, MSBFIRST, [reg]
    	Shout SI, SCK, MSBFIRST, [datas[0]] 
    	NEXT
    
    	PORTC.0=1
    	PORTC.0=0			
        
        Return
    
    Main:
    	TRISC=%010001100
    	Goto MAX6952_Init
    	reg=0x20
    	datas[0]="A"
    	Goto max6952_putchar
         Delayms 500
    Goto main
    I notice that PORTC.0 is not having output in Proteus when i use my PICBASIC code...

    is PORTC.F0 is PORTC.0 in PICBASIC?

    excuse me for my wrong grammar...
    thanks...

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


    Did you find this post helpful? Yes | No

    Default

    PBP <>Proteus
    PBP != Proteus
    Which is to say, PBP code is pretty much useless in Proteus and vice versa. This forum is for M E Labs Pic Basic, I am sure there is a Proteus forum if you check Google. If you get the correct compiler to use , I am sure you can get some help here.
    Best Regards,
    JS
    BTW, your grammar needs no excuse, it is quite acceptable.
    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.

  3. #3
    Join Date
    Dec 2008
    Posts
    2


    Did you find this post helpful? Yes | No

    Default

    I use Proton+ PICbasic from Crownhill, I use Proteus ISIS Professional as Simulator...

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by marcasjr View Post
    I use Proton+ PICbasic from Crownhill, I use Proteus ISIS Professional as Simulator...
    Proton <> PBP _ Crownhill sponsors their forum too, and also sells that compiler.
    Your Code as posted with my comments in red:
    Code:
    Device 16F877A
    XTAL = 20   <font color=red> DEFINE OSC 20</font color>  
    ALL_DIGITAL = TRUE  <font color=red> Not in PBP 
    
    The following will work but there are better ways.</font color>
    Symbol CS = PORTC.4		       ' SPI eeprom CS line
    Symbol SCK = PORTC.3		      ' Clock pin
    Symbol SI = PORTC.5			' Data in pin
    Symbol SO = PORTC.5		
    <font color=red> Like . . . 
    CS VAR PortC.4
    No Dims in PBP </font color>
    Dim reg as BYTE
    Dim datas[10] as BYTE
    Dim dongu as BYTE
    <font color=red> do it this way
    Dongu VAR BYTE
    Datas VAR BYTE[10]</font color>
    MAX6952_Init:
        PORTC.0=0
    	FOR dongu = 1 to 2
    	Shout SI, SCK, MSBFIRST, [0x04]
    	Shout SI, SCK, MSBFIRST, [0x01] 
    	NEXT
    	PORTC.0=1
    	PORTC.0=0	
    	
    	PORTC.0=0
    	FOR dongu = 1 to 2
    	Shout SI, SCK, MSBFIRST, [0x01]
    	Shout SI, SCK, MSBFIRST, [0xFF] 
    	NEXT
    	PORTC.0=1
    	PORTC.0=0	
    	
    	PORTC.0=0
    	FOR dongu = 1 to 2
    	Shout SI, SCK, MSBFIRST, [0x02]
    	Shout SI, SCK, MSBFIRST, [0xFF] 
    	NEXT
    	PORTC.0=1
    	PORTC.0=0	
    	
    	PORTC.0=0
    	FOR dongu = 1 to 2
    	Shout SI, SCK, MSBFIRST, [0x03]
    	Shout SI, SCK, MSBFIRST, [0x01] 
    	NEXT
    	PORTC.0=1
    	PORTC.0=0	
    
    	Return
    max6952_putchar:
        PORTC.0=0
    	FOR dongu = 1 to 2
    	Shout SI, SCK, MSBFIRST, [reg]
    	Shout SI, SCK, MSBFIRST, [datas[0]] 
    	NEXT
    
    	PORTC.0=1
    	PORTC.0=0			
        
        Return
    
    Main:
    	TRISC=%010001100
    	Goto MAX6952_Init
    	reg=0x20
    	datas[0]="A"
    	Goto max6952_putchar
         Delayms 500<font color=red> Nope! Pause 500</font color>
    Goto main
    That should give you something to chew on a while.
    Last edited by Archangel; - 7th December 2008 at 09:31.
    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.

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    Hi, Marcasjr

    You should switch to the other Crownhill forum, if you want to go on with PROTON ...

    Alain
    Last edited by Acetronics2; - 7th December 2008 at 09:27.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    It took me a minute to find it:
    http://www.picbasic.org/forum/
    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.

Similar Threads

  1. can anyone here can convert this in picbasic pro?
    By reianjim in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd December 2009, 11:43
  2. How to configure SPI in PICBASIC PRO?
    By moogle in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 15th April 2007, 18:31
  3. Picbasic VS C Compiler
    By koossa in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 11th October 2005, 21:44
  4. Replies: 22
    Last Post: - 12th July 2005, 17:39
  5. PicBasic Fundamentals
    By Billyc in forum General
    Replies: 9
    Last Post: - 4th May 2004, 10:04

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