Google

Mar 10, 2010

PWM with 89S52

Here is the program for Pulse width modulation PWM on basic for 89s52.

You could generate pwm using the following psedocode

#define high_period
#define low_period

main()
{
!!Code to initiate the timer;
!!Timer counter register value = high_period;
!!set port pin high
!!start timer
while(1);
}

interrupt void time_interrupt_routine(void)
{
if(port pin is high)
!!Timer counter register value = low_period;

else
!!Timer counter register value = high_period;

!!Toggle port pin
!! start timer;
}

Here high_period + low_period gives the time period in terms of clock cycle and

high_period/(high_period + low_period) *100 gives the dutycycle.

Mar 5, 2010

How to access R0 to R7 registers in Keil C?

you can use the following Program to access R0 to R7 registers in Keil C


{

unsigned char R0Val;

_asm

MOV A, R0
MOV _R0Val, A

_endasm

}

OR

{

unsigned char R0Val;

#pragma ASM

MOV A, R0
MOV _R0Val, A

#pragma ENDASM

}

C variables have to be prefixed by '_' or underscore character, to be accessible in the assembly section of the C code.

Hope this helps.