0% found this document useful (0 votes)
12 views8 pages

Sbit LCD

The document contains a code for a microcontroller that interfaces with an LCD and an ADC to detect metal based on input values from a buzzer. It displays messages on the LCD depending on the detected metal level, ranging from 'No Metal Detected' to various levels of 'Metal Detected' with corresponding custom characters. The program continuously checks the ADC value and updates the LCD output accordingly in a loop.

Uploaded by

elyagoubyikram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views8 pages

Sbit LCD

The document contains a code for a microcontroller that interfaces with an LCD and an ADC to detect metal based on input values from a buzzer. It displays messages on the LCD depending on the detected metal level, ranging from 'No Metal Detected' to various levels of 'Metal Detected' with corresponding custom characters. The program continuously checks the ADC value and updates the LCD output accordingly in a loop.

Uploaded by

elyagoubyikram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

sbit LCD_RS at RB0_bit;

sbit LCD_EN at RB1_bit;

sbit LCD_D7 at RB5_bit;

sbit LCD_D6 at RB4_bit;

sbit LCD_D5 at RB3_bit;

sbit LCD_D4 at RB2_bit;

sbit LCD_RS_Direction at TRISB0_bit;

sbit LCD_EN_Direction at TRISB1_bit;

sbit LCD_D7_Direction at TRISB5_bit;

sbit LCD_D6_Direction at TRISB4_bit;

sbit LCD_D5_Direction at TRISB3_bit;

sbit LCD_D4_Direction at TRISB2_bit;

const char ikram[] = {31,31,31,31,31,31,31,31};

