I am new in learning MikcoC. Currently, I wrote a simple coding to turn on the 4 green LEDs for 100ms when the button is being pressed.
I used the microcontroller PIC18F452 and I have configured PORT B as input and PORT D as output.
However, the circuit in my proteus did not function as expected although my coding was built successfully.
I tried it many times already and learnt the tutorial in youtube but the LEDs still cannot light on although I pressed and pressed again.
Assuming you have the configuration bits set correctly and the clock and reset working, do you have a pull-up/ pull-down resistor on whatever pin PORTB.F0 is defined as (your input pin) It will only change state if pressing the button moves it from one logic level to the other, you have to set the logic level before the button changes it.
hi lapsapbee, welcome to forum...BTW you want to control 4 LED of port D with button connected to port B..
Code:
void main()
{
TRISB = 0xFF;
TRISD = 0x00;
ADCON0 = 0x09;
ADCON1 = 0x0E;
PORTD = 0X00
while(1)
{
if (PORTB.F0 == 0) /// check this statement PORTB.F0 is it write ???
{
PORTD = 0xFF; // PORT D High you are turning all pins of port D high
Delay_ms(100); // delay
PORTD = 0x00; // PORTD is low
Delay_ms(100); // delay
}
}
}
The clock frequency, I set it to 20Mhz.. I don't know whether the resistor that I picked correct or not.. I use the RES so I can change the value of resistance.
There is the component that I used.
- - - Updated - - -
Hi peeyushsigma,
Thank you! Btw, I changed the coding as below (PORTA bit 3 as input):