Oilmex PIC-MT-USB and PIC16F877A


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Aug 2009
    Location
    Upstate New York
    Posts
    8

    Question Oilmex PIC-MT-USB and PIC16F877A

    I picked up PIC-MT-USB from Olmex, and have been totally unable to write a PICBASIC program that runs on it.

    For starters all I want to do light up the LED.

    To add to my embarassment, Olimex even publishes C code and the associated HEX. The hex code runs just fine. I have not been able to figure out how to .. Convert .. the C, or create my own code that can turn on the light.

    I am a newbie to MCUs (most of my programming skills are discrete TTL or CMOS), and have one simple project under my belt. This was the next step, but I am stuck.

    This is the link to the board: http://www.olimex.com/dev/pic-mt-usb.html

    Any experience or help welcome.

    Thanks!

  2. #2
    Join Date
    Mar 2008
    Location
    Gerogetown, Texas
    Posts
    94


    Did you find this post helpful? Yes | No

    Default

    Be sure to set the configuration to HS, the standard 877A.inc file is set to XT.
    Code:
    ;****************************************************************
    ;*  16F877A.INC                                                 *
    ;*                                                              *
    ;*  By        : Leonard Zerman, Jeff Schmoyer                   *
    ;*  Notice    : Copyright (c) 2003 microEngineering Labs, Inc.  *
    ;*              All Rights Reserved                             *
    ;*  Date      : 11/06/03                                        *
    ;*  Version   : 2.45                                            *
    ;*  Notes     :                                                 *
    ;****************************************************************
            NOLIST
        ifdef PM_USED
            LIST
            include 'M16F87xA.INC'  ; PM header
            device  pic16F877A, HS_osc, wdt_on, lvp_off, protect_off
            XALL
            NOLIST
        else
            LIST
            LIST p = 16F877A, r = dec, w = -302
            INCLUDE "P16F877A.INC"  ; MPASM  Header
            __config _HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF
            NOLIST
        endif
            LIST
    Here is the C code to blink the leds

    Code:
    #include <pic.h> 
    
    __CONFIG(UNPROTECT & PWRTEN & HS & BORDIS & WDTDIS & LVPDIS);
    
    #define		LED1		RB2
    #define		LED2		RB1
    
    //Just simple delay
    void Delay(unsigned long cntr) {
    	while (--cntr != 0);
    }
    
    int main(void) {
    
    	INTCON 	= 0x0;			// Disable inerupt
    	TRISB1 	= 0;			// Led1 pin as output
    	TRISB2 	= 0;			// Led2 pin as output
    
    
    	while(1) {
    		// led 1 on
    		LED1 = 1;
    		// led 2 off
    		LED2 = 0;
    		// Simple delay
    		Delay(50000);
    		// led 1 off
    		LED1 = 0;
    		// led 2 on
    		LED2 = 1;
    		// Simple delay
    		Delay(50000);
    	}
    
    }
    Here is a Picbasic translation

    Code:
    LED1   VAR PORTB.2
    LED2   VAR PORTB.1
    
    TRISB = %00000000
    
    Main:
    
    HIGH LED1
    LOW LED2
    Pause 500
    LOW LED1
    HIGH LED2
    Pause 500
    
    GOTO Main
    end
    Should work

    Good luck

  3. #3
    Join Date
    Aug 2009
    Location
    Upstate New York
    Posts
    8


    Did you find this post helpful? Yes | No

    Wink Oilmex board now blinks -thanks!

    "Be sure to set the configuration to HS, the standard 877A.inc file is set to XT."

    So I tired to compile the .inc file. THAT met with failure. Finally removed program(s) and reinstalled. the .inc file I found first was someting completely different.

    Finaly, with subborness that is only matched by my ignorance, I stumbled across the .inc file in the PBP directory, and replaced it with the code that was posted in the previous post, and then compiled and ran the code.

    Works great.

    So, my next quesiton has to do with how do I know when to change configuration from HS to XT?

    Clearly my education is lacking.. Pointers to where I can gain wisdom on the configuration files and need to change them would be welcom.

    Thanks again!

    Robert

  4. #4
    Join Date
    Mar 2008
    Location
    Gerogetown, Texas
    Posts
    94


    Did you find this post helpful? Yes | No

    Default

    Robert

    HS is 20 Mhz crystal or resonator
    XT is 4 Mhz crystal or resonator

    Take a look at your chips data sheet, it will become your best friend. The section under oscillator configurations will tell all.

    Have fun

  5. #5
    Join Date
    Aug 2009
    Location
    Upstate New York
    Posts
    8


    Did you find this post helpful? Yes | No

    Thumbs up Oscillator Settings..

    I don't think I spend more than two hours going over 232 pages of 16F87X informaion, and still not not come back with a clue. It's a little overwhelming, but, now with the pointer to the XT, LP or HS modes, I can spend a couple of hours understanding that little bit.

    Then there is the thought that even if I knew I had to change to HS mode, I would not have a clue how to do that without the first post. Maybe that's in the manual for the compiler, but I have not come across it yet.

    With the help of this group, I am sure to gain wistom quicly.

    I was even able to talk to the LC display, so yep, I AM having fun!

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


    Did you find this post helpful? Yes | No

    Default

    Hi taitny,
    OSC works sort of this way, remember the old axiom "speed costs money, how fast do you want to go" ? Sort the same here, "Speed costs energy, how fast do you want to go"?
    setting the OSC to XT gives the OSC less power to play with than HS does. and the settings that allow 32KC OCS give even less, generally you want HS if you go over 4mhz.
    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. USB-FTDI[UM232R] with PIC16f877a
    By bjox in forum USB
    Replies: 1
    Last Post: - 23rd February 2008, 22:40
  2. Usb X Pic16f877a
    By LLEEDD in forum USB
    Replies: 2
    Last Post: - 30th December 2007, 21:52

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