mukundh225
Newbie level 6
I am trying to switch my Port D outputs by a time of 1 sec. below is the code that I am using. Only Rd0, Rd1, Rd2 glow. after Rd2 it switches to Rd0 and it keeps looping. I ve set the register for port D properly but still my other 5 LEDS are not glowing.
Also only when I short RB3(pin 36) to gnd , I get this ouput. Without grounding pin 36 I don't get any LED glowing.
Could anyone please give me a reason for the above two problems.
#include<htc.h>
#include<pic16f887.h>
#include<stdio.h>
#include<conio.h>
#ifndef _XTAL_FREQ
// Unless already defined assume 4MHz system frequency
// This definition is required to calibrate __delay_us() and __delay_ms()
#define _XTAL_FREQ 4000000
#fuses INTRC_IO,NOWDT,NOPROTECT,NOCPD,NOBROWNOUT
#endif
void main()
{
OSCCON = 0x67; //calibrate internal oscillator...read about this in data sheet
TRISD = 0x00; //configuring portd as output(page57)
PORTD=0x00;
while(1)
{
//PORTD = 0xFF; //setting all pins of portD as high
PORTD=0X01;
__delay_ms(1000);//1000ms delay
PORTD=0X02;
__delay_ms(1000);//1000ms delay
PORTD=0X04;
__delay_ms(1000);//1000ms delay
PORTD=0X08;
__delay_ms(1000);//1000ms delay
PORTD=0X10;
__delay_ms(1000);//1000ms delay
PORTD=0X20;
__delay_ms(1000);//1000ms delay
PORTD=0X40;
__delay_ms(1000);//1000ms delay
PORTD=0X80;
__delay_ms(1000);//1000ms delay
}
}
Thanks
Mukund
Also only when I short RB3(pin 36) to gnd , I get this ouput. Without grounding pin 36 I don't get any LED glowing.
Could anyone please give me a reason for the above two problems.
#include<htc.h>
#include<pic16f887.h>
#include<stdio.h>
#include<conio.h>
#ifndef _XTAL_FREQ
// Unless already defined assume 4MHz system frequency
// This definition is required to calibrate __delay_us() and __delay_ms()
#define _XTAL_FREQ 4000000
#fuses INTRC_IO,NOWDT,NOPROTECT,NOCPD,NOBROWNOUT
#endif
void main()
{
OSCCON = 0x67; //calibrate internal oscillator...read about this in data sheet
TRISD = 0x00; //configuring portd as output(page57)
PORTD=0x00;
while(1)
{
//PORTD = 0xFF; //setting all pins of portD as high
PORTD=0X01;
__delay_ms(1000);//1000ms delay
PORTD=0X02;
__delay_ms(1000);//1000ms delay
PORTD=0X04;
__delay_ms(1000);//1000ms delay
PORTD=0X08;
__delay_ms(1000);//1000ms delay
PORTD=0X10;
__delay_ms(1000);//1000ms delay
PORTD=0X20;
__delay_ms(1000);//1000ms delay
PORTD=0X40;
__delay_ms(1000);//1000ms delay
PORTD=0X80;
__delay_ms(1000);//1000ms delay
}
}
Thanks
Mukund