Skip to content

Instantly share code, notes, and snippets.

@d-boz-wtwh
Created October 22, 2019 21:01
Show Gist options
  • Save d-boz-wtwh/8f409e632abe4ae7f2ad6ec63ac08bdb to your computer and use it in GitHub Desktop.
Save d-boz-wtwh/8f409e632abe4ae7f2ad6ec63ac08bdb to your computer and use it in GitHub Desktop.
Microcontroller Projects
#include<reg51.h>
sbit rs=P3^5; //Register select (RS)
sbit en=P3^6; //Enable (EN) pin
sbit cs=P3^0;
sbit wr= P3^1;
sbit rd= P3^2;
sbit intr= P3^3;
void delay(unsigned int time) //Time delay function
{
unsigned int i,j;
for(i=0;i< time;i++)
for(j=0;j<5;j++);
}
void lcdcmd(unsigned char value) //Function for sending values to the command register of LCD
{
P1=value;
P3=0x40;
delay(50);
en=0;
delay(50);
return;
}
void display(unsigned char value) //Function for sending values to the data register of LCD
{
P1=value;
P3=0x60;
delay(500);
en=0;
delay(50);
return;
}
void lcdint(void) //function to initialize the registers and pins of LCD
{
P1=0x00;
P2=0x00;
P3=0x00;
delay(15000);
display(0x30);
delay(4500);
display(0x30);
delay(300);
display(0x30);
delay(650);
lcdcmd(0x38);
lcdcmd(0x0F);
lcdcmd(0x01);
lcdcmd(0x06);
lcdcmd(0x80);
}
void main()
{
unsigned int Adcvalue,Adcvalue1;
char ch1,ch2,ch3;
P1=0x00; //Declared as Output port
P3=0x00; //Output port
P2=0xFF; //Input port
lcdint();
while (1){
delay(10000);
cs=0; //chipselect is on now --It is active low pin
wr=0; // write is enabled --It is also active low
delay(10);
wr=1; //start conversion analog to digital
rd=1;
while(intr==1); //The looop runs until intr==1 and
//when intr==0 it jumps to next iteration
rd=0; //read the digital output from adc
Adcvalue=P2;
ch1=Adcvalue/100;
if(ch1!=0)
display(ch1+0x30);
delay(100);
Adcvalue1=Adcvalue%100;
ch2=Adcvalue1/10;
display(ch2+0x30);
ch3=Adcvalue1-(ch2*10);
display(ch3);
delay(10000);
lcdcmd(0x01);
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment