Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 13th July 2005, 08:21 PM   (permalink)
Default 16F84 PIC stupid questions!

hello there

i am new to micro controllers specially the PIC's

i am so glad that a couple of seconds ago i foud out the MR Nigel Goodwin
is one of moderators at here because my questions are about a pic programmer that i built some of days ago from this web site:
http://chaokhun.kmitl.ac.th/~kswichit/f84/f84.htm

and the pic software is writen by MR Nigel.

anyway the pic programmer is good and i made it with no problem

now my biggest problem is that i am not familiar with the software and C language
i want to start with a ready circuit and a given code
but i have the following problems:

1: what is the difference between HEX files and source codes?
my mean is what i must do with them in the Nigel software?
i dont know i must use from bothe hex and source or one of them or each one...?
the source codes are based "C" language and i thought i should use from them with the nigel software but dont know what are the hex files so?

2: before writing to the pic micro what i must do at first?
Erasing, reading or...?

3:such as i know there is a button or any else thing the cause that the micro be burned after writing and after this we can not read or write into micro, so what is this button or... for the pic with Nigel software?

i think thats's enough for now, and i hope i could programming my 16f84 pic with your guides and helps

thanks for any input and really sory if my questions are stupid.
epilot is offline   Reply With Quote
Old 13th July 2005, 08:52 PM   (permalink)
Default Re: 16F84 PIC stupid questions!

Quote:
Originally Posted by epilot
hello there

i am new to micro controllers specially the PIC's

i am so glad that a couple of seconds ago i foud out the MR Nigel Goodwin
is one of moderators at here because my questions are about a pic programmer that i built some of days ago from this web site:
http://chaokhun.kmitl.ac.th/~kswichit/f84/f84.htm

and the pic software is writen by MR Nigel.

anyway the pic programmer is good and i made it with no problem

now my biggest problem is that i am not familiar with the software and C language
i want to start with a ready circuit and a given code
but i have the following problems:

1: what is the difference between HEX files and source codes?
my mean is what i must do with them in the Nigel software?
Source code is what YOU write, the assembler or compiler converts that to a HEX file, which is a text representation of the code that the PIC itself actually understands.

Quote:

i dont know i must use from bothe hex and source or one of them or each one...?
You write the source code, assemble or compile it to a HEX file, then load the HEX file into my programmer software and load it into the PIC.

Quote:

the source codes are based "C" language and i thought i should use from them with the nigel software but dont know what are the hex files so?
Most PIC code is in assembler, and I personally consider it VERY important to learn PIC assembler, without a reasonable knowledge of assembler you severely restrict the code you write using C or BASIC.

Quote:

2: before writing to the pic micro what i must do at first?
Erasing, reading or...?

3:such as i know there is a button or any else thing the cause that the micro be burned after writing and after this we can not read or write into micro, so what is this button or... for the pic with Nigel software?
With the common PIC's (either EEPROM or FLASH - like the 16F84), you can't do anything to stop them being usable (apart from obviously destroying them) - in all cases you can simply erase them and start again, even if read protected.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 13th July 2005, 09:31 PM   (permalink)
Default

ohh hello Nigel

thanks for the reply


such as i found out from your post so i can use from EACH source code or hex code depending on each one i have and if i use from source code in your software it would be converted to hex file by the software, and if i have the hex file i write it to your software and it would exchange to machine code. is this correct?
if so then the software do all thing wether i input the source code OR hex code? i hope i could understand your mean correctly


but what did you mean with this?
"You write the source code, assemble or compile it to a HEX file, then load the HEX file into my programmer software and load it into the PIC."

if i have a source cod i shoud put it in your software DIRECTLY or....?

can you please answer my "2" question i aske at my first post?

how i can burn the pics? my mean is i write into them and then protect them from reading and writing?

thanks
epilot is offline   Reply With Quote
Old 13th July 2005, 09:36 PM   (permalink)
Default

here's a hex file and a source code from A circuit with 16f84



