|
|
View previous topic :: View next topic |
Author |
Message |
Atma
Joined: 08 Aug 2005 Posts: 22
|
programming the PIC16F873 device |
Posted: Mon Aug 08, 2005 3:38 am |
|
|
Hi
I have a project where i have to create a software package and a programmer in order to program the PIC16F873 device. I plan to use C# to create the software package. Does anyone have any ideas on how i can go about creating the software? I have been looking at the PIC programming specification guide and i feel that i am suppose to be following the guidelines there including the steps and the flow charts such as loading data, reading data eitc but am not sure. Does anyone know how i can go about solving this problem? Please help i am in desparate need of help.
Thank you |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Aug 08, 2005 5:26 am |
|
|
Can you give us a bit more details on the programming of the PIC? Is the PIC to be programmed just one time (factory) or also in the field (customer/service engineer)?
For field updates many projects use a piece of software called bootloader, use this as a keyword on this forum and Google and you will find many examples and explanations.
As a starting point for bootloaders in the PIC I can recommend you to have a look at the Tiny bootloader |
|
|
Atma
Joined: 08 Aug 2005 Posts: 22
|
programming the PIC16F873 device |
Posted: Mon Aug 08, 2005 5:36 am |
|
|
ckielstra wrote: | Can you give us a bit more details on the programming of the PIC? Is the PIC to be programmed just one time (factory) or also in the field (customer/service engineer)?
For field updates many projects use a piece of software called bootloader, use this as a keyword on this forum and Google and you will find many examples and explanations.
As a starting point for bootloaders in the PIC I can recommend you to have a look at the Tiny bootloader |
hi there
thanks for your reply
the PIC16F873 is a flash device that i am suppose to be able to program. the PIC should be programmed just once using the software package that i am suppose to create. its in a factory situation. I have to build my own hardware for the PIC and my own software as well. I was thinking that in regards with the programming, i can use MPLAB to compile the code that is suppose to be placed onto the PIC and convert it into a hex file and then after that use my created software package to program the PIC device with hex file.
i dont know if that makes more sense on what i am suppose to do. I want to use C# but I dont know if the language will have all these functionalities. Do you have any idea how i can start?
thanks again. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Mon Aug 08, 2005 6:29 am |
|
|
Quote: |
the PIC16F873 is a flash device that i am suppose to be able to program. the PIC should be programmed just once using the software package that i am suppose to create.
|
Just buy a regular PIC Programmer, and life will smile you ! ! !
http://www.ccsinfo.com/machx.shtml
Humberto |
|
|
Atma
Joined: 08 Aug 2005 Posts: 22
|
|
Posted: Mon Aug 08, 2005 6:32 am |
|
|
Humberto wrote: | Quote: |
the PIC16F873 is a flash device that i am suppose to be able to program. the PIC should be programmed just once using the software package that i am suppose to create.
|
Just buy a regular PIC Programmer, and life will smile you ! ! !
http://www.ccsinfo.com/machx.shtml
Humberto |
i wish that i could do that but this is my final year project and in order to pass, i need to build the stuff by myself
thats why i require help |
|
|
Ttelmah Guest
|
|
Posted: Mon Aug 08, 2005 6:54 am |
|
|
On the MicroChip website, you will find the programming details. Look for 'PIC16F87X EEPROM programming specification', and seperately, 'In-Circuit serial programming (ICSP) guide'. The former covers the general programming of the chip, while the latter covers the specifics of doing it 'in circuit'.
You are going to need to write a program to decode the .hex file (web search on the Intel hex format), and output the required hardware signals to put the chip into programming mode, and transfer the data to it. This would be easy on older OS's, and was commonly done by attaching logic to the parallel port, but on Windows NT or latter (W2K, & WXP), the hardware protection will prevent this being done. Hence you will need to consider either having another PIC to take the data over an RS232 serial link, and generate the programming signals (this is how most programmers actually do it), or have to override the protection (write a full 32bit driver to do the transfer, or 'bodge' round, with something like 'porttalk'...).
Personally, I'd probably look at doing it with a PIC. A little board with a RS232 connector, and a RJ connetor that goes to a header on the target board, and the software involved at the PC end, is 'nil'. You could just send the file with hyperterminal as a text file, and have the board receive the data, decode each line, use RTS/CTS, to control the transmission, and operate the required lines to transfer each line of th hex file into the target machine. assuming you have access to a programmer already, it is the easiest solution.
Best Wishes |
|
|
Atma
Joined: 08 Aug 2005 Posts: 22
|
programming a PIC with another PIC |
Posted: Mon Sep 05, 2005 3:38 am |
|
|
Ttelmah wrote: | On the MicroChip website, you will find the programming details. Look for 'PIC16F87X EEPROM programming specification', and seperately, 'In-Circuit serial programming (ICSP) guide'. The former covers the general programming of the chip, while the latter covers the specifics of doing it 'in circuit'.
You are going to need to write a program to decode the .hex file (web search on the Intel hex format), and output the required hardware signals to put the chip into programming mode, and transfer the data to it. This would be easy on older OS's, and was commonly done by attaching logic to the parallel port, but on Windows NT or latter (W2K, & WXP), the hardware protection will prevent this being done. Hence you will need to consider either having another PIC to take the data over an RS232 serial link, and generate the programming signals (this is how most programmers actually do it), or have to override the protection (write a full 32bit driver to do the transfer, or 'bodge' round, with something like 'porttalk'...).
Personally, I'd probably look at doing it with a PIC. A little board with a RS232 connector, and a RJ connetor that goes to a header on the target board, and the software involved at the PC end, is 'nil'. You could just send the file with hyperterminal as a text file, and have the board receive the data, decode each line, use RTS/CTS, to control the transmission, and operate the required lines to transfer each line of th hex file into the target machine. assuming you have access to a programmer already, it is the easiest solution.
Best Wishes |
hi there
thanks for your reply. it seems that what you mentioned is exactly the way that my lecturer wants me to do my project. he wants me to use one PIC to program another PIC. now the way i see it is that i need to have some code written in C on the first PIC(thats going to program the target PIC). i have been reading the specification guides for the pic16F873 devices and i presume that the code that i have on the first PIC should be able to erase, read, write, verify etc the EEPROM memory and the flash memory of the target PIC. i have wriiten some code in C that will do the above.Is that assumption correct? am i on the right track?
Another thing is that I have connected the first PIC's I/O pins to the target PIC's MCLR, VDD, VSS, RB6 and RB7 pins and that means that i have to write some code that will deal with these pins and toggle them. How do i go about doing that?
Thanks again for all your help. |
|
|
Ttelmah Guest
|
|
Posted: Mon Sep 05, 2005 6:41 am |
|
|
Spot on.
You now need to split the design into two parts. The first is a system to receive a line of a file from the PC, and decode it. The second is the code to use this data to program the target PIC.
I'd work on the second part first. Have a structure defined something like:
Code: |
struct data_to_program {
int16 address;
int8 b[128];
} prog_buf;
|
Now the first half of the program, should receive the line, decode it, write this into the structure, when 128bytes have been received, turn off the receive (handshaking line to stop the transmission from the PC temporarily), and then call the code to actually program the PIC with this data. It can then re-enable receive, and loop for the next line, working through the whole hex file.
You can write the second half first, by having a temporary 'main', which loads a known line of data into this structure, then calls the 'program' routine. Use the professional programmer to see if this has written correctly.
Now the heart of the program routine, is the desciption given in the MicroChip data sheet 39025f.pdf. You need to work through this writing the code for the 'programmer'. So if you look at section 2.4, it says that you put the chip into programming mode, by holding RB6, and RB7 low, while raising the MCLR line.
So if you have got the line connected to your 'master' PIC, as (for example):
MCLR - PIN_B0
RB6 - PIN_B1
RB7 - PIN_B2
I'd probably define the pin names, to make the code easier to read, so:
#define MCLR PIN_B0
#define RB6 PIN_B1
#define RB7 PIN_B2
Then this part would become:
output_low(RB6);
output_low(RB7);
output_high(MCLR);
At this point the chip will be switched to programming mode.
The same logic will need to be followed for every part of the data sheet. You will need to clock out each word in turn, with instructions to erase, set an address, write, and read back (to verify). Once you have the programming code written, you can decide whether to have the decoding of th hex file in the PIC, or possibly to decode this in the PC, and just send the data as a sort of 'raw block'. Personally I'd probably include the hex decoding in the PIC, but this will be down to taste...
Best Wishes |
|
|
Guest
|
|
Posted: Mon Sep 05, 2005 9:13 am |
|
|
Ttelmah wrote: | Spot on.
You now need to split the design into two parts. The first is a system to receive a line of a file from the PC, and decode it. The second is the code to use this data to program the target PIC.
I'd work on the second part first. Have a structure defined something like:
Code: |
struct data_to_program {
int16 address;
int8 b[128];
} prog_buf;
|
Now the first half of the program, should receive the line, decode it, write this into the structure, when 128bytes have been received, turn off the receive (handshaking line to stop the transmission from the PC temporarily), and then call the code to actually program the PIC with this data. It can then re-enable receive, and loop for the next line, working through the whole hex file.
You can write the second half first, by having a temporary 'main', which loads a known line of data into this structure, then calls the 'program' routine. Use the professional programmer to see if this has written correctly.
Now the heart of the program routine, is the desciption given in the MicroChip data sheet 39025f.pdf. You need to work through this writing the code for the 'programmer'. So if you look at section 2.4, it says that you put the chip into programming mode, by holding RB6, and RB7 low, while raising the MCLR line.
So if you have got the line connected to your 'master' PIC, as (for example):
MCLR - PIN_B0
RB6 - PIN_B1
RB7 - PIN_B2
I'd probably define the pin names, to make the code easier to read, so:
#define MCLR PIN_B0
#define RB6 PIN_B1
#define RB7 PIN_B2
Then this part would become:
output_low(RB6);
output_low(RB7);
output_high(MCLR);
At this point the chip will be switched to programming mode.
The same logic will need to be followed for every part of the data sheet. You will need to clock out each word in turn, with instructions to erase, set an address, write, and read back (to verify). Once you have the programming code written, you can decide whether to have the decoding of th hex file in the PIC, or possibly to decode this in the PC, and just send the data as a sort of 'raw block'. Personally I'd probably include the hex decoding in the PIC, but this will be down to taste...
Best Wishes |
thank you so much for that explanation.. it really makes the understanding much much easier. the compiler that i have at the moment is the cc5x compiler. when i try to do the output_low stuff(was just trying it out), it refuses the syntax.it says that output_low is undefined. do you know what syntax i could use. another thing is that do you know if the ccs compiler is downloadable from anywhere since thats what most of the code that i find on the web is linked to. do you know if there is any easy to use better compiler?
when you say MCLR - PIN_B0, you basically mean that the MCLR of the target PIC is connected to the PIN_B0(I/O pin right)of the programming PIC right?
So sorry if the questions sound a bit dumb.
Thanks a lot again for your help. |
|
|
Guest
|
|
Posted: Mon Sep 05, 2005 9:14 am |
|
|
Ttelmah wrote: | Spot on.
You now need to split the design into two parts. The first is a system to receive a line of a file from the PC, and decode it. The second is the code to use this data to program the target PIC.
I'd work on the second part first. Have a structure defined something like:
Code: |
struct data_to_program {
int16 address;
int8 b[128];
} prog_buf;
|
Now the first half of the program, should receive the line, decode it, write this into the structure, when 128bytes have been received, turn off the receive (handshaking line to stop the transmission from the PC temporarily), and then call the code to actually program the PIC with this data. It can then re-enable receive, and loop for the next line, working through the whole hex file.
You can write the second half first, by having a temporary 'main', which loads a known line of data into this structure, then calls the 'program' routine. Use the professional programmer to see if this has written correctly.
Now the heart of the program routine, is the desciption given in the MicroChip data sheet 39025f.pdf. You need to work through this writing the code for the 'programmer'. So if you look at section 2.4, it says that you put the chip into programming mode, by holding RB6, and RB7 low, while raising the MCLR line.
So if you have got the line connected to your 'master' PIC, as (for example):
MCLR - PIN_B0
RB6 - PIN_B1
RB7 - PIN_B2
I'd probably define the pin names, to make the code easier to read, so:
#define MCLR PIN_B0
#define RB6 PIN_B1
#define RB7 PIN_B2
Then this part would become:
output_low(RB6);
output_low(RB7);
output_high(MCLR);
At this point the chip will be switched to programming mode.
The same logic will need to be followed for every part of the data sheet. You will need to clock out each word in turn, with instructions to erase, set an address, write, and read back (to verify). Once you have the programming code written, you can decide whether to have the decoding of th hex file in the PIC, or possibly to decode this in the PC, and just send the data as a sort of 'raw block'. Personally I'd probably include the hex decoding in the PIC, but this will be down to taste...
Best Wishes |
thank you so much for that explanation.. it really makes the understanding much much easier. the compiler that i have at the moment is the cc5x compiler. when i try to do the output_low stuff(was just trying it out), it refuses the syntax.it says that output_low is undefined. do you know what syntax i could use. another thing is that do you know if the ccs compiler is downloadable from anywhere since thats what most of the code that i find on the web is linked to. do you know if there is any easy to use better compiler?
when you say MCLR - PIN_B0, you basically mean that the MCLR of the target PIC is connected to the PIN_B0(I/O pin right)of the programming PIC right?
So sorry if the questions sound a bit dumb.
Thanks a lot again for your help. |
|
|
Atma
Joined: 08 Aug 2005 Posts: 22
|
in regards with the previous post |
Posted: Mon Sep 05, 2005 9:16 am |
|
|
hi sorry...forgot to log in when i posted the previous post. the previosu post was mine. can you please have a look at it. thanks heaps
thanks again for all your help. |
|
|
Atma
Joined: 08 Aug 2005 Posts: 22
|
|
Posted: Sat Oct 08, 2005 1:02 pm |
|
|
Ttelmah wrote: | Spot on.
You now need to split the design into two parts. The first is a system to receive a line of a file from the PC, and decode it. The second is the code to use this data to program the target PIC.
I'd work on the second part first. Have a structure defined something like:
Code: |
struct data_to_program {
int16 address;
int8 b[128];
} prog_buf;
|
Now the first half of the program, should receive the line, decode it, write this into the structure, when 128bytes have been received, turn off the receive (handshaking line to stop the transmission from the PC temporarily), and then call the code to actually program the PIC with this data. It can then re-enable receive, and loop for the next line, working through the whole hex file.
You can write the second half first, by having a temporary 'main', which loads a known line of data into this structure, then calls the 'program' routine. Use the professional programmer to see if this has written correctly.
Now the heart of the program routine, is the desciption given in the MicroChip data sheet 39025f.pdf. You need to work through this writing the code for the 'programmer'. So if you look at section 2.4, it says that you put the chip into programming mode, by holding RB6, and RB7 low, while raising the MCLR line.
So if you have got the line connected to your 'master' PIC, as (for example):
MCLR - PIN_B0
RB6 - PIN_B1
RB7 - PIN_B2
I'd probably define the pin names, to make the code easier to read, so:
#define MCLR PIN_B0
#define RB6 PIN_B1
#define RB7 PIN_B2
Then this part would become:
output_low(RB6);
output_low(RB7);
output_high(MCLR);
At this point the chip will be switched to programming mode.
The same logic will need to be followed for every part of the data sheet. You will need to clock out each word in turn, with instructions to erase, set an address, write, and read back (to verify). Once you have the programming code written, you can decide whether to have the decoding of th hex file in the PIC, or possibly to decode this in the PC, and just send the data as a sort of 'raw block'. Personally I'd probably include the hex decoding in the PIC, but this will be down to taste...
Best Wishes |
hi there
thanks so much for that explanation.. I manged to write code that would be able to program, verify, erase and read from the target PIC on to the programming PIC. the only thing is that the code is not totally complete. Is there anyway that i can check if the code is doing what its suppose to be doing? I am still working on the serial communication part of the coding..
Another thing is how do i get to load a hex file on to the target chip? where do i go from here?
thanks |
|
|
Atma
Joined: 08 Aug 2005 Posts: 22
|
|
Posted: Sat Oct 08, 2005 1:02 pm |
|
|
Ttelmah wrote: | Spot on.
You now need to split the design into two parts. The first is a system to receive a line of a file from the PC, and decode it. The second is the code to use this data to program the target PIC.
I'd work on the second part first. Have a structure defined something like:
Code: |
struct data_to_program {
int16 address;
int8 b[128];
} prog_buf;
|
Now the first half of the program, should receive the line, decode it, write this into the structure, when 128bytes have been received, turn off the receive (handshaking line to stop the transmission from the PC temporarily), and then call the code to actually program the PIC with this data. It can then re-enable receive, and loop for the next line, working through the whole hex file.
You can write the second half first, by having a temporary 'main', which loads a known line of data into this structure, then calls the 'program' routine. Use the professional programmer to see if this has written correctly.
Now the heart of the program routine, is the desciption given in the MicroChip data sheet 39025f.pdf. You need to work through this writing the code for the 'programmer'. So if you look at section 2.4, it says that you put the chip into programming mode, by holding RB6, and RB7 low, while raising the MCLR line.
So if you have got the line connected to your 'master' PIC, as (for example):
MCLR - PIN_B0
RB6 - PIN_B1
RB7 - PIN_B2
I'd probably define the pin names, to make the code easier to read, so:
#define MCLR PIN_B0
#define RB6 PIN_B1
#define RB7 PIN_B2
Then this part would become:
output_low(RB6);
output_low(RB7);
output_high(MCLR);
At this point the chip will be switched to programming mode.
The same logic will need to be followed for every part of the data sheet. You will need to clock out each word in turn, with instructions to erase, set an address, write, and read back (to verify). Once you have the programming code written, you can decide whether to have the decoding of th hex file in the PIC, or possibly to decode this in the PC, and just send the data as a sort of 'raw block'. Personally I'd probably include the hex decoding in the PIC, but this will be down to taste...
Best Wishes |
hi there
thanks so much for that explanation.. I manged to write code that would be able to program, verify, erase and read from the target PIC on to the programming PIC. the only thing is that the code is not totally complete. Is there anyway that i can check if the code is doing what its suppose to be doing? I am still working on the serial communication part of the coding..
Another thing is how do i get to load a hex file on to the target chip? where do i go from here?
thanks |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|