numair_noor
Member level 2
hi, i m new to pic microcontroller. i am trying to program a pic microcontroller may be PIC18F458. for a simple timer program.
for the following question:
A timer based on 24 hours timer which has a switch to select off,
a)8 hrs on and 16 hrs off
b)10 hrs on and 14 hrs off
c)12 on and 12 hours off
d) 16 hrs on and 8 hrs off
e)18 hrs on and 6 hrs off
and on all the time which has LED light in indicate mode it is on.
The input and output is ranging of 100 to 240 VAC and should be able to handle a load about 120W which work out to about 1.2 amp at 100VAC.
this is the code i have written so far.
PROBLEMS:
1)i am new to pic
2)when i run this program this gives me error: "undeclared identifier PORTCbit in expression"
3)am i using the do-while loop correctly(i m asking this because i want to know if user changes switch from c to b, then it must break where ever it is. and go back to other mode.)
4)please tell me how to access bit wise. i m using mikroc pro 4.60.0.0
5)please also tell me the best and easy to install compiler. i have installed mplab ide v5.6 before. but it required some library called c18. i could not install it. so i deleted it. and install this one. if it is ok. thn please tell me the procedure to solve. em trying to torrent newer version of software mikroc pro thanks in advance.
for the following question:
A timer based on 24 hours timer which has a switch to select off,
a)8 hrs on and 16 hrs off
b)10 hrs on and 14 hrs off
c)12 on and 12 hours off
d) 16 hrs on and 8 hrs off
e)18 hrs on and 6 hrs off
and on all the time which has LED light in indicate mode it is on.
The input and output is ranging of 100 to 240 VAC and should be able to handle a load about 120W which work out to about 1.2 amp at 100VAC.
this is the code i have written so far.
PROBLEMS:
1)i am new to pic
2)when i run this program this gives me error: "undeclared identifier PORTCbit in expression"
3)am i using the do-while loop correctly(i m asking this because i want to know if user changes switch from c to b, then it must break where ever it is. and go back to other mode.)
4)please tell me how to access bit wise. i m using mikroc pro 4.60.0.0
5)please also tell me the best and easy to install compiler. i have installed mplab ide v5.6 before. but it required some library called c18. i could not install it. so i deleted it. and install this one. if it is ok. thn please tell me the procedure to solve. em trying to torrent newer version of software mikroc pro thanks in advance.
Code:
//declaration for switches for input
#define sw0 PORTBbits.RB0
#define sw1 PORTBbits.RB1
#define sw2 PORTBbits.RB2
#define sw3 PORTBbits.RB3
#define sw4 PORTBbits.RB4
#define sw5 PORTBbits.RB5
#define sw6 PORTBbits.RB6
//declaration for led's and outputs
#define led0 PORTCbit.RC0
#define led1 PORTCbit.RC1
#define led2 PORTCbits.RC2
#define led3 PORTCbits.RC3
#define led4 PORTCbits.RC4
#define led5 PORTCbits.RC5
#define led6 PORTCbits.RC6
#define led7 PORTCbits.RC7
int main()
{
unsigned int a,c,d;
//char f;
TRISB0.RB0=1;
TRISB1.RB1=1;
TRISB2.RB2=1;
TRISB3.RB3=1;
TRISB4.RB4=1;
TRISB5.RB5=1;
TRISB6.RB6=1;
TRISB7.RB7=1;
TRISC0.RC0=0;
TRISC1.RC1=0;
TRISC2.RC2=0;
TRISC3.RC3=0;
TRISC4.RC4=0;
TRISC5.RC5=0;
TRISC6.RC6=0;
TRISC7.RC7=0;
//TRISB=1; //monitor port b as input
//TRISC=0; //monitor port c as output
while(1)
{
//condition 1
do
{
led0=1; //led is indicatin the timer is in on mode
for(a=0;a<=7;a++) //timer is on for 8 hours
{
for(c=0;c<=59;c++)
{
for(d=0;d<=59;d++)
delay_ms(900);
}
}
led0=0; //led indicating that timer is now in off mode
for(a=0;a<=15;a++) //timer is off for 16 hours
{
for(c=0;c<=59;c++)
{
for(d=0;d<=59;d++)
delay_ms(900);
}
}
}while(sw0==1 && sw1==1 && sw2==0 && sw3==0 && sw4==0 && sw5==0 && sw6==0);
//cond2()
do
{
led1=1; //led is indicatin the timer is in on mode
for(a=0;a<=9;a++) //timer is on for 10 hours
{
for(c=0;c<=59;c++)
{
for(d=0;d<=59;d++)
delay_ms(900);
}
}
led1=0; //led indicating that timer is now in off mode
for(a=0;a<=13;a++) //timer is off for 14 hours
{
for(c=0;c<=59;c++)
{
for(d=0;d<=59;d++)
delay_ms(900);
}
}
}while(sw0==1 && sw1==0 && sw2==1 && sw3==0 && sw4==0 && sw5==0 && sw6==0);
//cond3()
do
{
led2=1; //led is indicatin the timer is in on mode
for(a=0;a<=11;a++) //timer is on for 12 hours
{
for(c=0;c<=59;c++)
{
for(d=0;d<=59;d++)
delay_ms(900);
}
}
led2=0; //led indicating that timer is now in off mode
for(a=0;a<=11;a++) //timer is off for 12 hours
{
for(c=0;c<=59;c++)
{
for(d=0;d<=59;d++)
delay_ms(900);
}
}
}while(sw0==1 && sw1==0 && sw2==0 && sw3==1 && sw4==0 && sw5==0 && sw6==0);
//cond4()
do
{
led3=1; //led is indicatin the timer is in on mode
for(a=0;a<=15;a++) //timer is on for 16 hours
{
for(c=0;c<=59;c++)
{
for(d=0;d<=59;d++)
delay_ms(900);
}
}
led3=0; //led indicating that timer is now in off mode
for(a=0;a<=7;a++) //timer is off for 8 hours
{
for(c=0;c<=59;c++)
{
for(d=0;d<=59;d++)
delay_ms(900);
}
}
}while(sw0==1 && sw1==0 && sw2==0 && sw3==0 && sw4==1 && sw5==0 && sw6==0);
//cond5()
do
{
led4=1; //led is indicatin the timer is in on mode
for(a=0;a<=17;a++) //timer is on for 18 hours
{
for(c=0;c<=59;c++)
{
for(d=0;d<=59;d++)
delay_ms(900);
}
}
led4=0; //led indicating that timer is now in off mode
for(a=0;a<=5;a++) //timer is off for 6 hours
{
for(c=0;c<=59;c++)
{
for(d=0;d<=59;d++)
delay_ms(900);
}
}
}while(sw0==1 && sw1==0 && sw2==0 && sw3==0 && sw4==0 && sw5==1 && sw6==0);
}