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.

help for 2MHz pwm using pic16f877a

Status
Not open for further replies.

pany2008

Junior Member level 3
Joined
Aug 24, 2009
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
India
Activity points
1,627
Hi,

I am having problem for pwm using pic16f877a, I am not getting the pulse output from microcontroller. Please can you help me out for seeing my source code if their is any thing wrong or missing then please help me out.

#include<pic.h>
#include<math.h>
#include "ioports1.h"
#include "delay.h"
#include "lcd.h"

__CONFIG (HS & DEBUGDIS & WDTDIS & BORDIS & PWRTEN & LVPDIS & PROTECT);

unsigned int dummy_sec;

void Sec(unsigned int);

void main()
{
Sec(100);
init_ports();
Sec(50);
lcd_init(); //LCD initialized
Sec(25);

lcd_line1(0); //LCD address specified AT LINE 1
lcd_string(" PANKAJ PATEL "); //Displays message "LCD INTERFACING"
lcd_line2(0); //LCD address specified AT LINE 2
lcd_string(" PWM EXAMPLE "); //Displays message "LCD INTERFACING"

Sec(200);
init();

for(;;)
{
GIE = 1;
lcd_line1(0); //LCD address specified AT LINE 1
lcd_string(" PANKAJ PATEL "); //Displays message "LCD INTERFACING"
lcd_line2(0); //LCD address specified AT LINE 2
lcd_string(" PWM EXAMPLE "); //Displays message "LCD INTERFACING"
}
}

init_ports()
{
T_CPU_LED = 0; // pin enable to output
CPU_LED = 0;
}

init()
{
TMR1H = 0xfc;
TMR1L = 0x17;
TMR1CS = 0;
T1CKPS0 = 0;
T1CKPS1 = 0;
T1CON = 0b00000001;
TMR1ON = 1;
TMR1IF = 0;
TMR1IE = 1;
PR2 = 0b00000000;
T2CON = 0b00000100;
CCPR1L = 0b00000000;
CCP1CON = 0b00011100;
TMR2ON = 1;
TMR2IF = 0;
TMR2IE = 1;
PEIE = 1;
GIE = 1;
}

void Sec(unsigned int itime)
{
unsigned int i;
unsigned char j;
for(i=0;i<itime;i++)
for(j=0;j<165;j++);
}


void interrupt ISR()
{
if(TMR1IF)
{
PIE1 = 0;
TMR1IF = 0;
TMR1ON = 0;
CPU_LED = !CPU_LED;
++dummy_sec;
if(dummy_sec > 1000)
{
// CPU_LED = !CPU_LED;
dummy_sec = 0;
}

TMR1H = 0xfc;
TMR1L = 0x17;
TMR1ON = 1;
PIE1 = 1;
}

}
 

You need to initialize the port properly first. TRISx = 0 ; // 0 = output , 1 = input
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top