praveenrpk92
Newbie level 6
Hi, I'm trying to design an ISP programmer for AT89S52. I'm using 2 Microcontrollers, controller 1 has chip erase code in it & I have successfully erased controller 2. Although I'm not able to read the MISO pin which should give the value 01101001 during byte 4 cycle of programming enable sequence.
Here's the code in controller 1:
Here's what received in hyperterminal:
I'm getting these weird smiley symbols. I tried to read the value of MISO pin in while loop and I'm getting 1's and 0's properly. Please help.
Update : I replaced send(tpx) with send(tpx+48) and got the 01101001 sequence in hyperterminal. So, rx should be 0x69 which should display 'i' in hyperterminal but I'm getting nothing for that send instruction alone.
Here's the code in controller 1:
Code:
#include <REGX52.h>
#include <intrins.h>
sbit RST=P2^0;
sbit MOSI=P2^1;
sbit MISO=P2^2;
sbit SCK=P2^3;
unsigned char bit_i=0;
bit txbit,rxbit,flag;
unsigned char a,b,c,d;
unsigned int i=0;
unsigned char rx,tpx;
void delay_us(unsigned int d);
void send(unsigned char x);
void sendbyte(unsigned char spibyte);
void main(void)
{
delay_us(32000);
MISO=1;
RST=0;
SCK=0;
TMOD=0x20;
PCON=PCON | 0x80;
TH1=0xFF;
TL1=0xFF;
SCON=0x50;
TR1=1;
RI=0;
TI=0;
send('M');
delay_us(1000);
send('C');
SCK=0;
//RST=0;
for(i=0;i<500;i++)
{P1_3=1;delay_us(1000);P1_3=0;}
//=======Program enable===========
a=0xac;
b=0x53;
c=0x00;
d=0x11;
sendbyte(a);
sendbyte(b);
sendbyte(c);
sendbyte(d);
//==========Erase==================
a=0xac;
b=0x82;
c=0x12;
d=0x13;
sendbyte(a);
sendbyte(b);
sendbyte(c);
sendbyte(d);
for(i=0;i<1000;i++)
{P1_3=1;delay_us(1000);P1_3=0;}
send('E');
while(1){
P1_3=1;
for(i=0;i<2500;i++)
{P1_3=1;delay_us(1000);P1_3=0;}
P1_3=0;
}
}
void delay_us(unsigned int d)
{
unsigned int i, limit;
limit = d/15;
for(i=0;i<limit;i++);
}
void send(unsigned char x)
{
SBUF=x;
while(TI==0);
//delay_us(10000);
TI=0;
}
void sendbyte(unsigned char spibyte)
{
rx=0x00;
if(spibyte==0x11){flag=1;}else{flag=0;}
for(bit_i=0;bit_i<8;bit_i++)
{P1_3=1;
txbit=spibyte/128;
spibyte=spibyte<<1;
MOSI=txbit;
delay_us(1000);
_nop_();
SCK=1;
delay_us(1000);
_nop_();
if(flag)
{tpx=MISO;send(tpx);
rx= rx | (tpx<<(7-i));}
SCK=0;
P1_3=0;}
if(flag)
{send(':');
send(rx);
send(';');}
}
Here's what received in hyperterminal:
I'm getting these weird smiley symbols. I tried to read the value of MISO pin in while loop and I'm getting 1's and 0's properly. Please help.
Update : I replaced send(tpx) with send(tpx+48) and got the 01101001 sequence in hyperterminal. So, rx should be 0x69 which should display 'i' in hyperterminal but I'm getting nothing for that send instruction alone.
Last edited: