Shop OBEX P1 Docs P2 Docs Learn Events
Curious about PICs — Parallax Forums

Curious about PICs

blklightning21blklightning21 Posts: 2
edited 2010-06-16 20:57 in BASIC Stamp
Hi i am new to all of this but am very interested in working with and programming PICs. I was just wondering if starting with the parallax basic stamp 2 would be a good starting point to get going in that direction. Any help and input would be very much appreciated.

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2010-06-13 06:45
    If your interest is in Microchip PICs AND you want to use a Basic language then yes a Basic Stamp can help. Once you learn the Basic Stamp, you can move to PicBasic Pro, which is a compiler for the PIC chips. It is quite similar to the PBasic that is used with the Basic Stamps.

    Most everything you will learn with the Basic Stamps can be applied to programming with PicBasic Pro. In fact, in their forum, they will reference Parallax documentation quite often as a learning resource.

    Rich H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.
  • $WMc%$WMc% Posts: 1,884
    edited 2010-06-13 06:50
    blklightning21

    I feel this is the best place to start, But don't take my word for it. Look around the Parallax forums and then go look at some of the other forums.

    I thing the choice will be obvious

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there············___$WMc%___···························· BoogerWoods, FL. USA


    want speed?·want·to use the Propeller?·want to stay with BASIC___www.propbasic.com___


    You can feel stupid by asking a stupid question or You can be really·stupid by not asking at all.

    ·
  • blklightning21blklightning21 Posts: 2
    edited 2010-06-13 09:08
    Well thanks alot guys for being so nice and answering my question. I am really interested in programming microchips because i really want the knowledge to build my own game controllers and the like. Really excited to start researching the threads and getting some hands on experience
  • bill190bill190 Posts: 769
    edited 2010-06-13 14:45
    I would suggest starting with the Basic Stamp. Make many different projects connecting resistors, transistors, LED's, and other chips to the Stamp. These projects have complete instructions in the documentation.

    Here is a simple Basic Stamp program to turn on an LED...

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    OUT0 = 1
    OUTPUT 0

    Then move on to the Parallax Propeller chip. Learn the hardware. Learn how the system clock works and how you can set it to different speeds. Learn about the counters and how to set these up. These are very much like the hundreds of Pic "register settings". Learn to program in Spin language, then learn to program in assembly. Then I think there is a C language·compiler for the Propeller, learn to program with that. The Propeller is very well documented and you can get a ton of help on these forums. Same as the Stamp.

    Here is a simple Propeller program to blink some LED's...

    PUB Toggle
    · dira[noparse][[/noparse]27]~~
    · repeat
    ··· outa[noparse][[/noparse]27] := 1
    ··· waitcnt(650_000 + cnt)
    ··· outa[noparse][[/noparse]27] := 0
    ··· waitcnt(11_500_000 + cnt)

    Here is a simple Propeller program in assembly...

    VAR

    long StackSpaceSendBits[noparse][[/noparse]6]

    pub CogTest

    cognew(@SendBits, @StackSpaceSendBits) 'Launch new cogSendBits

    DAT

    ORG 0········

    SendBits
    ······· or dira, TestPin0
    ······· or outa, TestPin0

    TestPin0 long %0000_0000_0000_0000__0000_0001_0000_1001

    Then everything about Pic programming I see on the internet is in C language or assembly language. And you can·have sections·of assembly programming within a Pic C program -·some things are best done in assembly. You need to understand how the hardware works with a Pic. There are hundreds of register settings for this and that. Pics have "interrupts" and for some things you need to know how this works - all to do with the design of the hardware of the specific chip. Then to really know what you are doing, you would need to read a typically 400 page data sheet on the microcontroller (hardware) and read a several hundred page user manual·for the C compiler, then be able to poke around the C libraries and function source code to learn how things work. With C the documentation is the programming!

    Here is a simple Pic C program which toggles some LED's (Lots of settings!)...

    #include <p18f4550.h>
    #include <delays.h>

    //******************************************************************************
    //Configuration bits

    // 20 MHz oscillator input
    // CPU = 48 MHz
    // USB = 48 MHz

    · //PLL Prescaler Selection bits:
    · #pragma config· PLLDIV = 5···· ·//Divide by 5 (20 MHz oscillator input)

    · //CPU System Clock Postscaler:
    · #pragma config· CPUDIV = OSC1_PLL2·//[noparse][[/noparse]OSC1/OSC2 Src: /1][noparse][[/noparse]96 MHz PLL Src: /2] (= 48 MHz CPU Clock)

    · //USB Clock Selection bit (used in Full Speed USB mode only; UCFG:FSEN = 1):
    · #pragma config· USBDIV = 2···· //USB clock source comes from the 96 MHz PLL divided by 2 = 48 MHz, FSEN = 1

    · //Oscillator Selection bits:
    · #pragma config· FOSC = HSPLL_HS··//HS oscillator, PLL enabled, HS used by USB

    · //Fail-Safe Clock Monitor Enable bit:
    · #pragma config· FCMEN = OFF··· ·//Fail-Safe Clock Monitor disabled

    · // Two-Speed Start-up
    · //Internal/External Oscillator Switchover bit:
    · #pragma config· IESO = ON····· ·//Oscillator Switchover mode enabled (Two-Speed Start-up)

    · //Power-up Timer Enable bit:
    · #pragma config· PWRT = OFF···· ·//PWRT disabled

    · // Pins VDD
    · //Brown-out Reset Enable bits:
    · #pragma config· BOR = ON_ACTIVE·//Brown-out Reset enabled in hardware only and disabled in Sleep

    · //Brown-out Voltage bits:···· Brown-out Reset Voltage/Min Typ Max Units
    · #pragma config· BORV = 3······ ·//Minimum setting· 2.00 2.05 2.16 V

    · // Pins VUSB
    · //USB Voltage Regulator Enable bit:
    · #pragma config· VREGEN = OFF·· ·//USB voltage regulator disabled

    · //Watchdog Timer Enable bit:
    · #pragma config· WDT = OFF····· ·//HW Disabled - SW Controlled

    · //Watchdog Timer Postscale Select bits:
    · #pragma config· WDTPS = 32768· ·//1:32768

    · // Pins MCLR/VPP/RE3
    · //MCLR Pin Enable bit:
    · #pragma config· MCLRE = ON···· ·//MCLR pin enabled; RE3 input pin disabled

    · //Low-Power Timer 1 Oscillator Enable bit:
    · #pragma config· LPT1OSC = OFF· ·//Timer1 configured for higher power operation
    ·
    · // Pins RB6/KBI2/PGC*, RB7/KBI3/PGD*
    · //PORTB A/D Enable bit:
    · #pragma config· PBADEN = OFF·· ·//PORTB<4:0> pins are configured as digital I/O on Reset

    · // Pins RC1/T1OSI/CCP2/UOE, RB3/AN9/CCP2/VPO*
    · //CCP2 MUX bit:
    · #pragma config· CCP2MX = ON··· ·//CCP2 input/output is multiplexed with RC1

    · //Stack Full/Underflow Reset Enable bit:
    · #pragma config· STVREN = ON··· ·//Stack full/underflow will cause Reset

    · // Pins MCLR/VPP/RE3, RB5/KBI1/PGM
    · //Single-Supply ICSP Enable bit:
    · #pragma config· LVP = OFF····· ·//Single-Supply ICSP disabled

    · // Pins (44 pin only) NC/ICCK/ICPGC, NC/ICDT/ICPGD, NC/ICRST/ICVPP, NC/ICPORTS
    · //Dedicated In-Circuit Debug/Programming Port (ICPORT) Enable bit:
    · #pragma config· ICPRT = OFF··· ·//ICPORT disabled

    · //Extended Instruction Set Enable bit:
    · #pragma config· XINST = OFF··· ·//Instruction set extension and Indexed Addressing mode disabled (Legacy mode)

    · // Pins RB6/KBI2/PGC, RB7/KBI3/PGD
    · //Background Debugger Enable bit:
    · #pragma config· DEBUG = OFF··· ·//Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins

    · //Code Protection bit Block 0:
    · #pragma config· CP0 = OFF····· ·//Block 0 (000800-001FFFh) not code-protected

    · //Code Protection bit Block 1:
    · #pragma config· CP1 = OFF····· ·//Block 1 (002000-003FFFh) not code-protected

    · //Code Protection bit Block 2:
    · #pragma config· CP2 = OFF····· ·//Block 2 (004000-005FFFh) not code-protected

    · //Code Protection bit Block 3:
    · #pragma config· CP3 = OFF····· ·//Block 3 (006000-007FFFh) not code-protected

    · //Boot Block Code Protection bit:
    · #pragma config· CPB = OFF····· ·//Boot block (000000-0007FFh) not code-protected

    · //Data EEPROM Code Protection bit:
    · #pragma config· CPD = OFF····· ·//Data EEPROM not code-protected

    · //Write Protection bit Block 0:
    · #pragma config· WRT0 = OFF···· ·//Block 0 (000800-001FFFh) not write-protected

    · //Write Protection bit Block 1:
    · #pragma config· WRT1 = OFF···· ·//Block 1 (002000-003FFFh) not write-protected

    · //Write Protection bit Block 2:
    · #pragma config· WRT2 = OFF···· ·//Block 2 (004000-005FFFh) not write-protected

    · //Write Protection bit Block 3:
    · #pragma config· WRT3 = OFF···· ·//Block 3 (006000-007FFFh) not write-protected

    · //Boot Block Write Protection bit:
    · #pragma config· WRTB = OFF···· ·//Boot block (000000-0007FFh) not write-protected

    · //Configuration Register Write Protection bit:
    · #pragma config· WRTC = OFF···· ·//Configuration registers (300000-3000FFh) not write-protected

    · //Data EEPROM Write Protection bit:
    · #pragma config· WRTD = OFF···· ·//Data EEPROM not write-protected

    · //Table Read Protection bit Block 0:
    · #pragma config· EBTR0 = OFF··· ·//Block 0 (000800-001FFFh) not protected from table reads executed in other blocks

    · //Table Read Protection bit Block 1:
    · #pragma config· EBTR1 = OFF··· ·//Block 1 (002000-003FFFh) not protected from table reads executed in other blocks

    · //Table Read Protection bit Block 2:
    · #pragma config· EBTR2 = OFF··· ·//Block 2 (004000-005FFFh) not protected from table reads executed in other blocks

    · //Table Read Protection bit Block 3:
    · #pragma config· EBTR3 = OFF··· ·//Block 3 (006000-007FFFh) not protected from table reads executed in other blocks

    · //Boot Block Table Read Protection:
    · #pragma config· EBTRB = OFF··· ·//Boot block (000000-0007FFh) not protected from table reads executed in other blocks


    //******************************************************************************

    void main()
    {

    ·// Pin 0
    ·#define LEDPin LATAbits.LATA0 ··//Define LEDPin as PORT A Pin 1
    ·#define LEDTris TRISAbits.TRISA0 ··//Define LEDTris as TRISA Pin 1

    ·// Pin 1
    ·#define LEDPin1 LATAbits.LATA1
    ·#define LEDTris1 TRISAbits.TRISA1

    ·#define LPin25 LATCbits.LATC6
    ·#define TPin25 TRISCbits.TRISC6

    ·#define LPin21 LATDbits.LATD2
    ·#define TPin21 TRISDbits.TRISD2

    LEDTris = 0··;//Set LED Pin data direction to OUTPUT
    LEDPin = 1··;//Set LED Pin

    LEDTris1 = 0;
    LEDPin1 = 0;

    TPin21 = 0;
    LPin21 = 0;

    TPin25 = 0;
    LPin25 = 0;

    while(1)
    {
    LEDPin = ~LEDPin;··//Toggle LED Pin
    LEDPin1 = ~LEDPin1;·//Toggle LED Pin

    LPin21 = ~LPin21;
    LPin25 = ~LPin25;

    ·Delay10KTCYx(255)·;·//0 to 255 Delay 250K cycles (1 second at 1MHz since each instruction takes 4 cycles)
    ·Delay10KTCYx(255);
    ·Delay10KTCYx(255);
    ·Delay10KTCYx(255);
    ·Delay10KTCYx(255);
    ·Delay10KTCYx(255);
    ·Delay10KTCYx(255);

    }

    }
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2010-06-14 05:46
    The BS2 combined with the "What's a Microcontroller" kit will help you learn general microcontroller programming concepts, as well as skills specific to the BS2 line on products. It won't help you learn _specifically_ about PICs.

    PICs are simply one type of microcontroller out of many different varieties from several manufacturers. The BS2 is not really a microcontroller, but more accurately a small computer that contains a microcontroller. It is commonly referred to as a microcontroller module. Of the seven modules in the BS2 lineup, only one contains a Microchip PIC chip - the base BS2. All others contain a Ubicom SX28 or SX48.

    The thing common to all of the BS2 modules is that the on-board microcontroller is pre-programmed with the Parallax PBasic interpreter. This interpreter runs byte codes that are created & loaded by the PBasic editior from the PBasic code that you write. As such, the PBasic interpereter provides a layer of abstraction that keeps you from programming the on-board microcontroller directly. The benefit here is ease of programming. The negative is less hardware control, as well as lower overall performance as measured in "instructions per second".

    What this ultimately means is that while the BS2 is a great starting point to learn microcontroller concepts, it may not be the best choice for your ultimate goals. If your project needs exceed the capability of the BS2 series, you'll need to look at something else.

    As for the something else... Parallax also has the SX & Propeller chips, in standalone form, or as inexpensive protoboards. These chips are a bit less beginner friendly than the BS2 series, but can provide much more performance than the BS2. Another possibility, although a non-Parallax product, is the Arduino, which is designed to be relatively beginner friendly. You can blink an LED in C/C++ with a lot less code than posted above for the PIC. You might also want to look at the game development systems developed by Andre LaMothe over at www.xgamestation.com. They may be more than what you're looking for, but if you are interested in game development, especially from the hardware perspective, I think you'll something interesting there.
  • LeonLeon Posts: 7,620
    edited 2010-06-14 10:17
    You don't need all that code simply to flash an LED with a PIC. Here is a simpler example:

    /*
    ** test.c
    ** Flashes LED on RA2 (pin 6)
    */
    
    #include <p18f1220.h>
    
    #pragma config OSC = HS
    #pragma config WDT = OFF
    
    
    void dly(void);
    
    void main (void)
    {
    
        LATA = 0;
        ADCON1 = 0x7F;
        TRISAbits.TRISA2 = 0;
    
        while (1)
        {
            LATAbits.LATA2 = 0;
            dly();
            LATAbits.LATA2 = 1;
            dly();
        }
        
    }
    
    void dly(void)
    {
        int i;
    
        for (i = 0; i < 10000; i++)
            ;
    }
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Leon Heller
    Amateur radio callsign: G1HSM
  • PrettybirdPrettybird Posts: 269
    edited 2010-06-15 17:58
    · Parallax has the best support for sure.
  • LeonLeon Posts: 7,620
    edited 2010-06-15 18:06
    Microchip support is pretty good. When I had a problem with an ICD 2 debugger that was several years old, I received a free replacement the next morning. I recently found a bug in the latest release of MPLAB, reported it, and received a development version that fixed the bug in a couple of days.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Leon Heller
    Amateur radio callsign: G1HSM
  • JaimeJaime Posts: 16
    edited 2010-06-16 20:57
    I have worked with the PIC18F873, PIC16F84A there are lots of Application Notes about several topics, you build the circuits, run the software and work
    flawlessly, Microchip literature is superb, in the other hand..Basic Stamp support is very good, they never leave you in the middle of the road..

    Jaime

    microwaveteach@hotmail.com
Sign In or Register to comment.