:1000000000308A00AE2800000000F73065000030A4
:10001000051901300038031D0F2811141116D228BC
:100020008E0A3C300E02031C21288E018F0A3C30C0
:100030000F02031C21288F01900A183010020318A8
:100040009001D82814088900831608148312080820
:1000500095000A301502031C3328203015020318BE
:100060003328063095021A301502031C39280C304B
:1000700095020130140797001708890083160814A9
:100080008312080896000A301602031C4D282030FF
:10009000160203184D28063096021A301602031C69
:1000A00053280C30960200341108403900380319E7
:1000B0007C28940114088900831608148312080808
:1000C0008C000C0A03197C28222015081002031D3D
:1000D000792816080F02031D7928023014079700AB
:1000E000170889008316081483120808FF3A03389A
:1000F0008600033094075A28D92817308400000856
:1001000003198A2888280000000000000000000071
:10011000800B83289628930A12081302031D9A283D
:10012000003066000610643097007D2800306600BD
:1001300006149301DA281108013900380319AD2893
:100140003E30940022201508900016088F008E0182
:1001500011179112111003309200DB2884018301E2
:1001600004308C008C1DBC28073081018130840054
:100170000008C0390F388000640081308400000816
:10018000C0390C0480000030660006109101013077
:10019000920093018101123090008F018E010B19A2
:1001A000D3280528CF280B110030660086171028A9
:1001B00054288B289B28003066008613CF286300C4
:02400E00F83F79
:00000001FF
;PIC16F84













F84 Miniature Realtime Controller V1.0
// PIC16F84 LP Xtal 32768Hz runs rtc.c
// The RTC.C was compiled by PCW PIC C Compiler V2.266
// April 10,1999
// Copyright(C) 1999 Wichit Sirichote

#include <RTC.H>
#fuses LP,NOPROTECT,NOWDT // must include this line !!


// set clock to 19:00 when press set time button once
// change below for your convenient

#define setHour 19
#define setMin 0

// Scheduler format in eeprom
/*

address data
2100 19 00 04 19 01 00 FF FF as seen in Nigel's data memory
2108 FF FF FF FF FF FF FF FF window
...........
meaning

2100 19 ; set hour
2101 00 ; set min
2102 04 ; output byte to be sent to port_B, '1' turn on, '0' off
....
FF byte is end of stored PGM


output byte use '1' means turn the device on

RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0

OUTPUT NC 5 4 3 2 1 NC NC

NOTE! output byte seen in Nigel's EEPROM window must be HEXadecimal, e.g.
Suppose at 20:00 turn output 1 and 2 on, the output byte must be

0 0 0 0 1 1 0 0 = 0C


*/

// rename i/o devices

#define LED PIN_B0
#define KEY PIN_A2

// variables declaration
char sec,min,hour,flag1,rate,temp,i,A,B;

// Bit assignment of flag1
// mask byte effect
// 0x20 installation test on/off(0)
// 0x40 compare time enable bit(1)
// 0x10 blink disable (1)
// 0x01 button pressed (1)

time() // update clock every 1 second
{
sec++;
if ( sec >= 60)
{
sec = 0;
min++;
if ( min >= 60)
{
min = 0;
hour++;
if ( hour >= 24)
hour = 0;
}
}
}


// convert() function provides direct entering decimal value of preset
// time in 64 bytes eeprom data memory
// say, 19 00 04 ; when reach 19:00 turns RB2 on
// as seen by Nigel's PigPro16 eeprom window, 19 means 19h or 25d
// convert will substract 25 with 6 giving 19.
// similarly but substract with 12 if > 19, e.g., 20h or 32d convert
// function will give 32d - 12d = 20.

convert() // entry : index pointer i
// exit: A,B
{
A = read_eeprom(i);
if ((A > 0x09) && (A < 0x20))
A = A - 6; // convert 10h-19h to 10d-19d
if ( A> 0x19 )
A = A - 12; // convert 20h-23h to 20d-23d

B = read_eeprom(i+1);
if ((B > 0x09) && (B < 0x20))
B = B - 6;
if ( B > 0x19)
B= B - 12;
}


scan_PGM() // scan program saved in user eeprom
{

if((flag1 & 0x40) != 0) // allow entering only after S1 has been pressed
{
i = 0;
while( read_eeprom(i) != 0xff) // if not EOF (0xff) do
{
convert();
if (hour == A && min == B)
port_B = ~read_eeprom(i+2)|0x03; // fire output
i = i+3; // next address
}
}

}


setTime()
{
if ((flag1 & 0x01) != 0) //input(KEY)==0)
{
hour = setHour;
min = setMin;
sec = 0;
flag1 |= 0x40; // enable compare time
flag1 &= ~0x20; // reenable test on off
flag1 &= ~0x01; // clear key press bit
rate = 3;
}
}

blink() // turn LED on 100 ms
{
output_low(LED);
delay_ms(100);
output_high(LED);
}


fireLED()
{
temp++;
if ( temp == rate)
{
blink();
temp = 0;
}
}

chkKEY()
{
if(input(KEY)==0)
{flag1 |= 0x01; // set bit 0 telling key been pressed
flag1 |= 0x10; // disable firing LED
// output_high(LAMP); // turn on lamp when press button
}
}



