#include at89x51.h
#include intrins.h//for _nop_() instructions
#include stdio.h
#include stdlib.h
void init_serial_port(void);//
void init_lcd(void);
void init_timer0(void);
void init_interrupts(void);
void clear_screen(void);
void lcd_start_messeges(void);
void serial_start_messeges(void);//
void waitms(unsigned int );
void clearlcd(void);
void waitUS (unsigned char );
//void putcharlcd(unsigned char);
void putstringlcd(unsigned char *);
void positioncursor(unsigned char);
void write_lcd(unsigned char ) ;
sbit rs_lcd = P3^6; // Register Select LCD, H= Data, L = Instruction code
sbit en_lcd = P3^5; // Enable LCD H->L enable
sbit rw = P2^1;
sbit READ = P3^4; /* Define these according to how you have connected the */
sbit WRITE = P3^3;/* RD, WR, and INTR pins of ADC Connected to 89c51 */
sbit INTR = P3^2;
//*************** THE END of declaration******************************************
/* text messeges */
unsigned char code msg1[]= " MSc Physics \0";
unsigned char code msg2[]= " Microcontroller labPROJECT \0";
unsigned char code msg3[]= " Humidity Measurement \0";
unsigned char code msg4[]= " DIGITAL CLOCK \0";
unsigned char code msg5[]= " MEMMORY MAPPING \0";
unsigned char code msg6[]= " using ADC/DAC \0";
unsigned char code msg7[]= " By \0";
unsigned char code msg8[]= " Group \0";
unsigned char code msg9[]= " of \0";
unsigned char code msg10[]=" Students \0";
unsigned char code msg11[]=" 8051 class \0";
unsigned char code msg12[]=" Exploring the \0";
unsigned char code msg13[]=" New Era \0";
unsigned char code msg14[]=" Please Enter the \0";
unsigned char code msg15[]=" Current Time \0";
unsigned char code msg16[]="10% \0";
unsigned char code msg17[]="20% \0";
unsigned char code msg18[]="30% \0";
unsigned char code msg19[]="40% \0";
unsigned char code msg20[]="50% \0";
unsigned char code msg21[]="60% \0";
unsigned char code msg22[]="70% \0";
unsigned char code msg23[]="80% \0";
unsigned char code msg24[]="90 %\0";
unsigned char code msg25[]="100 %\0";
/* Variable declartion for the clock */
char data hrs_str[2];
char data TIME[6]; // Var array total unit calculation
char data LAMHA=0;
char data SEC;
char data MIN;
char data HOUR;
char data TEMEP=0;
char data TEMEP1=0;
char data temp[2];
char data min_str[3];
unsigned char adVal;
unsigned long volts;
/****************************************/
/* end of text messeges block */
// global variables declarations
/*++++++++++++++++++++++++++++*/
void main (void) { //enable global interrupt
min_str[2] ='\0';
rw = 0 ;
init_serial_port();//
clear_screen();
init_lcd();
serial_start_messeges();//
lcd_start_messeges();
init_timer0();
ES =1;
IT0=1;
READ=1;
WRITE=0;
waitms(150);
READ=0;
WRITE=1;
READ=1;
WRITE=0;
waitms(100);
WRITE=1;
while (1) {}
}
void timer0(void) interrupt 1 { //every 10msec
TR0=0;//stop the timer 0
TH0 = 0xDC;
TL0 = 0x11;
TR0= 1;
LAMHA++;
if(LAMHA>=100)
{ LAMHA=0;
SEC++;
/* dispaly time after every second at lcd */
if(SEC>=59)
{ SEC=0;
MIN++;
if(MIN>=59)
{ MIN=0;
HOUR++;
READ=1;
WRITE=0;
READ=0;
WRITE=1;
READ=1;
WRITE=0;
waitms(200);
WRITE=1;
if(HOUR>=13)
HOUR=1;
}
}
////////////////////////////////////////////////////////////
TIME[0]=(HOUR/10)+0x30;
TIME[1]=(HOUR%10)+0x30;
TIME[2]=(MIN/10)+0x30;
TIME[3]=(MIN%10)+0x30;
TIME[4]=(SEC/10)+0x30;
TIME[5]=(SEC%10)+0x30;
positioncursor(0x40); //2nd line
write_lcd(TIME[0]);
write_lcd(TIME[1]);
write_lcd(':');
write_lcd(TIME[2]);
write_lcd(TIME[3]);
write_lcd(':');
write_lcd(TIME[4]);
write_lcd(TIME[5]);
/* send time at serial port */
//printf("\n Current Time is \n ");
putchar(0x0D);
putchar(TIME[0]);
putchar(TIME[1]);
putchar(':');
putchar(TIME[2]);
putchar(TIME[3]);
putchar(':');
putchar(TIME[4]);
putchar(TIME[5]);
//////////////////////////////////////////////////////////////
} }
// InitIO();
//Define External interrupt
void ext_int0(void) interrupt 0{
// READ = 1;
WRITE = 1;
// INTR = 1;
// while(1) {
//Make a low-to-high transition on the WR input
// while( INTR == 1 ); // wait until the INTR signal makes
//high-to-low transition indicating
//completion of conversion
//Read the voltage value from the port
READ = 0;
waitms(400);
adVal = P0;
puts("\n Current HUMIDITY IS \n");
if(adVal<=0x19) {positioncursor(0x00); //first line putstringlcd(msg16); putchar(0x00); puts(msg16);} if(adVal>0x19 && adVal<=0x32) { positioncursor(0x00); //first line putstringlcd(msg17); putchar(0x00); puts(msg17);} if(adVal>0x32 && adVal<=0x4B) { positioncursor(0x00); //first line putstringlcd(msg18); putchar(0x00); puts(msg18);} if(adVal>0x4B && adVal<=0x64) { positioncursor(0x00); //first line putstringlcd(msg19); putchar(0x00); puts(msg19);} if(adVal>0x64 && adVal<=0x7D) {positioncursor(0x00); //first line putstringlcd(msg20); putchar(0x00); puts(msg20);} if(adVal>0x7D && adVal<=0x96) { positioncursor(0x00); //first line putstringlcd(msg21); putchar(0x00); puts(msg21);} if(adVal>0x96 && adVal<=0xAF) { positioncursor(0x00); //first line putstringlcd(msg22); putchar(0x00); puts(msg22);} if(adVal>0xAF && adVal<=0xC8) { positioncursor(0x00); //first line putstringlcd(msg23); putchar(0x00); puts(msg23);} if(adVal>0xC8 && adVal<=0xE1) { positioncursor(0x00); //first line putstringlcd(msg24); putchar(0x00); puts(msg24);} if(adVal>0xE1 && adVal<=0xFF) { positioncursor(0x00); //first line putstringlcd(msg25); putchar(0x00); puts(msg25);} READ = 1; INTR=1; //Compute the digital value of the volatge read //Print the value of the voltage in decimal form //} } void serial_recieve(void) interrupt 4 { if(RI) { RI= 0; if(SBUF == 's'| SBUF == 'S') { puts("\n Enter Time, hhmmss \n"); hrs_str[0]=getchar(); hrs_str[1]=getchar(); HOUR= (char)atoi(hrs_str); min_str[0]=getchar(); min_str[1]=getchar(); MIN= (char)atoi(min_str); SEC = 0x00; } } } void clearlcd(void){ rs_lcd =0; write_lcd(0x01); rs_lcd =1; } void positioncursor(unsigned char c ){ rs_lcd = 0; write_lcd(0x80 | c); // 1xxx xxxx set address of cursor rs_lcd =1; } void putstringlcd(unsigned char *d){ while(!(*d == '\0')){ write_lcd(*d); d++; }} void write_lcd(unsigned char a) { P1 = a; waitUS(250); waitUS(250); waitUS(250); waitUS(250); en_lcd = 0; waitUS(250); en_lcd = 1; } void waitUS(unsigned char a){ while(--a != 0); /* wait = a * 2 + 5 usec @ 12 MHz*/ } void waitms(unsigned int a) { while (--a !=0) { waitUS(247); //500us delay waitUS(247); waitUS(247); //500us delay waitUS(247); } } void lcd_start_messeges(void) { positioncursor(0x00); //first line putstringlcd(msg1); positioncursor(0x40); //2nd line putstringlcd(msg2); waitms(800); clearlcd(); positioncursor(0x00); //first line putstringlcd(msg3); positioncursor(0x40); //2nd line putstringlcd(msg4); waitms(800); clearlcd(); positioncursor(0x00); //first line putstringlcd(msg5); positioncursor(0x40); //2nd line putstringlcd(msg6); waitms(800); clearlcd(); positioncursor(0x00); //first line putstringlcd(msg7); waitms(800); clearlcd(); positioncursor(0x00); //first line putstringlcd(msg8); positioncursor(0x40); //2nd line putstringlcd(msg9); waitms(800); clearlcd(); positioncursor(0x00); //first line putstringlcd(msg10); positioncursor(0x40); //2nd line putstringlcd(msg11); waitms(800); clearlcd(); positioncursor(0x00); //first line putstringlcd(msg12); positioncursor(0x40); //2nd line putstringlcd(msg13); waitms(800); clearlcd(); positioncursor(0x00); //first line putstringlcd(msg14); positioncursor(0x40); //2nd line putstringlcd(msg15); waitms(800); clearlcd(); } void init_serial_port(void) { SCON = 0x52; //SCON: mode 1, 8-bit UART, enable rcvr TMOD |= 0x20; // timer 1 autoreload mode */ TH1 = -12; // TH1: (smod disable ) // -13 reload value for 2400 baud @ 11.0592 MHz TR1 = 1; //TR1: timer 1 run TI = 1; //TI: set TI to send first char of UART } void init_timer0(void) { TMOD &=~0x0F; //clear timer0 mode bits TMOD |= 0x01; //put time0 in 16 bit TH0 = 0xDC; TL0 = 0x11; T0 =0; // set low periority for timer0 ET0 =1; //enable timer 0 interrupt TR0 =1; EA = 1; EX0=1; } void init_interrupts(void) { IE = 0x93; // enable globle , serial and timer0 interrupt IP |= 0x01; // high priority for serial interrupt IT0=1;//TCON |= 0x01; // low edge triggered interrupts } void init_lcd(void){ rs_lcd = 0 ; //for cmd waitms(500); write_lcd(0x38); //Function Set 0011 1000 waitms(100); write_lcd(0x38); //Function Set 0011 1000 waitms(100); write_lcd(0x38); //Function Set 0011 1000 waitms(100); write_lcd(0x0C); //display off/ON No Cursor No Blinking at cursor waitms(100); write_lcd(0x01); //clear Display waitms(100); write_lcd(0x06); //Entry Mode Set rs_lcd = 1 ; // for data } void serial_start_messeges(void) { puts ("this is serial"); puts (msg2); puts (msg3); puts (msg4); puts (msg5); puts (msg6); puts (msg7); puts (msg8); puts (msg9); puts (msg10); puts (msg11); puts (msg12); puts (msg13); puts (msg14); puts (msg15); } void clear_screen(void){ unsigned char i=50; while (--i >=1)
putchar(0x0A);
putchar(0x0D);
}
This is code of the microcontroller project.
BACK to Content Page .Tags:- 8051/AT89S52 based SMOKE DETECTOR and FIRE ALARM SYSTEM Embedded Instrumentation Monolithic Thermocouple Amplifiers AD594 AND AD595 humidity measurement Free 8051 microcontroller resources, PAULMON - Easy To Use Monitor Program, AS31 Assembler, Development Circuit Board Design, Code Library humidity chart humidity control dew point
humidity calculator PIC-Microcontroller Code Samples humidity sensor 8051 pwm code : 8051 Microcontroller Projects AVR PIC Projects absolute humidity precipitation Microcontroller Based Digital code Lock (AT89C2051) vaisala humidity transmitter 8051 Microprocessor Example Program minco humidity transmitter Download Example Programs for C Compiler for 8051 humidity sensor 8051 Programs examples & tutorial industrial humidity meter C/C++ Compiler 8051 - IAR Embedded Workbench for 8051 humidity measuring meter pascal compiler 8051 use humidity meter Commercial 8051 Compiler - Schematic drafting, printed circuit checking humidity humidity meter price Interfacing Humidity Sensor with 8051 Microcontroller. This AT89C51 based Humidity Detector Project described with circuit diagram,Project: Temperature and Humidity Data Logger Project