+ Reply to Thread
Results 1 to 3 of 3

Thread: C to PICbasic

  1. #1
    .nanaa's Avatar
    .nanaa Guest

    Unhappy C to PICbasic

    I have a .c code but I need to convert it to .hex, 'cause I want to do a Bi-color led project using the PIC 16F84...something like 4 led's blinking according with the functions.

    The .c code :


    //include file
    #include <pic.h>

    //16F84 configuration
    __CONFIG(0x3FF1);

    //portb macro
    #define PORTBIT(adr, bit) ((unsigned)(&adr)*8+(bit))

    //portb pin assignment
    static bit LED0 @ PORTBIT(PORTB, 0);
    static bit LED1 @ PORTBIT(PORTB, 1);
    static bit LED2 @ PORTBIT(PORTB, 2);
    static bit LED3 @ PORTBIT(PORTB, 3);
    static bit LED4 @ PORTBIT(PORTB, 4);
    static bit LED5 @ PORTBIT(PORTB, 5);
    static bit LED6 @ PORTBIT(PORTB, 6);
    static bit LED7 @ PORTBIT(PORTB, 7);

    //global variables
    unsigned int i; //for loop pause
    unsigned int c; //for loop event loop

    //functions
    void pause_action(); //pause
    void blink_redgreen(); //blink red then green
    void blink_baf(); //blink red and green back and forth
    void alt_blink(); //every other red then green
    void blink_sequence(); //blinks red one at a time
    //end functions

    //main function
    void main(void)
    {
    TRISB = 0x00;
    PORTB = 0b00000000;

    while(1)
    {

    blink_redgreen();
    blink_baf();
    alt_blink();
    blink_sequence();

    };

    }
    //end main function

    void pause_action()
    {

    for(i=0; i<4000; i++);
    for(i=0; i<4000; i++);
    for(i=0; i<4000; i++);
    for(i=0; i<4000; i++);
    for(i=0; i<4000; i++);
    for(i=0; i<4000; i++);

    };

    void blink_redgreen()
    {

    for(c=0; c<10; c++)
    {

    PORTB = 0b10101010;
    pause_action();

    PORTB = 0b01010101;
    pause_action();

    };

    };

    void blink_baf()
    {

    for(c=0; c<10; c++)
    {

    PORTB = 0b10100101;
    pause_action();

    PORTB = 0b01011010;
    pause_action();

    };

    };

    void alt_blink()
    {

    for(c=0; c<10; c++)
    {

    PORTB = 0b10011001;
    pause_action();

    PORTB = 0b01100110;
    pause_action();

    };

    };

    void blink_sequence()
    {

    for(c=0; c<10; c++)
    {

    PORTB = 0b10010101;
    pause_action();

    PORTB = 0b01100101;
    pause_action();

    PORTB = 0b01011001;
    pause_action();

    PORTB = 0b01010110;
    pause_action();

    };

    };



    Thanks for any help.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,910

    Default

    Sorry only Basic here!

    Look for the C forum of your compiler.

    Ioannis

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    Should be something like
    Code:
    C var byte
    TRISB = 0
    PORTB = 0
    
    Main
    	gosub blink_redgreen
    	gosub blink_baf
    	gosub alt_blink
    	gosub blink_sequence
    	goto Main
    
    
    pause_action:
    	pause 500 ' arbitrary delay... 500 mSec here
    	return
    
    
    blink_redgreen:
    	for c=0 to 9
    		PORTB = %10101010
    		gosub pause_action
    		PORTB = %01010101
    		gosub pause_action
    
    		next
    	return
    
    blink_baf:
    	for c=0 to 9
    		PORTB = %10100101
    		gosub pause_action
    		PORTB = %01011010
    		gosub pause_action
    		next
    	return
    
    alt_blink:
    	for c=0 to 9
    		PORTB = %10011001
    		gosub pause_action
    		PORTB = %01100110
    		gosub pause_action
    		next
    	return
    
    blink_sequence:
    	for c=0 to 9
    		PORTB = %10010101
    		gosub pause_action
    		PORTB = %01100101
    		gosub pause_action
    		PORTB = %01011001
    		gosub pause_action
    		PORTB = %01010110
    		gosub pause_action
    		next
    	return
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. How to configure SPI in PICBASIC PRO?
    By moogle in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 15th April 2007, 18:31
  2. Picbasic VS C Compiler
    By koossa in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 11th October 2005, 21:44
  3. Replies: 22
    Last Post: - 12th July 2005, 17:39
  4. PicBasic Fundamentals
    By Billyc in forum General
    Replies: 9
    Last Post: - 4th May 2004, 10:04
  5. PicBasic Pro & PicBasic syntax different
    By Billyc in forum General
    Replies: 5
    Last Post: - 16th April 2004, 21:19

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

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