main()
{

setup_counters(RTCC_INTERNAL,RTCC_DIV_32); // [32768/4]/32 = 256Hz

/* 256Hz clock will be counted by Timer, when it rolls from FF to 00
T0IF will then be set, in other word, one second has elapsed */

output_low(LED);
flag1 = 0;
rate = 1;
temp = 0;
tmr0 = 0;
hour = 18;
min = 0;
sec = 0;


while(1)
{
while(!bit_test(intcon,2))
chkKEY(); // check key S1 while T0IF = 0
bit_clear(intcon,2);

// the following tasks executed every 1 second
output_high(PIN_B7); // use RB7 for measuring tasks execution
time();
scan_PGM();
fireLED();
setTime();
output_low(PIN_B7);

}
}
epilot is offline   Reply With Quote
Old 14th July 2005, 06:45 AM   (permalink)
Default

Quote:
Originally Posted by epilot

but what did you mean with this?
"You write the source code, assemble or compile it to a HEX file, then load the HEX file into my programmer software and load it into the PIC."

if i have a source cod i shoud put it in your software DIRECTLY or....?
No, my software only reads HEX files, you need an assembler (MPLAB/MPASM is free) or a high level compiler like C or BASIC to create the HEX file.

Quote:

can you please answer my "2" question i aske at my first post?
You don't need to do anything except write to the PIC, the writing sequence starts by erasing the chip.

Quote:

how i can burn the pics? my mean is i write into them and then protect them from reading and writing?
You just click on the button in WinPicProg to write them, and if you want to "read protect" it you can set the code protect flag first, this then prevents the PIC being read by anyone else.

There's no write protection on a PIC (nor any need for it!).
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 14th July 2005, 08:35 AM   (permalink)
Default

When you enable the code protect does it just prevent the PIC from being read? I have not tried that feature yet.
__________________
I was born with nothing. And I still have most of it!
GatorGuy is offline   Reply With Quote
Old 14th July 2005, 08:50 AM   (permalink)
Default

Quote:
Originally Posted by GatorGuy
When you enable the code protect does it just prevent the PIC from being read? I have not tried that feature yet.
Yes, that's all it does, personally it's not a feature I've ever used much - for your own use you probably wouldn't either?.

If you DO use code protection, makes ABSOLUTELY SURE you have multiple copies (in different locations) of both your source code and HEX file - because you won't be able to recover the code from the PIC if you should lose your original code!.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 14th July 2005, 09:17 PM   (permalink)
Default

hi

ok thanks Nigel

so why your software has a part called " source code"?

i had some of problems when i put the above HEX files in your software while writing and has these errors while writing:
"program Verify failed on line 0, program aborted" or
"program Verify failed on line 8, program aborted"
i dont know wht is the problem really?

please i need for more help to write in my pic


how i can find out that my pic is the programed aftter programing?

if i read the pic micro with "READ PIC" after programing it what will happen?
what i will have aftter reading the pic? my before writings or...?



i am so sorry for my stupid questions but i need more and more help to go ahead
epilot is offline   Reply With Quote
Old 14th July 2005, 11:41 PM   (permalink)
Default

Quote:
Originally Posted by epilot
hi

ok thanks Nigel

so why your software has a part called " source code"?

i had some of problems when i put the above HEX files in your software while writing and has these errors while writing:
"program Verify failed on line 0, program aborted" or

"program Verify failed on line 8, program aborted"
i dont know wht is the problem really?
I've heard that this error is caused by low programming voltage on MCLR pin...
Quote:
please i need for more help to write in my pic


how i can find out that my pic is the programed aftter programing?

if i read the pic micro with "READ PIC" after programing it what will happen?
It should display your program .
Quote:

what i will have aftter reading the pic? my before writings or...?



i am so sorry for my stupid questions but i need more and more help to go ahead
Are you sure that you are using the correct voltages , because on the schematic it shows , a 17 V DC voltage going into a full wave rectifier IC..
williB is offline   Reply With Quote
Old 15th July 2005, 08:17 AM   (permalink)
Default

Quote:
Originally Posted by epilot
hi

ok thanks Nigel

so why your software has a part called " source code"?
Because it has an in-built disassembler, that can generate source code from a HEX file (or from the data read from a PIC).

Quote:

i had some of problems when i put the above HEX files in your software while writing and has these errors while writing:
"program Verify failed on line 0, program aborted" or
"program Verify failed on line 8, program aborted"
i dont know wht is the problem really?
As suggested, the most common cause is too low a voltage (or too much ripple) on the MCLR pin.

