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
PLS HELP ME (IM NEW)
Re: PLS HELP ME (IM NEW)
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.
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.
Re: PLS HELP ME (IM NEW)
mr filip, thx for replying. can u kindly tell me where to find the example folder and how to check the button configuration?
Re: PLS HELP ME (IM NEW)
Hi,
Here is the requested folder path :
Examples\EasyPic5\P16F877A\Button\
Regards,
Filip.
Here is the requested folder path :
Examples\EasyPic5\P16F877A\Button\
Regards,
Filip.
Re: PLS HELP ME (IM NEW)
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
}
/*
* 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
}
Re: PLS HELP ME (IM NEW)
Instead ofi want only 1 pin to be high only.
Code: Select all
PORTD = ~PORTD;
Code: Select all
PORTD.F1 = ~PORTD.F1; //invert the value of PIN 1 of PORTD
Code: Select all
PORTD.B1 = ~PORTD.B1; //invert the value of PIN 1 of PORTD