View: 7686|Reply: 27
|
how to start with PIC???
[Copy link]
|
meera83 This user has been deleted
|
i would like to use PIC16F877A, I already download the datasheet..
if i choose to use programming C++, what should i start to do in order want to write a program for the chip???
what the relation between PIC16F877A and MPLab and C++?? :hmm:
so confusing since my Programming not so good..:geram: |
|
|
|
|
|
|
|
hmm, I've never used PIC before. I'm an AVR guy (atmel microcontrollers).
well, basically, PIC or AVR etc are programmable chips. so you need to write the program. You can choose to write in assembly, or other languages. when you compile it, you'll have some files with machine language in it. you then write the file (program) the chip by connecting your pc to the programmer board where the chip sits.
if you wanna use C or C++, most of the time you'll have to pay for the cross-compiler. but i'm sure there are also free open source ones. I personally recommend using assembly language, because it's as close as it can be to the machine language (low level language). using that you can know very well how efficient your program is.
I'm sure the datasheet is pretty thick. You don't need to read all that. Just read whatever you need to know for your application.
http://www.microchip.com/stellen ... p;dDocName=en027853
that's an example of a development board (or programmer). you can find cheap ones, or expensive ones, or even build your own, if you know how. but you need it. I spent well over US$200 on my kit.
so if you wanna write in C++, you first need to find a cross compiler. this is one example.
http://www.sourceboost.com/Products/Products.html
this is the one from Microchip. maybe it can do C++ too.
http://www.microchip.com/stellen ... p;dDocName=en019469
i've never used PIC, so I don't know exactly how to do it. if you use AVRs like AtMega or AtTiny I may be able to help better. |
|
|
|
|
|
|
meera83 This user has been deleted
|
Originally posted by BeanDiesel at 21-12-2006 12:57 PM
hmm, I've never used PIC before. I'm an AVR guy (atmel microcontrollers).
well, basically, PIC or AVR etc are programmable chips. so you need to write the program. You can choose to write in as ...
i have a few question.
i have install Turbo C++ for writting the program. then, is it i need to install MPLAB??
is it i can directly use Turbo C++ to write program without MPLAB?
in Turbo C++, when we run the program, the software can automaticly change the assembly language to machine language,right??then is it i don't need to pay for compiler??
for the PIC, our University already have the interface board for transfering the program to chip, i think i don't need to buy it.. |
|
|
|
|
|
|
meera83 This user has been deleted
|
i now blur blur in how to start in writting the program..
i want to write program contain:
first: part A, take the output from a chip,for example the output is 0010.
second: part B--microcontroller, microcontroller will be store first the infomation like oooo store in address 1 will light up the first LED at part C chip. 0010 store at address 2 will light up second LED at part C chip..and so on.
when part B read the output from part A--0010, then it will compare 0010 with information inside each adress, when he found a matching at address 2, then the second LED will turn on..
i have no idea about the squential in wirting program for a microcontroller.
there are a lot of memory location EPROM,EEPROM,REGISTER...for the chip, then where should i store the program?? and where should the information for each address like 0000,0010 store for?? |
|
|
|
|
|
|
|
Originally posted by meera83 at 12/20/06 09:53 PM
i have a few question.
i have install Turbo C++ for writting the program. then, is it i need to install MPLAB??
is it i can directly use Turbo C++ to write program without MPLAB?
in Turbo C++, when we run the program, the software can automaticly change the assembly language to machine language,right??then is it i don't need to pay for compiler??
for the PIC, our University already have the interface board for transfering the program to chip, i think i don't need to buy it..
in that case you should use PIC. I used AVR because my school doesn't have it. the EE or CS department may have it, but ME department sure doesn't.
ok. I have never used Turbo C++, or at least i dont remember using it. yes, a compiler like Turbo C++ will compile your script into machine language, but i'm guessing that it's intended for Windows machine machine language. so that you can run it in windows. machine language differs from machine to machine, just like assembly language. i dont know if there's a plug in that you can install to Turboo C++ so that it will compile to PIC language.
well, since your school has the development board, someone must know how to use it. you might want to ask them for help. |
|
|
|
|
|
|
|
Originally posted by meera83 at 12/20/06 10:11 PM
i now blur blur in how to start in writting the program..
i want to write program contain:
first: part A, take the output from a chip,for example the output is 0010.
second: part B--microcontroller, microcontroller will be store first the infomation like oooo store in address 1 will light up the first LED at part C chip. 0010 store at address 2 will light up second LED at part C chip..and so on.
when part B read the output from part A--0010, then it will compare 0010 with information inside each adress, when he found a matching at address 2, then the second LED will turn on..
i have no idea about the squential in wirting program for a microcontroller.
there are a lot of memory location EPROM,EEPROM,REGISTER...for the chip, then where should i store the program?? and where should the information for each address like 0000,0010 store for??
first off, let me ask you, what is the chip you're talking about in Part A? the way i see it, it should be like this,
Switch/Keypad-->Microcontroller-->Audio Chip + Display
Let's assume that when a key is pressed, the keypad will output some kind of pattern to its output (some switches may output in BCD pattern which is a little easier to understand). Now, let's assume you are using a 40-pin microcontroller, which usually has 4 output ports. Let's say you use Port A to read the output of the keypad.
Your program has to run in a loop. You don't need to use interrupt since the program will be pretty short and your application is not really time critical. Each loop should take probably less than 100 microseconds. So you don't need to use interrupt funtion of the microcontroller.
Ok, the first thing that has to be done in the loop is to read the input of Port A. You will store this information in one or two registers. Register is like a variable, but you have limited number of registers. So, use them wisely. Like my program, I'll have to overwrite some registers in one loop multiple times. But I don't believe you have to do that.
So, now that you have the number in your register (usually in hex), you may need some kind of if-else statement. But before that, there may be some pulses that you have to send to the audio chip before you tell it which number to play right? so do that first. when it comes to telling the chip which number to play, do the if else statement.
that is, if the register value is equal to some number, it indicates that the user has pressed 1, else if it's equal to something else, the user pressed 2, else if......
for each if-else statement, something appropriate must be done. let's say for number 1, send appropriate signal to the chip telling it to play the sound for number 1. to communicate with the chip, you may want to use Port B for example. also, connect Port C for example to your 7-segment LED display. after sending the signal to the chip on which sound to play, send the LED some signal to display and latch it. keep it until the user release the key for example.
after that, you may (or may not, i don't remember exactly how the chip works) need to send some more signals to start the playback.
now, because the program will run very very fast, and the person who presses the key may not release it very quickly, you may want the program to wait until the user release the botton to restart the loop. so at the end of the loop, run a check on Port A to make sure that no button in pressed. if a button is pressed, hold. if not, go back to the beginning of the loop.
your program should be stored in Flash, not EEPROM. I usually use EEPROM to store something that I don't intend to change at all. For example, when I used to use LED instead of LCD display and drive it straight from my microcontroller, I store the map for the display in the EEPROM. For example, to display number 1, segments B and C of the display must be turned on. In binary form, it would be like 00000110. So I store 00000110 in the EEPROM location number $01. So when my calculation yields number 1, the program will check the EEPROM and obtain the display code from it. |
|
|
|
|
|
|
|
dude, you're doing the hard and long way. Its much much better to program a microcontroller using assembly language, especially when the PIC16F877a which is part of the PIC midrange MCUs which is RISC (Reduced Instruction Set Computer) which only comprise of 35 instructions in all. Yes, you can write any program with only using these 35 instructions. These instructions are found in the instruction set part of the 877 manual.
You use the freeware MPLAB(latest version 7.4) downloaded from www.microchip.com to write your assembly language program. Then , using the same software, you can change the assembly language program to machine code (or what we call a hex file). Next, download another freeware called IC Prog. This software will allow you to download (or burn) the hex file into the microcontroller flash memory(most MCUs today use flash memory, not eproms). The hardware used to download the hex file to the microcontroller is called a JDM programmer. The total cost to build the programmer is only about RM5, and the 877a costs about RM20 in Jalan Pasar. Simple as that. |
|
|
|
|
|
|
|
Originally posted by reinloch at 12/21/06 04:03 AM
dude, you're doing the hard and long way. Its much much better to program a microcontroller using assembly language, especially when the PIC16F877a which is part of the PIC midrange MCUs which is RISC (Reduced Instruction Set Computer) which only comprise of 35 instructions in all.
yes, I personally would go with assembly language. it's a lot more straight forward, and requires minimal software.
by the way, there's an electronic store at jalan pasar? what is it called? i've always been curious where to find these stuff in malaysia. |
|
|
|
|
|
|
meera83 This user has been deleted
|
what should i consider when i intend to download a compiler??
is it MPLab a compiler? then CCS also a compiler,right??
i just know that my school got a PIC 16F877A interface board for install the programming after i write it..
the compiler i choose is it need to consider what kind of interfce board i use?? |
|
|
|
|
|
|
meera83 This user has been deleted
|
Originally posted by BeanDiesel at 21-12-2006 09:04 PM
yes, I personally would go with assembly language. it's a lot more straight forward, and requires minimal software.
by the way, there's an electronic store at jalan pasar? what is it called? ...
two rows of shop along Jalan Pasar,KL 90% is Electric & Electronic component shop..
most of us like to directly look through E&E component here.. |
|
|
|
|
|
|
|
hmmm i used pic 16F and 18F family before ... and for the programming part, i prefer to use MPLAB (for 18F family) and WizC (for16F), The difference? MPLab uses C++ as its main language, which is hell l ot easier and of course the simulation function would help you a lot in your project. On the other hand, WizC uses assembly language .. easy but u need to concern abt the max size for ur whole codes since it requires more instructions.
How to start? Well ... for MPLab, there's a manual available from the site, which i think is very useful to help you with the codings. So, my advice is, go thru the MPLab manual first. |
|
|
|
|
|
|
meera83 This user has been deleted
|
Originally posted by youthgonewild at 23-12-2006 06:45 PM
hmmm i used pic 16F and 18F family before ... and for the programming part, i prefer to use MPLAB (for 18F family) and WizC (for16F), The difference? MPLab uses C++ as its main language, which is h ...
MPLab uses C++???
then is it i can directly use assembly language for MPLab?? |
|
|
|
|
|
|
|
Originally posted by meera83 at 12/23/06 08:47 AM
MPLab uses C++???
then is it i can directly use assembly language for MPLab??
if you can use C++ i don't see the reason to use assembly language. i think the whole point of using C++ is to avoid from using assembly language. i may be wrong though. |
|
|
|
|
|
|
|
Reply #1 meera83's post
meera this problem really connected to board programming.. so move it there k.. |
|
|
|
|
|
|
|
ahh, I'm back ^_^
anyways, BeanDiesel's question bout electronic stores at Jalan Pasar... yes, there's lot's of electronic stores there, but most of them have really small selections. Of the ones I frequent with large inventories, are Maplin and Nixie. Both are on Jalan Landak, really easy to get there, just jump on the Star LRT and drop off on the Pudu station, both shops just about a few hundred meters away. Nixie is just opposite Pudu Plaza, and Maplin is the second shop from when you turn into Jalan Landak from Jalan Pasar. Get a map, just in case :-) However, for special chips, which they don't stock at Jalan Pasar, its better to order from Farnell or RS, both located in PJ. You can check their catalog at http://my.farnell.com/jsp/home/homepage.jsp and http://www.rsmalaysia.com/cgi-bi ... ;cacheID=mynetscape respectively. But be warned though, it won't be very cheap since they're specially ordering stuff for you. I believe its best to just order from ebay... but not everyone have credit cards :_( ...
If you're not into making your own pic programmer, a reasonable alternative is here: http://www.cytron.com.my/index.asp
Yup, its operated by our very own UTM boys, and they have a nifty startup kit selling for RM60. The kit can also run from laptop usb, so now you can program on the go :-D
Now, bout Meera's question, the compiler is a translating program that translates high level languges (HLL) (e.g. C++) to assembly language, and an assembler is the program that changes assembly language instructions to machine code (located in a file with a ".hex" extension, which you can open with notepad and see the machine codes in hexadecimal). So, yes, MPALB is a compiler and an assembler at the same time. If you're referring to the Texas Instrument's CCS (Code Composer Studio), that also has an assembler... but its slightly different, since the device is a digital signal processor and not a microcontroller. However, the differences are only technical, such as the fact that dsp chips have extra powerful hardware multipliers and barrel shifters for example, that perform the filtering functions that are the main purposes of the devices. Their assembly language instructions are very much similar to microcontrollers... which is why i believe, once you've learnt the assembly language for one device, its easy to shift to a different device range since assembly languages are fundamentally similar, with the exception of some syntax discrepancies only. If you write a program in a HLL, what hapens when you comppile it, is that the single HLL line will be changed to many lines of assembly language instructions, which sometimes may not be very compact, since its done by a conversion table. When you write assembly language programs, with experience and intuition, it it much smaller than conversion from HLL and executes much faster too. But, what BeanDiesel says is corrrect, the main reason for C++ is to save time. Since new devices are introduced almost weekly, companies will have to pay their workers to learn the new syntaxes... a better way is just to teach them C++ once and then use C++ to write programs for the devices instead of the native device language, shortens the learning curve considerably.
The schematic for the JDM programmer: http://www.k9spud.com/jdm/schematic.html
The schematic above is for the 16F84a, the connections to the 16F877a and 18F452 are similar. Refer below:
http://www.ucapps.de/mbhp_jdm_expired.html
The software for these devices are ICprog at: http://www.ic-prog.com/
After you place your chip on the homemade programmer, and connect the programmer to your PC via serial port, you can download your program to the chip using the ICprog program by loading your .hex file into ICProg and clicking on "Program". Note that, the information in the sites above may be outdated.
I still recall the time when I built my first programmer, and the whole thing worked like magic ^_^
So, good luck on your programmer... Merry Xmas and a Happy New Year.
[ Last edited by reinloch at 24-12-2006 02:15 PM ] |
|
|
|
|
|
|
|
ko gune je software MICROC. tak pening sgt sbb ko ley refer contoh2 dlm library die.
microc pakai C language.
klu ko nk wt simulation ko pakai PROTEUS.
kalau kt proteus assembly n c language blh gune.
final projek ke nih? buat mobile robot ke? |
|
|
|
|
|
|
|
Originally posted by reinloch at 12/23/06 10:07 PM
ahh, I'm back ^_^
anyways, BeanDiesel's question bout electronic stores at Jalan Pasar... yes, there's lot's of electronic stores there, but most of them have really small selections. Of the one ...
wow, that's an excellent answer.
by the way, i've never realized the difference between an assembler and a compiler. well I'm a Mechanical Engineer, as long as it works, it's good enough for me. |
|
|
|
|
|
|
|
Originally posted by reinloch at 12/23/06 10:07 PM
Since new devices are introduced almost weekly, companies will have to pay their workers to learn the new syntaxes... a better way is just to teach them C++ once and then use C++ to write programs for the devices instead of the native device language, shortens the learning curve considerably.
I've never used C or C++ or other HLL to program a chip. but with assembly language, I know I have full control over the efficiency of my program. and from what I've heard, when every clock cycle matters, assembly language is the way to go, although it may not be as straightforward as HLL's. Would you agree to that? |
|
|
|
|
|
|
meera83 This user has been deleted
|
Originally posted by XkostonX at 24-12-2006 03:08 PM
ko gune je software MICROC. tak pening sgt sbb ko ley refer contoh2 dlm library die.
microc pakai C language.
klu ko nk wt simulation ko pakai PROTEUS.
kalau kt proteus assembly n c language bl ...
yap, this is my final year project..
not about mobile robot..
i m asking to design an interface which can read out what had been shown at four 7 segment display continuously.. |
|
|
|
|
|
|
| |
|