void NEWCHAR(char pos_row, char pos_char) {

char i;

Lcd_Cmd(64);

for (i = 0; i<=7; i++) Lcd_Chr_CP(ikram[i]);

Lcd_Cmd(_LCD_RETURN_HOME);

Lcd_Chr(pos_row, pos_char, 0);

unsigned int Buzzer;

void main () {

ADC_Init();

Buzzer= ADC_Read(0);

TrisD=0x00;

PORTD = Buzzer >> 2;

Lcd_Init();

_LCD_CLEAR;
_LCD_RETURN_HOME;

LCD_Cmd(_LCD_CURSOR_OFF);

while (1) {

if (PORTD<35){

LCD_Out (1,5, "No Metal");

LCD_Out (2,5, "Detected");

else if (PORTD>=35 && PORTD<=40){

LCD_Out (1,2, "Metal Detected");

NEWCHAR(2,1);

else if (PORTD>40 && PORTD<=43){

LCD_Out (1,2, "Metal Detected");

NEWCHAR(2,1);

NEWCHAR(2,2);

else if (PORTD>43 && PORTD<=47){

LCD_Out (1,2, "Metal Detected");

NEWCHAR(2,1);

NEWCHAR(2,2);

NEWCHAR(2,3);

else if (PORTD>47 && PORTD<=51){

LCD_Out (1,2, "Metal Detected");

NEWCHAR(2,1);

NEWCHAR(2,2);

NEWCHAR(2,3);

NEWCHAR(2,4);

}
else if (PORTD>51 && PORTD<=55){

LCD_Out (1,2, "Metal Detected");

NEWCHAR(2,1);

NEWCHAR(2,2);

NEWCHAR(2,3);

NEWCHAR(2,4);

NEWCHAR(2,5);

else if (PORTD>55 && PORTD<=59){

LCD_Out (1,2, "Metal Detected");

NEWCHAR(2,1);

NEWCHAR(2,2);

NEWCHAR(2,3);

NEWCHAR(2,4);

NEWCHAR(2,5);

NEWCHAR(2,6);

else if (PORTD>59 && PORTD<=63){

LCD_Out (1,2, "Metal Detected");

NEWCHAR(2,1);

NEWCHAR(2,2);

NEWCHAR(2,3);

NEWCHAR(2,4);

NEWCHAR(2,5);

NEWCHAR(2,6);

NEWCHAR(2,7);

else if (PORTD>63 && PORTD<=67){

LCD_Out (1,2, "Metal Detected");


NEWCHAR(2,1);

NEWCHAR(2,2);

NEWCHAR(2,3);

NEWCHAR(2,4);

NEWCHAR(2,5);

NEWCHAR(2,6);

NEWCHAR(2,7);

NEWCHAR(2,8);

else if (PORTD>67 && PORTD<=71){

LCD_Out (1,2, "Metal Detected");

NEWCHAR(2,1);

NEWCHAR(2,2);

NEWCHAR(2,3);

NEWCHAR(2,4);

NEWCHAR(2,5);

NEWCHAR(2,6);

NEWCHAR(2,7);

NEWCHAR(2,8);

NEWCHAR(2,9);

else if (PORTD>71 && PORTD<=75){

LCD_Out (1,2, "Metal Detected");

NEWCHAR(2,1);

NEWCHAR(2,2);

NEWCHAR(2,3);

NEWCHAR(2,4);

NEWCHAR(2,5);

NEWCHAR(2,6);
NEWCHAR(2,7);

NEWCHAR(2,8);

NEWCHAR(2,9);

NEWCHAR(2,10);

else if (PORTD>75 && PORTD<=79){

LCD_Out (1,2, "Metal Detected");

NEWCHAR(2,1);

NEWCHAR(2,2);

NEWCHAR(2,3);

NEWCHAR(2,4);

NEWCHAR(2,5);

NEWCHAR(2,6);

NEWCHAR(2,7);

NEWCHAR(2,8);

NEWCHAR(2,9);

NEWCHAR(2,10);

NEWCHAR(2,11);

else if (PORTD>79 && PORTD<=83){

LCD_Out (1,2, "Metal Detected");

NEWCHAR(2,1);

NEWCHAR(2,2);

NEWCHAR(2,3);

NEWCHAR(2,4);

NEWCHAR(2,5);

NEWCHAR(2,6);

NEWCHAR(2,7);

NEWCHAR(2,8);
NEWCHAR(2,9);

NEWCHAR(2,10);

NEWCHAR(2,11);

NEWCHAR(2,12);

else if (PORTD>83 && PORTD<=87){

LCD_Out (1,2, "Metal Detected");

NEWCHAR(2,1);

NEWCHAR(2,2);

NEWCHAR(2,3);

NEWCHAR(2,4);

NEWCHAR(2,5);

NEWCHAR(2,6);

NEWCHAR(2,7);

NEWCHAR(2,8);

NEWCHAR(2,9);

NEWCHAR(2,10);

NEWCHAR(2,11);

NEWCHAR(2,12);

NEWCHAR(2,13);

else if (PORTD>87 && PORTD<=91){

LCD_Out (1,2, "Metal Detected");

NEWCHAR(2,1);

NEWCHAR(2,2);

NEWCHAR(2,3);

NEWCHAR(2,4);

NEWCHAR(2,5);

NEWCHAR(2,6);
NEWCHAR(2,7);

NEWCHAR(2,8);

NEWCHAR(2,9);

NEWCHAR(2,10);

NEWCHAR(2,11);

NEWCHAR(2,12);

NEWCHAR(2,13);

NEWCHAR(2,14);

else if (PORTD>91 && PORTD<=95){

LCD_Out (1,2, "Metal Detected");

NEWCHAR(2,1);

NEWCHAR(2,2);

NEWCHAR(2,3);

NEWCHAR(2,4);

NEWCHAR(2,5);

NEWCHAR(2,6);

NEWCHAR(2,7);

NEWCHAR(2,8);

NEWCHAR(2,9);

NEWCHAR(2,10);

NEWCHAR(2,11);

NEWCHAR(2,12);

NEWCHAR(2,13);

NEWCHAR(2,14);

NEWCHAR(2,15);

else if (PORTD>95){

LCD_Out (1,2, "Metal Detected");


NEWCHAR(2,1);

NEWCHAR(2,2);

NEWCHAR(2,3);

NEWCHAR(2,4);

NEWCHAR(2,5);

NEWCHAR(2,6);

NEWCHAR(2,7);

NEWCHAR(2,8);

NEWCHAR(2,9);

NEWCHAR(2,10);

NEWCHAR(2,11);

NEWCHAR(2,12);

NEWCHAR(2,13);

NEWCHAR(2,14);

NEWCHAR(2,15);

NEWCHAR(2,16);

You might also like