PIC Micro-controller

Think of a PIC microcontroller as the brain of your favorite gadgets. It's like a super-smart computer chip that can be taught to do all sorts of things, like switching on lights, sensing the environment around it, or showing information on a screen. These little chips are really powerful, even though they're tiny!

You can find PIC microcontrollers in all sorts of everyday things, like your TV remote, the equipment doctors use in hospitals, and even some of the appliances in your kitchen. They're the secret sauce that makes these devices work smoothly and do exactly what we want them to do.

 NOTE : THE SHARED CODE MIGHT NOT BE APPROPRIATE TO VIEW ON MOBILE DEVICES KINDLY PREFER LAPTOP/PC.


Temperature monitoring system using transmitter and receiver:

Here's how it works: The transmitter, equipped with a temperature sensor, keeps a constant watch on the surroundings. Once the temperature hits a set limit, it wirelessly sends this data to the receiver.

On the receiver's end, the data is received and analyzed. If the temperature goes beyond the pre-set threshold, it alerts you promptly. This means you can take action quickly to maintain the right temperature conditions.

source code:


TRANSMITTER CODE
#include <p18f4550.h>
#include "UART.h"
#include "ADC_LCD.h"
char temp_str[10]; 
unsigned int adc_value;
int temperature;
void main(void) 
{
    OSCCON = 0x72;
    UART_Initial(9600);
    TRISD = 0x00;  
    TRISEbits.TRISE0 = 1;
    ADC_Init();    
    while (1) {
        adc_value = ADC_Read();
        temperature = ADC_to_Temperature(adc_value);
        sprintf(temp_str, "%d", temperature);
        if (temperature >= 30) {
            UART_Write('1');
        } else {
            UART_Write('0');
        }
        MSdelay(100); 
    }
    return;
}

RECEIVER CODE


#include <p18f4550.h>
#define red PORTCbits.RC0
#define blue PORTCbits.RC1

#define F_CPU 8000000/64
int k;

char warning[]="WARNING";
void MSdelay(unsigned int val)
{
unsigned int i,j;
for(i=0;i<=val;i++)

for(j=0;j<81;j++); 

}
void UART_Initial(long baud_rate) {
    float bps; 
    TRISCbits.TRISC6 = 1;
    TRISCbits.TRISC7 = 1;

    bps = ((float)(F_CPU) / (float)baud_rate) - 1;
    SPBRG = (int)bps; 
    TXSTAbits.CSRC = 0;
    TXSTAbits.TX9 = 0; 

    TXSTAbits.TXEN = 1; 
    TXSTAbits.SYNC = 0; 
    TXSTAbits.BRGH = 0; 
    RCSTAbits.SPEN = 1;
    RCSTAbits.RX9 = 0;
    RCSTAbits.CREN = 1; 
}

void UART_Write(char data) {

    TXREG = data; 
    while (!TXSTAbits.TRMT); 
}
char UART_Read(void) {

    while (!PIR1bits.RCIF); 
    return RCREG; 
}
void UART_String(const char *str) {
    while (*str != '\0') {
        UART_Write(*str);

        str++;
    }
}

void main(void) {
    char received_data;
    OSCCON = 0x72; 
    UART_Initial(9600);
    TRISCbits.TRISC0 = 0;   
    TRISCbits.TRISC1 = 0;
    blue=1;
    while (1) {
        if (PIR1bits.RCIF) {
            received_data = UART_Read();
            if (received_data == '1') {
               red=1;
               blue=0;

               UART_String(warning);             

            } 
            else if (received_data == '0') {

                red = 0; 
                blue=1;
            }
        }
    }
}






Comments

Popular Posts