[MOVED] light turns on when push button is pressed mikroc

Status
Not open for further replies.

moad

Newbie level 5
Joined
Jan 30, 2015
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
113

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
void main() {
     TRISA.F0=1;
     TRISC=0;
     PORTC=0;
     while (1){
           if (PORTA.F0 == 1){
           PORTC=1;
           delay_ms(1000);
           PORTC=0;
           }
     }
 
}



the above is a simple code to make all leds in portc to turn on when ra0 is pressed, unfortonately nothing happens when its pressed? any suggesstions would be appreciated, thanks
 
Last edited by a moderator:

Re: light turns on when push button is pressed mikroc

You had not mentioned what microcontroller were used, but registers seems belonging to the PIC family.
If it is the case, and assuming the one you selected has A/D converter, you need to disable it on init, due default configuration for PortA is not digital I/O's.
 

Code:
           PORTC=1;
Will light the LED on PORTC bit 0 only.

If you want all LEDs lit then change to:
Code:
           PORTC = 0xFF;      // Light all LEDs on PORTC

.. Plus you may need to heed the advice from andre_teprom - depending on which PIC you are using.

Need to know exactly which PIC to give proper advice..

It is always a good idea to comment you code, helps you and those who read your code.
 

Try this code.

Code:
void main() {
     TRISA.F0 = 1;
     TRISC = 0;
     PORTC = 0;

     while (1) {
           if(PORTA.F0 == 1) {
		Delay_ms(50);
		if(PORTA.F0 == 1) {
           		PORTC = 0xFF;
           		Delay_ms(1000);
           		PORTC = 0;
		}
           }
     }
 
}
 

And what on hardware side? you are trying to read logic 1 so did you connected any pull down resistor on RA0 pin?
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…