Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

16F877A Switch controlled LED.

Status
Not open for further replies.

Cent-0

New Member
Hi all,

I'm learning the basic microcontroller, i want to make LED lights on and off, controlled by the switch. I chose RA0 as the input and the output RD0-RD7, but it does not work, I use mplab and Hitech c compiler. If there can give me an example code for testing purposes, assistance from you all very much appreciated.
 
This code.

#include <pic.h>
#include <htc.h>
__CONFIG(0x3F32);
#define PB1 RB0
#define LED PORTD
#define _XTAL_FREQ 20000000

void pic_init();
main()
{int i;
pic_init();
for(;;){
LED=0b11111111;
__delay_ms(300);
LED=0b00000000;
__delay_ms(300);
LED=0b00011000;
__delay_ms(300);
LED=0b00100100;
__delay_ms(300);
LED=0b01000010;
__delay_ms(300);
LED=0b10000001;
__delay_ms(300);
LED=0b01000010;
__delay_ms(300);
LED=0b00100100;
__delay_ms(300);
LED=0b00011000;
__delay_ms(300);
LED=0b00000000;
__delay_ms(300);

}
}

void pic_init(){
TRISA=0b00000000;
TRISB=0b00000011;
TRISC=0b00000000;
TRISD=0b00000000;
TRISE=0b00000000;
ADCON1=0b0000110;
PORTA=0b00000000;
PORTB=0b00000000;
PORTC=0b00000000;
PORTD=0b00000000;
PORTE=0b00000000;}
 
Last edited:
Your code shows all of PORTA set as outputs, and RB0 and RB1 set as inputs. This is at odds with you expecting to use RA0 as an input.

You might want to start with some basic tutorials, like Nigel's...see the Sticky at the top of the forum.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top