Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Generate a square wave with duty-cicle of 50% on 8051

Status
Not open for further replies.

K-PAX

Newbie level 4
Joined
Dec 30, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,323
hello! i´am using the 8051 microcontroller with 12MHZ crystal, and i want to generate a square wave with the frequency of 5KHZ which gives a 50% of duty cycle.
how can i control delay time thar i have to use?and how i can do to control it.
The last question that i have is why does i have to use CSEG AT ..... ???

---------- Post added at 17:41 ---------- Previous post was at 16:59 ----------

can i do it like that?
ORG 0
jmp start

START: JB P1.0,PULSE
CLR P1.7
JMP START

PULSE: SETB P1.7
JMP DELAY

DELAY: MOV R0,#46
TAKE: DJNZ R0,TAKE
CLR P1.7
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
JMP DELAY
END
 

You could use a software delay, however a more efficient method would be to use a timer and interrupt.

You can set the timer to 1/2 period of the square wave and switch states from high to low and low to high using the timer interrupt.

Using a timer would also offload the work to the generate the PWM, to the timer and interrupt system, freeing the microcontroller to perform other tasks.

Pulse Width Modulation (PWM): 8051 Code example

**broken link removed**

BigDog
 

THIS just training exercices for the final exam. but i have some doubts. like the function CSEG AT WHY DOES i have to specifie an adress?
 

CSEG is not a function, it is a compiler directive tell the compiler as to where the devices program code should be located in FLASH or ROM memory.

Depending on your device (8051 variant):

CSEG ORG 0000h

could be used, however if you have a bootloader resident in the device, then you may need to relocated the beginning of your code to an used position in FLASH or ROM.

Architecture and programming of 8051 MCU's

What development board are you using and is there a bootloader resident in the device?

BigDog
 

Iam using the atme at89c51rd2.
 

Are you using a prefab development board, or is it DIY?

Are you using a bootloader to load your program or an external hardware programmer?

BigDog
 

this is a prefab board, iam using a external hardware to programmer.
Do you know any good book with exercises about it?
 

What is the model and manufacturer of our development board?

The following texts cover the 8051 and Assembly Language Programming:

The 8051/8052 Microcontroller: Architecture, Assembly Language, and Hardware Interfacing

8051 Microcontroller: Architecture, Programming and Applications

8051 Microcontroller, The (4th Edition)

I own all three texts, they all cover the topics well. The last two texts are out of print, however Kenneth Ayala has published a new third edition and I've heard good things about it, while MacKenzie and Phan is hard to find and expensive.

BigDog
 

this was built in my university. thanks for the help m8
 

now i whant to use timer 0 to do the square wave with the same duty-cycle....how i know the number that i have to put in TH0 and TL0? is there any formula to calculate thaat?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top