vterminater
Junior Member level 1
hey i have to generate 3 pulses...on,off,on using pic18f4550,will be using 20Mhz crystal...and the time period of each is specified by the user..any ideas on how to do it..:any program?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
turn on the pwm pin;
delay_ms(pwm_width);
turn off the pwm pin;
delay_ms(pwm_period-pwm_width);
Pin on
delay_ms(20); //Pin on for a delay of 20mS
Pin off
delay_ms(10); //Pin off for a delay of 10mS
Pin on
delay_ms(30); //Pin on for a delay of 30mS
Pin off
#include<stdio.h>
#include<AT89X51.h>
//fclk=(focs/12)=(12M/12)=1MHz=1uS //Maximum Delay(Timer0 Mode 2) = 255 x 1uS = 255uS
void delay(unsigned char);
void main(){
unsigned char i;
TMOD=0X02;
i=0xFF;
while(1){
P2_7=0;
delay(i);
P2_7=1;
delay(255-i);
}
}
void delay(unsigned char value){
unsigned char x;
for(x=0;x<value;x++){
TH0=0xE4;
TR0=1;
while(TF0!=1);
TF0=0;
TR0=0;
}
}
It wont do PWM..e.g
pwm_isr() {
static pwm_status=0; //0=pwm off and 1=pwm on
if (timer overflow) { // in case you have other interrupt source
reset timer flag;
if (pwm_status) { // pwm is on
load timer to256-(pwm_period-pwm_width); // count pwm_period-pwm_width cycle
turn off pwm output;
pwm_status=0;
}
else {
load timer to 256-pwm_width; //count pwm_width ticks;
turn on pwm_output;
pwm_status=1;
}
}
not used to the c dode...asm code please..
#include<p18f4550.inc>
CONFIG WDT= OFF; disable watchdog timer
CONFIG MCLRE = ON; MCLEAR Pin on
CONFIG DEBUG = ON; Enable Debug Mode
CONFIG LVP = OFF; Low-Voltage programming disabled (necessary for debugging)
CONFIG FOSC = INTOSC_EC
;for external clocK
Td1 equ 0x00
Td2 equ 0x01
Td3 equ 0x02
Td equ 0x03
org 0
goto start
org 0x20
start:clrf TRISD
movlw 0x32
movwf Td1
movlw 0x64
movwf Td2
movlw 0xc8
movwf Td3
movlw 0xff
movwf PORTD
movlw b'10111000'
movwf T0CON
movff Td1,Td
call delay
movlw 0x00
movwf PORTD
movff Td2,Td
call delay
movlw 0xff
movwf PORTD
movff Td3,Td
movlw 0x00
movwf PORTD
org 0x60
delay:movlw 0x05
mullw Td
movff PRODL,TMR0L
movff PRODH,TMR0H
bcf INTCON,TMR0IF
here:goto here
return
end
not getting the output properly for this!!!why?????????help![]()