Quote:

please i need for more help to write in my pic


how i can find out that my pic is the programed aftter programing?
Pressing the 'Verify' button will check the contents against the loaded HEX file, it does this automatically during programming as well (unless you disable it?).

Quote:

if i read the pic micro with "READ PIC" after programing it what will happen?
what i will have aftter reading the pic? my before writings or...?
It simply reads the entire contents of the PIC, overwriting the contents of the programmer buffer, and displaying the contents of the PIC.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 15th July 2005, 10:01 AM   (permalink)
Default

ok i went to software option part and turned Vpp and VDD
on and measured the voltage on the MCLR and on the VDD
voltage on the MCLR =13.4V
voltage on the VDD = 4.9V

i used from a 18V transformer for the circuit(hardware)

i dont know what is the problem that i can not write to my pic and when i read it, it seems that my pic is empety. this means my codes never went in the pic!!? :cry:


such as you say Nigel , the software can generate source codes from hex file but cannot do the opposit way?

i dont know what is the problem, when i exchange $3BC port to $378
it comeback to $3BC port again!?
epilot is offline   Reply With Quote
Old 15th July 2005, 11:31 AM   (permalink)
Default

Quote:
Originally Posted by epilot
ok i went to software option part and turned Vpp and VDD
on and measured the voltage on the MCLR and on the VDD
voltage on the MCLR =13.4V
voltage on the VDD = 4.9V

i used from a 18V transformer for the circuit(hardware)
What do you mean?, do you mean a simple 18V AC mains transformer, or a wallwart that's 18V DC?. A wallwart may have too much hum or ripple, you would need a scope to check.

Quote:

i dont know what is the problem that i can not write to my pic and when i read it, it seems that my pic is empety. this means my codes never went in the pic!!? :cry:
You could try increasing the programming delay, the default setting is 10mS - try increasing to 12mS or 15mS.

Quote:

such as you say Nigel , the software can generate source codes from hex file but cannot do the opposit way?
Yes, there's no need for it the other way, MicroChip already supply an assembler called MPASM as part of MPLAB.

Quote:

i dont know what is the problem, when i exchange $3BC port to $378
it comeback to $3BC port again!?
WinPicProg automatically detects the programmer, so $3BC is obviously where it is.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 15th July 2005, 01:12 PM   (permalink)
Default

no i used from an AC 18V transformer with a full wave rectifier diode like the schematic

i think that two 87Lxx and capacitors connected to these ICs makes the ripples very limited

from where i can download MPASM or MPLAB?
if i have a "C" code what software i need for?

Nigel, i put that HEX file you see above at 4 post in a text document and opened it to the software and have no problem with this but when i push the Write pic button i get this error
"program Verify failed on line 0, program aborted"
please see the hex program, perhaps the problem is from the hex file?
epilot is offline   Reply With Quote
Old 15th July 2005, 03:42 PM   (permalink)
Default

Quote:
Originally Posted by epilot
no i used from an AC 18V transformer with a full wave rectifier diode like the schematic

i think that two 87Lxx and capacitors connected to these ICs makes the ripples very limited
Yes, that's fine! - but wallwarts often drop below the minimum input voltage of the regulators, and that's a common problem.

Quote:

from where i can download MPASM or MPLAB?
From MicroChip at http://www.microchip.com

Quote:

if i have a "C" code what software i need for?
You need a PIC C compiler, there are various versions available, you can usually get free limited test versions, no doubt people will make suggestions, I don't use C.

Quote:

Nigel, i put that HEX file you see above at 4 post in a text document and opened it to the software and have no problem with this but when i push the Write pic button i get this error
"program Verify failed on line 0, program aborted"
please see the hex program, perhaps the problem is from the hex file?
No, the HEX file can't cause the problem, if it's a valid HEX file and will load, the it should program.

I presume you have WinPicProg configured correctly for the programmer you're using?.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 15th July 2005, 07:02 PM   (permalink)
Default

i cheked the hardware again and it seems there is no problem with it

i dont know what is the problem and i am so confused now

the only thing that i think about is:
perhaps the problem is from the cable because my caple that goes to printer port has some of wires conected to ground and i assume that there are the problem but i am not sure if i must cut them or not
:cry: :? :? :?

Nigel, does your software works with all kind DIY pic programmer?

i want to built another kind, perhaps such as this:http://www.jdm.homepage.dk/newpics.htm

http://www.jdm.homepage.dk/easypic.htm
epilot is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes




All times are GMT. The time now is 05:24 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.