PDA

View Full Version : Oilmex PIC-MT-USB and PIC16F877A



taitny
- 24th August 2009, 01:59
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!

DaveC3
- 24th August 2009, 04:13
Be sure to set the configuration to HS, the standard 877A.inc file is set to XT.


;************************************************* ***************
;* 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



#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




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

taitny
- 25th August 2009, 02:25
"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

DaveC3
- 25th August 2009, 02:40
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

taitny
- 26th August 2009, 02:36
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!

Archangel
- 26th August 2009, 05:05
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.

taitny
- 26th August 2009, 23:49
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

Bill Legge
- 27th August 2009, 02:30
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

mackrackit
- 27th August 2009, 03:13
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!!!

taitny
- 14th September 2009, 04:57
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!

mackrackit
- 14th September 2009, 05:25
Does the new board have an inverter chip? MAX232 for example.

taitny
- 15th September 2009, 03:43
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

mackrackit
- 15th September 2009, 04:09
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.

taitny
- 16th September 2009, 00:40
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/Sunday_Shoot/html/2008-06-01_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

mackrackit
- 16th September 2009, 02:16
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.