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

LCD Test

This code defines functions for initializing and sending data to an LCD display. It initializes the LCD display by sending initialization commands. It then displays static text on the first and second lines of the LCD. It periodically reads sensor data from an analog-to-digital converter and displays the sensor values on the LCD. The main loop continuously reads the sensors, displays the values, and waits before repeating.

Uploaded by

balabooks
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)
80 views8 pages

LCD Test

This code defines functions for initializing and sending data to an LCD display. It initializes the LCD display by sending initialization commands. It then displays static text on the first and second lines of the LCD. It periodically reads sensor data from an analog-to-digital converter and displays the sensor values on the LCD. The main loop continuously reads the sensors, displays the values, and waits before repeating.

Uploaded by

balabooks
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
You are on page 1/ 8

#include <htc.

h>
#define ldata PORTD
#define rs RE2
#define rw RE1
#define en RE0
#define device RB1
void Lcdinit();
void Lcddisplay(unsigned char value[]);
void lcddata(unsigned char value);
void Lcdcmd(unsigned char value);
void delay();
void delay1();
void serial_txr(unsigned char a);

void delay()
{
int i;
for(i=0;i<200;i++);
}

void delay1()
{
int i;
for(i=0;i<50;i++);
}

void Lcdinit()
{
Lcdcmd(0x38);
delay();
delay();
delay();
delay();
Lcdcmd(0x38);
delay();
delay();
delay();
delay();

Lcdcmd(0x38);
delay();
delay();
delay();
delay();

Lcdcmd(0x01);
delay();
Lcdcmd(0x02);
delay();
Lcdcmd(0x08);
delay();
Lcdcmd(0x0c);
delay();
Lcdcmd(0x06);
delay();
Lcdcmd(0x80);
delay();
}

void Lcdcmd(unsigned char value)
{
ldata=value;
rs=0;
rw=0;
en=1;
delay1();
en=0;
return;
}

void lcddata(unsigned char value)
{
ldata=value;
rs=1;
rw=0;
en=1;
delay1();
en=0;
}

void delay2()
{
long i;
for(i=0;i<50000;i++);
}

void serial_txr(unsigned char a)
{
TXREG=a;
while(TXIF==0);
}

unsigned char val[6],flagx=0,val1[90];


void Delay()
{
long i;
for(i=0;i<40000;i++)
{


}
}

/* Sample code to set up the A2D module */
void init_a2d(void){
ADCON0=0; // select Fosc/2
ADCON1=2; // select left justify result. A/D port configuration 0
ADON=1; // turn on the A2D conversion module
}

/* Return an 8 bit result */
unsigned char read_a2d(unsigned char channel){
channel&=0x07; // truncate channel to 3 bits
ADCON0&=0xC5; // clear current channel select
ADCON0|=(channel<<3); // apply the new channel select
ADGO=1; // initiate conversion on the selected channel
while(ADGO)continue;
return(ADRESH); // return 8 MSB of the result
}


void main() //Main entry
{
unsigned char temp,gas;


TRISC=0X80;
TXSTA=0X26;
RCSTA=0X90;
SPBRG=0X20;
CMCON=0x07;
//RCSTA=0x90; // receive enabling with the same speed
// TXSTA =(0x24); // High speed selection baud rate 9600
//SPBRG = 64;
CVRCON=0x00;
TRISD=0x00;
TRISE=0x00;
TRISA=0x00; //output for devices
Lcdinit();

init_a2d();

TRISB=0xFF;
device=0;
Lcdcmd(0x01);
delay();
delay();
delay();

Lcdcmd(0x80);
lcddata(' ');
lcddata(' ');
lcddata(' ');
lcddata('L');
lcddata('P');
lcddata('G');
lcddata(' ');
lcddata('R');
lcddata('E');
lcddata('F');
lcddata('I');
lcddata('L');
lcddata('L');
lcddata(' ');

lcddata('&');
lcddata('&');

Lcdcmd(0xC0);

lcddata('L');
lcddata('E');
lcddata('A');
lcddata('K');
lcddata('A');
lcddata('G');
lcddata('E');
lcddata(' ');
lcddata('S');
lcddata('Y');
lcddata('S');
lcddata('T');
lcddata('E');
lcddata('M');
lcddata(' ');

delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();delay2();
delay2();
delay2();
delay2();
delay2();
//Lcdcmd(0x01);
delay();
delay();
delay();

/*Lcdcmd(0x80);
lcddata(' ');
lcddata(' ');
lcddata('B');
lcddata('Y');
lcddata(' ');
lcddata('T');
lcddata('H');
lcddata('I');
lcddata('R');
lcddata('U');
lcddata('T');
lcddata('H');
lcddata('A');

lcddata('N');
lcddata('I');

lcddata(' ');
lcddata(' ');
Lcdcmd(0xC0);
lcddata(' ');
lcddata(' ');
lcddata(' ');
lcddata(' ');
lcddata('P');
lcddata('O');
lcddata('L');
lcddata('Y');
lcddata('T');
lcddata('E');
lcddata('C');
lcddata('H');
lcddata('N');
lcddata('I');
lcddata('C'); */

delay2();delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();

//device=0x01;


while(1)
{


if (device==1)
{
Lcdcmd(0x01);
delay();
delay();
delay();

Lcdcmd(0x80);
lcddata(' ');
lcddata(' ');
lcddata('G');
lcddata('A');
lcddata('S');
lcddata(' ');
lcddata('L');
lcddata('E');
lcddata('K');
lcddata('A');
lcddata('G');
lcddata('E');
lcddata(' ');

lcddata(' ');
lcddata(' ');

lcddata(' ');
lcddata(' ');
Lcdcmd(0xC0);
lcddata(' ');
lcddata(' ');
lcddata('D');
lcddata('E');
lcddata('T');
lcddata('E');
lcddata('C');
lcddata('T');
lcddata('E');
lcddata('D');
lcddata(' ');
lcddata(' ');
lcddata(' ');
lcddata(' ');
lcddata(' ');

delay2();delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
}

delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
delay2();


delay2();
delay2();
delay2();
delay2();delay2();
delay2();
delay2();
delay2();
delay2();
delay2();
}

}

You might also like