Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
71 views

Code For Major Project

This document contains code to control an LCD display and read an analog to digital converter (ADC) value on a PIC microcontroller. It initializes the LCD, defines pin assignments, and includes a main loop that displays the gate status (open or closed) based on the ADC reading. If the ADC value is below 25, it displays "Gate Open", otherwise it displays "Gate Closed".

Uploaded by

Shalini Rai
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Code For Major Project

This document contains code to control an LCD display and read an analog to digital converter (ADC) value on a PIC microcontroller. It initializes the LCD, defines pin assignments, and includes a main loop that displays the gate status (open or closed) based on the ADC reading. If the ADC value is below 25, it displays "Gate Open", otherwise it displays "Gate Closed".

Uploaded by

Shalini Rai
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

#include<pic.

h>

#define delay for(i=0;i<=1000;i++)

#define rs RC0

#define rw RC1

#define e RC3

#define relay RC2

__CONFIG( FOSC_HS & WDTE_OFF & PWRTE_OFF & CP_OFF & BOREN_ON &
LVP_OFF & CPD_OFF & WRT_OFF & DEBUG_OFF);

unsigned int adc();

LCD CODE

void lcd_int();

void cmd(unsigned char a);

void dat(unsigned char b);

void show(unsigned char *s);

int i;
void main()

TRISB=TRISC=0; //Port B and Port C is Output (LCD)

TRISA0=1; //RA0 is input (ADC)

lcd_int();

while(1) {

cmd(0x80);

show("No os slots available");

cmd(0x8D);

unsigned int val=adc();

show(" ");

if(val<= 25)

cmd(0xc0);

show("Gate Open ");

relay = 1;

}
else

cmd(0xc0);

show("Gate closed ");

relay = 0;

void lcd_int()

cmd(0x38);

cmd(0x0c);

cmd(0x06);

cmd(0x80);

}
void cmd(unsigned char a)

PORTB=a;

rs=0;

rw=0;

e=1;

delay;

e=0;

void dat(unsigned char b)

PORTB=b;

rs=1;

rw=0;

e=1;

delay;

e=0;
}

void show(unsigned char *s)

while(*s) {

dat(*s++);

unsigned int adc()

unsigned int adcval;

ADCON1=0xc0; //right justified

ADCON0=0x85; //adc on, fosc/64

while(GO_nDONE); //wait until conversion is finished

adcval=((ADRESH<<8)|(ADRESL)); //store the result

//adcval=(adcval/3)-1;
adcval = ((float)adcval/1023.0)*100.0;

//dat((adcval/1000)+48);

dat(((adcval/100)%10)+48);

dat(((adcval/10)%10)+48);

dat((adcval%10)+48);

return adcval;

You might also like