PLS HELP ME (IM NEW)

General discussion on mikroC.
Post Reply
Author
Message
imnewbie
Posts: 5
Joined: 16 Oct 2011 17:53

PLS HELP ME (IM NEW)

#1 Post by imnewbie » 16 Oct 2011 18:23

hi guys, im new to mikroc. pls help me. currently im using mikroC ver.8.1 to control the ON/OFF switch of a LED using PIC16f877a. can any1 provide me the code?

//Final Year Project
void main() {
// pic16f887
// pic16f877A

TRISB = 0; // PORTB is output
TRISD = 0xFF; //define as input
TRISA = 0; // PORTA is output
TRISC = 0;

Lcd_Init(&PORTB); // Initialize LCD connected to PORTB
Lcd_Cmd(Lcd_CLEAR); // Clear display
Lcd_Cmd(Lcd_CURSOR_OFF); // Turn cursor off


while(1){

if (PORTD.F1 == 1) //button to count people coming in
{
PortC = 0x02;
delay_ms(500); //to set the delay of the sensor
}

}

}


can any1 tell me whats wrong with the code? im putting a switch at RD1 and LED at RC2 but still i cant control the LED with the switch

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: PLS HELP ME (IM NEW)

#2 Post by filip » 17 Oct 2011 10:13

Hi,

Please, try the Button Example in the Example folder of the compiler, it will show you how to correctly use the button press activities.

Regards,
Filip.

imnewbie
Posts: 5
Joined: 16 Oct 2011 17:53

Re: PLS HELP ME (IM NEW)

#3 Post by imnewbie » 17 Oct 2011 11:05

mr filip, thx for replying. can u kindly tell me where to find the example folder and how to check the button configuration?

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: PLS HELP ME (IM NEW)

#4 Post by filip » 18 Oct 2011 09:10

Hi,

Here is the requested folder path :
Examples\EasyPic5\P16F877A\Button\

Regards,
Filip.

imnewbie
Posts: 5
Joined: 16 Oct 2011 17:53

Re: PLS HELP ME (IM NEW)

#5 Post by imnewbie » 24 Oct 2011 11:49

mr filip, sorry to bother u again.i used the example button that u mentioned and it works. when high input to RB1, it will give high output to RD pins. the problem is i want only 1 pin to be high only. how can i make that? pls help me.

/*
* Project name:
Button_Test
* Copyright:
(c) MikroElektronika, 2005-2008.
* Description:
This code demonstrates how to use Button library. Program toggles LEDs
on PORTD, upon applying high voltage level on PORTB's RB1 pin.
* Test configuration:
MCU: PIC16F877A
Dev.Board: EasyPIC5
Oscillator: HS, 08.0000 MHz
Ext. Modules: -
SW: mikroC v8.0
* NOTES:
- In order to work properly, in this example, ports B and D must have pull down
resistors, also button jumper JP17 on EasyPIC5 board has to be in VCC position (that is,
the voltage level to be applied when a button is pressed should be high (VCC)).
*/

void main(){
char oldstate = 0;
TRISB = 0xFF; // set PORTB to be input
TRISD = 0; // set PORTD to be output
PORTD = 0x0F; // initialize PORTD

do {
if (Button(&PORTB, 1, 1, 1)) // detect logical one on RB1 pin
oldstate = 1;
if (oldstate && Button(&PORTB, 1, 1, 0)) { // detect one-to-zero transition on RB1 pin
PORTD = ~PORTD;
oldstate = 0;
}
} while(1); // endless loop
}

jovdamo86
Posts: 12
Joined: 17 Nov 2011 06:05
Location: Philippines

Re: PLS HELP ME (IM NEW)

#6 Post by jovdamo86 » 22 Dec 2011 08:26

i want only 1 pin to be high only.
Instead of

Code: Select all

PORTD = ~PORTD;
You can use:

Code: Select all

PORTD.F1 = ~PORTD.F1;   //invert the value of PIN 1 of PORTD
or

Code: Select all

PORTD.B1 = ~PORTD.B1;   //invert the value of PIN 1 of PORTD

Post Reply

Return to “mikroC General”