romarioo
Newbie level 4
iam having atrouble to debug a code for pic 16f871 to blink the Leds for port B and c...plz help me with it
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
// TODO: USER CODE!!
}//include file
#define PORTBIT(adr, bit) ((unsigned)(&adr)*8+(bit))
#define LED0,LED1,LED2,LED3,LED4,LED5,LED6,LED7
//portb pin assignment
static bit LED0 @ PORTBIT(PORTB, 0);
static bit LED1 @ PORTBIT(PORTB, 1);
static bit LED2 @ PORTBIT(PORTB, 2);
static bit LED3 @ PORTBIT(PORTB, 3);
static bit LED4 @ PORTBIT(PORTB, 4);
static bit LED5 @ PORTBIT(PORTB, 5);
static bit LED6 @ PORTBIT(PORTB, 6);
static bit LED7 @ PORTBIT(PORTB, 7);
static bit LED0 @ PORTBIT(PORTC, 0);
static bit LED1 @ PORTBIT(PORTC, 1);
static bit LED2 @ PORTBIT(PORTC, 2);
static bit LED3 @ PORTBIT(PORTC, 3);
static bit LED4 @ PORTBIT(PORTC, 4);
static bit LED5 @ PORTBIT(PORTC, 5);
static bit LED6 @ PORTBIT(PORTC, 6);
static bit LED7 @ PORTBIT(PORTC, 7);
unsigned int i;
unsigned int n;
//functions
void pause_action(); //pause
void blink_red();
//main function
void main(void)
{
TRISB = 0x00;
PORTB = 0b00000000;
TRISC = 0x00;
PortC=0c00000000;
while(1)
{
blink_red();
blink_sequence();
};
}
void pause_action()
{
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
};
void blink_red()
{
for(n=0; n<10; n++)
{
PORTB = 0b00001111;
pause_action();
PORTB = 0b01010101;
pause_action();
};
};
void blink_sequence()
{
for(n=0; n<10; n++)
{
PORTB = 0b01010101;
pause_action();
PORTB = 0b01111111;
pause_action();
PORTB = 0b01011001;
pause_action();
PORTB = 0b01010110;
pause_action();
};
};
{
void blink sequence()
{
for (n=0; n<10; n++)
PORTC=oc00110011;
pause_action();
PORTC=oc11001100;
pause_action();
};
};
---------- Post added at 03:15 ---------- Previous post was at 03:11 ----------
most of the errors aere related to the LED assignings and recognitions
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
// TODO: USER CODE!!
}//include file
#define PORTBIT(adr, bit) ((unsigned)(&adr)*8+(bit))
#define LED0,LED1,LED2,LED3,LED4,LED5,LED6,LED7
//portb pin assignment
static bit LED0 @ PORTBIT(PORTB, 0);
static bit LED1 @ PORTBIT(PORTB, 1);
static bit LED2 @ PORTBIT(PORTB, 2);
static bit LED3 @ PORTBIT(PORTB, 3);
static bit LED4 @ PORTBIT(PORTB, 4);
static bit LED5 @ PORTBIT(PORTB, 5);
static bit LED6 @ PORTBIT(PORTB, 6);
static bit LED7 @ PORTBIT(PORTB, 7);
static bit LED0 @ PORTBIT(PORTC, 0);
static bit LED1 @ PORTBIT(PORTC, 1);
static bit LED2 @ PORTBIT(PORTC, 2);
static bit LED3 @ PORTBIT(PORTC, 3);
static bit LED4 @ PORTBIT(PORTC, 4);
static bit LED5 @ PORTBIT(PORTC, 5);
static bit LED6 @ PORTBIT(PORTC, 6);
static bit LED7 @ PORTBIT(PORTC, 7);
unsigned int i;
unsigned int n;
//functions
void pause_action(); //pause
void blink_red();
//main function
void main(void)
{
TRISB = 0x00;
PORTB = 0b00000000;
TRISC = 0x00;
PortC=0c00000000;
while(1)
{
blink_red();
blink_sequence();
};
}
void pause_action()
{
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
};
void blink_red()
{
for(n=0; n<10; n++)
{
PORTB = 0b00001111;
pause_action();
PORTB = 0b01010101;
pause_action();
};
};
void blink_sequence()
{
for(n=0; n<10; n++)
{
PORTB = 0b01010101;
pause_action();
PORTB = 0b01111111;
pause_action();
PORTB = 0b01011001;
pause_action();
PORTB = 0b01010110;
pause_action();
};
};
{
void blink sequence()
{
for (n=0; n<10; n++)
PORTC=oc00110011;
pause_action();
PORTC=oc11001100;
pause_action();
};
};
---------- Post added at 03:15 ---------- Previous post was at 03:11 ----------
most of the errors aere related to the LED assignings and recognitions