Jhuman Khan
Published

🔥 How to Make the Best IoT Project using PIC16F877A

In this project, we’ll learn how to design and build a complete IoT-based control system using the PIC16F877A microcontroller.

BeginnerFull instructions provided4
🔥 How to Make the Best IoT Project using PIC16F877A

Story

Read more

Schematics

CIrcuit Diagram

Code

CCSC Code

C#
#include <16f877a.h>
#fuses HS, NOWDT, NOPROTECT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#define RELAY1 PIN_B0
#define RELAY2 PIN_B1
#define RELAY3 PIN_B2
#define RELAY4 PIN_B3

void main() {
    char data;
    set_tris_b(0xF0); // RB0–RB3 as output

    while(TRUE) {
        if(kbhit()) {
            data = getc();
            switch(data) {
                case '1': output_high(RELAY1); break;
                case '2': output_low(RELAY1); break;
                case '3': output_high(RELAY2); break;
                case '4': output_low(RELAY2); break;
                case '5': output_high(RELAY3); break;
                case '6': output_low(RELAY3); break;
                case '7': output_high(RELAY4); break;
                case '8': output_low(RELAY4); break;
                default: break;
            }
        }
    }
}

Credits

Jhuman Khan
22 projects • 7 followers
Diploma in Electronics, B.Sc in EEE

Comments