Programming a microcontroller
Fig. 1: Circuit Diagram of 8051 Programmer
Please note while programming an 89SXX series of microcontroller the pin number of the target microcontroller are fixed and not of the master microcontroller. It is not necessary to use the MOSI, MISO and SCK pin of the master controller. Any pin could be used for the purpose. However for the target controller it has to be MOSI, MISO and SCK only.
Instruction Sets
Fig. 2: Table listing 8051 instructions to perform different operations during the programming process
The above table shows the instruction sets used to perform different operations during the programming process. Every instruction is made up of 4 bytes. When a particular instruction is received by the target microcontroller, the corresponding operation is performed.
Symbol
|
Parameter
|
Min
|
Typ
|
Max
|
Units
|
1 / tCLCL
|
Oscillator Frequency
|
3
|
|
33
|
MHz
|
tCLCL
|
Oscillator Period
|
30
|
|
|
ns
|
tSHSL
|
SCKPulseWidth High
|
8tCLCL
|
|
|
ns
|
tSLSH
|
SCKPulseWidth Low
|
8tCLCL
|
|
|
ns
|
tOVSH
|
MOSISetup toSCK High
|
tCLCL
|
|
|
ns
|
tSHOX
|
MOSIHold after SCKHigh
|
2tCLCL
|
|
|
ns
|
tSLIV
|
SCKLow to MISO Valid
|
10
|
16
|
32
|
ns
|
tERASE
|
Chip Erase Instruction Cycle Time
|
|
|
500
|
ms
|
tSWC
|
Serial Byte Write Cycle Time
|
|
|
64tCLCL+ 400
|
µs
|
Codes for various operatiions
sck=0;
bit=byte/128;
byte=byte<<1;
mosi=bit;
sck=1;
delay(1);
_nop_();
sck=0;
delay(1);
_nop_();
In order to send the next bit the same process is repeated.
sck=1;
delay(1);
_nop_();
data=data<<1;
if(miso==1)
data++;
sck=0;
delay(1);
_nop_();
Codes Contd..
The following is the code to send and receive a single bit to and from the target controller:
sck=0;
bit = byte/128;
byte=byte<<1;
mosi=bit;
sck=1;
delay(1);
_nop_();
data=data<<1;
if(miso==1)
data++;
sck=0;
delay(1);
_nop_();
Now let us see how an entire byte comprising of eight bits is sent and received serially to and from the target microcontroller.
sck=0;
for(i=0;i<8;i++)
{
bit = byte/128;
byte=byte<<1;
mosi=bit;
sck=1;
delay(1);
_nop_();
data=data<<1;
if(miso==1)
data++;
sck=0;
delay(1);
_nop_();
}
Filed Under: Tutorials
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.