Oilmex PIC-MT-USB and PIC16F877A


Closed Thread
Results 1 to 15 of 15
  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.

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


    Did you find this post helpful? Yes | No

    Smile Looking for Newbie Book on PIC / PICBASIC

    It makes sense that higher speed takes more power, and it's really cool that they built in the functionality to allow making the trade off between speed and power.

    If I had an idiot's guide to the .INC file, it might have saved me some head banging.

    Anyone recommend a book that covers the subject?

    The he code that DaveC3 sent, offers me food for thought, and it enabled me to get my program running. It would be great if I could find a guide that explains each element of each line (sure some of the info is in the device manual), but I am open to literature that might be able to impart wisdom.

    Cheers!

    Taitny

  8. #8
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default Getting Started Olimex

    Hi,

    I started about 2 years ago - with a PIC16F877A and had partial success but kept coming across bits that I could not work out. So I:

    1. Got the simpler PIC16F84A chip.

    2. A 'development board' from Mikroelektronika (the EasyPIC5) - a bit pricey but it also handles the PIC16F877A. This has all the buttons, LEDs and other peripherals for quick learning/experimenting (get the LCD extra). It also minimises the chance of a wrong connection that can bugger up a learning session for days!

    Or, get the simpler board from Olimex 'PIC18 Board.' The name is a bit confusing because it caters for chips with 18 pins (like the PIC16F84A) not the PIC18F seriec of microcontrollers.

    3. Books that were helpful: 'Programming PIC Microcontrollers With PicBasic' by Chuck Hellebuyck. 'PicBasic Projects' by Dogan Ibrahim.

    4. Work through the exercises in the books.

    5. Work through the Microchip Spec for the PIC16F84.

    6. Download the Microchip integrated development environment (free) and do some assembler level programming to see the bits moving around.

    If the advice is misplaced - sorry.

    Regards Bill Legge

  9. #9
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by taitny View Post
    If I had an idiot's guide to the .INC file, it might have saved me some head banging.

    Anyone recommend a book that covers the subject?
    http://www.picbasic.co.uk/forum/showthread.php?t=11116

    I have said it before and I will say it again.

    Forget the books, read this forum ( the above link is a good start) and work through the samples on MeLabs web site. http://www.melabs.com/resources/samples.htm

    It seems that folks who have read the "book" still come here asking basic questions. So logic tells me the "book" is not much good. So you may as well start here on the forum and save some time.

    As for a starter PIC... Get one that has analog and comparators and learn how to use it. Turn the analog stuff off until you are ready for it. Starting off with an obsolete part does not make much sense. The 877A is a good place to start. It has plenty of I/Os for future bigger projects along with the analog when needed.

    Just my opinion.
    Good luck!!!
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Question Mystery sending data through serial port.

    On my 4 MHZ dev board I can send serial data just fine.
    When I move the chip to the Oilmex board with 20 MHZ clock, I get higher bit characters.
    This is what "Hello World" looks Like with coming from the Olimex
    The data rate looks to be 2400 baud (based on Oscope), but I can't get normal ASCII out.

    åë«::
    ú
    åë«::
    ú
    åë«::
    ú
    åë«::
    ú


    Here is the code:
    ' PicBasic Pro program to send a string to the serial port
    ' the hardware serial port

    'DEFINE OSC 4 'Works fine with a 4 MHZ system

    DEFINE OSC 20
    'on a 4 MHZ system it sends out data at 480 Baud just fine
    DEFINE HSER_BAUD 2400 ' Select the baud rate
    'Sends out high order bits on 20 MHZ system



    loop:
    Hserout ["Hello World", 13, 10] ' Send text followed by carriage return and linefeed
    pause 1000
    Goto loop ' Do it all over again

    End



    Any suggestion on what i need to do to fix this strange output?

    Thanks!

  11. #11
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Does the new board have an inverter chip? MAX232 for example.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Thumbs up Mystery sending data through serial port - DO'H

    Dave - it does NOT have the Max chip. The LAB-X1 DOES have the Max..

    I will ponder the ramificions of this.. I suspect setting parity to -1 is not the answer. Seemed to recall somehting about Invert in the compiler book .

    I went back to the book "Since the sereal transmission is sdone in hardware, it is not possible to set the levels to an invertes state to eleminate an RS-232 driver"

    I read that several times.. Suddenly it has meaning!

    It's got a FT232RL, wich convers USB to RS-232, no doubt with the right state. I tapped in after the chip directly to the MCU.

    Lookse like I need to add the MAX232, or switch development boards, although if you have a magic bullet, I am willing to listen..

    Thanks!

    Robert

  13. #13
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    No magic bullets... Mine are all Pb

    If you do not have a 232 chip and you feel adventerous it can be done with a transistor or two. Here is a good read. For that matter the whole site should be a must read for PICers.
    http://www.rentron.com/Micro-Bot/IR_Serial.htm

    When you order the 232 do not forget the capacitors that go with it.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Wink No magic bullets...

    Thanks for the pointer to the IR Serial. I will probably play with the MAX chip just to gain wisdom, but I do have all the transistors and realted hardware to go the other route.

    Odd think, it was Pb bullets that got me going down the PIC path. A co worker replaced my analog discrete 7400 series logic trigger board with a 16 pin PIC. And added some great features.

    This is one of the photographs that resulted:
    http://www.ohbah.com/~rt/strobe/Sund...17-49-10-1.htm

    So I decided it was time for me to hang up my TTL cookbook and try the MCU route.

    With help from folks like you, it's been fun

    Thanks!

    Robert

  15. #15
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    That was one heck of a shot !!!

    If you are not needing the the features of the hardware serial you can use SEROUT2 in an inverted mode. Same syntax, so it is easy to switch back to HSEROUT when you get the 232 chip or the hardware put togther.
    Dave
    Always wear safety glasses while programming.

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