Please help me friends

Thread Starter

nalakan2

Joined Nov 20, 2013
4
I'm using PIC16F877A
I want mikroC code to do this;

This is a project contains 3 LEDs (A,B,C)

A - can turn on when C is off
B - can turn on when C is off
C - can turn on when both A and B are off

3 push to on switches are use to on/off the LEDs

Please help me with this...
 

PIYUSH SONI

Joined Nov 15, 2013
32
Hi Nalakan , Welcome to the Forum.
Actually before doing program you should know on which port you want to get output. As you have taken 3 LED then to turn on any of them you have to assign it to 1.
To turn off assign it to 0. Try it once , use any condition statement for your result.
 

Papabravo

Joined Feb 24, 2006
21,225
It is common for professors to give the same assignments every year.
I wonder if we have the raw data to identify the universities and the professors who so poorly prepare their students that they are forced to ask us for help. We could then put together a free e-book that we could send to those students in advance of the semester with some catchy title they would be sure to read. May even a cover with a side-boob shot of JWoww.
 

WBahn

Joined Mar 31, 2012
30,051
I wonder if we have the raw data to identify the universities and the professors who so poorly prepare their students that they are forced to ask us for help.
Ah, but were it that simple.

First, we have to keep in mind that the cross section of students that "are forced to ask us for help" are far from being representative of the students in their class, the overwhelming majority of whom are NOT "forced to ask us for help".

The ones that do come here do so for a host of reasons. You of course have those that are trying to learn something more deeply or learn stuff that goes beyond what their coursework covers. But for the ones that are struggling, it may be because (1) they have a lousy professor; (2) they were poorly prepared to even start the course they are currently in; (3) they routinely put off even looking at their homework until the night before it's due; (4) they have no interest in learning anything and have been copying other people's work up to this point; (5) something just isn't clicking; (6) they aren't utilizing the resources, such as office hours and help sessions, that are available to them; (7) they simply are not cut out for technical material of this nature.

We often see what appear to be telltales about some of these possibilities. We also often hear tales about how their professors refuse to help them. Some of these tales might even be accurate.
 

Thread Starter

nalakan2

Joined Nov 20, 2013
4
Hi Nalakan , Welcome to the Forum.
Actually before doing program you should know on which port you want to get output. As you have taken 3 LED then to turn on any of them you have to assign it to 1.
To turn off assign it to 0. Try it once , use any condition statement for your result.

Here is the mikroC program I used to turn on/off LEDs. I tried so many times to make the conditions, but couldn't get correct results.

bit LED1;
bit LED2;
bit LED3;

void main() {
TRISB = 0x00;
TRISD = 0xFF;
PORTB = 0x00;
PORTD = 0x00;

LED1 = 0;
LED2 = 0;
LED3 = 0;

do
{
// button 1
if (Button(&PORTD,0,1,1))
{
LED1 = 1;
}
if (LED1 && Button(&PORTD,0,1,0))
{
RB0_bit = ~RB0_bit;
LED1 = 0;
}
// end button 1

// button 2
if (Button(&PORTD,1,1,1))
{
LED2 = 1;
}
if (LED2 && Button(&PORTD,1,1,0))
{
RB1_bit = ~RB1_bit;
LED2 = 0;
}
// end button 2

// button 3
if (Button(&PORTD,2,1,1))
{
LED3 = 1;
}
if (LED3 && Button(&PORTD,2,1,0))
{
RB2_bit = ~RB2_bit;
LED3 = 0;
}
// end button 3


} while (1);


}
 

JohnInTX

Joined Jun 26, 2012
4,787
What results ARE you getting?

One thing missing from your code is initializing ANSEL and ANSELH (to make the port pins digital). If you do not do this, all reads will be '0' and writing single bits on a port will be problematic. See 3.4.1 - ANSELH REGISTER in the datasheet.
 

ErnieM

Joined Apr 24, 2011
8,377
OK, so you made an attempt and it didn't work. That makes us happy as we don't think we're writing your homework for you. We like helping, we hate doing.

Did they teach you how to use a debugger? Sorry I don't use MikroC to give any specific help here but debuggers can either simulate your code in the PC (no real PIC needed) or actually run the code in the PIC and let you watch it.

Anyway, if you are having trouble it may well be other setting such as JohnInTX suggests; I don't have time this morning to check whatever else it might be. The data sheet usually gives you a list of all registers that affect a ports in each port section.

I have the feeling you are in a hurry and don't have the time to learn another technique to get this to work, so try this: strip out all your logic code (comments to hide a line works well, as does goto or while(0) ), and change the code to turn on all LEDs when any button is pressed. This way you can see that all the inputs work as inputs, and all the outputs work as outputs.

That part alone is probably harder then the logic as it depends on all the other functions the input/output pins can have.
 

Thread Starter

nalakan2

Joined Nov 20, 2013
4
:cool:

After long hours of hard work, trying with several methods I got the correct results.. thank you everyone.. Including those who thought that I'm trying to get done my homework by others :rolleyes:

Ah, anyway I'm hoping to post my final code after testing it with prototype.
up to now I have tested it with proteus, it worked :):)
 
Top