Trying to make a program in MIKROC

Thread Starter

LETITROLL

Joined Oct 9, 2013
218
Hy again , i have solved the problem using delays after each button press and each variable's value change :
What do you think , if there is a better solution don't hesitate to share it :

Rich (BB code):
#define start porta.b0
#define led1  portb.b0
#define led2  portb.b1
#define led3  portb.b2
#define led4  portb.b3
 
int x0,x1,x2,x3;

void main() {
porta=0x00;
portb=0xff;
trisa=0xff;
trisb=0x00;
x0=1;x1=0;x2=0;x3=0;

while(1){


if((start==1)&&(x0==1)){
delay_ms(200);
x0=0;
delay_ms(200);
x1=1;led4=1;led1=0;
}

if((start==1)&&(x1==1)){
delay_ms(200);
x1=0;
 delay_ms(200);
x2=1;led1=1;led2=0;
}

if((start==1)&&(x2==1)){
delay_ms(200);
x2=0;
 delay_ms(200);
x3=1;led2=1;led3=0;
}

if((start==1)&&(x3==1)){
delay_ms(200);
x3=0;
delay_ms(200);
led3=1;led4=0;
}
if((start==1)&&(led4==0)){
delay_ms(200);
x0=1;
delay_ms(200);
led4=1;


}
}
}
 

Thread Starter

LETITROLL

Joined Oct 9, 2013
218
Have a look here;

http://www.mikroe.com/download/eng/documents/compilers/mikroc/pro/pic/help/button_library.htm

"Button Library
The Button Library provides routines for detecting button presses and debouncing (eliminating the influence of contact flickering upon pressing a button).
Button
Prototype
unsigned short Button(unsigned short *port, unsigned short pin, unsigned short time, unsigned short active_state);"


like this ?

unsigned short button (PORTB,0,1,1) ;

If so how do i work with it inside my program ??
 

THE_RB

Joined Feb 11, 2008
5,438
There are examples on that help page I gave the link to. :)

Generally you use it something like this;
Rich (BB code):
if(button(PORTB,0,1,1))
{
  x1=0;
  x2=1;
  led1=1;
  led2=0;
}
So you can use it in an if() statement.
 

Thread Starter

LETITROLL

Joined Oct 9, 2013
218
There are examples on that help page I gave the link to. :)

Generally you use it something like this;
Rich (BB code):
if(button(PORTB,0,1,1))
{
  x1=0;
  x2=1;
  led1=1;
  led2=0;
}
So you can use it in an if() statement.
Yes i see .

What about this book ? Is it good ?

The C Programming Language, 2nd Edition by BRIAN KERNIGHAN & DENNIS M.RITCHIE
 

t06afre

Joined May 11, 2009
5,934
The C Programming Language, 2nd Edition by BRIAN KERNIGHAN & DENNIS M.RITCHIE
I have used this book. And I liked it, and it is also a classic. Then it comes to books, it is hard to say what good it will do you. One book may work for some, but not for others. The best thing is to test run it. Like getting it from the library. Then you can decide how good it is for you. The good thing about the latter book. Is that it is platform independent. But depending on how true your C compiler is to the ANSI C standard.
 

Thread Starter

LETITROLL

Joined Oct 9, 2013
218
I have used this book. And I liked it, and it is also a classic. Then it comes to books, it is hard to say what good it will do you. One book may work for some, but not for others. The best thing is to test run it. Like getting it from the library. Then you can decide how good it is for you. The good thing about the latter book. Is that it is platform independent. But depending on how true your C compiler is to the ANSI C standard.
I should use an almost fully ANSI compatible compiler for it then .

What is the compiler to use to apply the learned technics from the book in my case ( PIC microcontrollers programming taken in consideration) ??
 

t06afre

Joined May 11, 2009
5,934
I you are taking a some sort of microcontroller course. You should use the compiler used in that course. And not any other. A good source of learning, is to use the software manual accompanying the compiler. And also learning to use any debugger tools that you have available. As long as you are reluctant to use the latter. You will not understand how to program. Then you are stuck, it may take days to get answer here, but by using the debugging tools it may only take a few minutes to solve a problem. Second a book like the one you mentioned may also help. But you can not learn how to use C by reading only. You have to use us it.
 

Thread Starter

LETITROLL

Joined Oct 9, 2013
218
Ok i appreciate your time to6afre .

I hope i can get something done after reading that book and doing some C exercices .

BTW , am a student in PLC ( programmable logic controlers )systems , but before i start learning their programming , i need to make a project by using PIC

The important thing i need for my project right now is the ability to transform the project's idea into a well structured program .
 
Top