Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to generate 100 Khz square wave output from the 80C51

Status
Not open for further replies.

prevravanth

New Member
Hi,

I want to generate 100 Khz square wave output from the 80c51 using the crystal 11.059 Mhz.

But i am able to generate only 50 khz maximum,

can you correct my code for making 100 Khz

void main(void)
{


TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50; // for serial communication
EA = 1;
TR1 = 1;


TMOD=0x01;
TL0=0xFD; // TL0 Reload value
TH0=0xFF; // TH0 Reload value 50 Khz
ET0=1;
TR0=1; // Start Timer0
EA=1;


while(1)
{
}


}

void timer0() interrupt 1 // interrupt address is 0x000b
{

TF0 = 0; // reset interrupt flag
P0_1 = ~P0_1; // P3.4 toggle when interrupt.
TL0=0xFD; // TL0 Reload value
TH0=0xFF; // TH0 Reload value 50 Khz


}


Please help me
Thanks
 
I find it odd that you are using Timer0 for this purpose. Which specific part are you using? I need the manufacturer and the complete part number. If it were up to me I would be using the PCA or timer2 and the generation of the squarewave would be done in hardware with no software intervention. I also would not start with a crystal of 11.059 MHz. If you are using this crystal to generate accurate baudrates I'm here to tell you that it may not be necessary depending on the baudrate you are trying to generate.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top