ecaits
Member level 4
- Joined
- Jan 16, 2014
- Messages
- 76
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 579
On above subject, I can successfully compile the code but cannot getting output in real pic simulator.
I am taking input in A port and wanted output in LED as well as LCD.
Code is given below.
Plz suggest me which is the missing portion???
#include<htc.h>
#include<pic.h>
#include<math.h>
#include<stdio.h>
#define RS RE0 //LCD Register Select
#define RW RE1 //LCD Read/Write Pin
#define EN RE2 //LCD Enable Pin
#define DATA PORTD //LCD Data Port
void linit(void); //LCD initialization Function
void lclr(void); //LCD Clear Function
void lcomd(unsigned char); //LCD Command Declaring Fucntion
void ldata(char); //LCD Data Display Fucntion
// void DelayMs(unsigned int);
#define _XTAL_FREQ 4000000
unsigned int ADC_Read(unsigned char);
void ADC_Init();
//unsigned int GO_nDONE;
void ADC_Init()
{
ADCON0 = 0x41;
ADCON1 = 0xC0; //right justified
}
unsigned int ADC_Read(unsigned char channel)
{
int i;
char a,b,c,d;
if(channel > 7)
return 0;
ADCON0 &= 0xC5;
ADCON0 |= channel<<3;
__delay_ms(2);
GODONE = 1;
while(GODONE);
i = ((ADRESH<<8)+ADRESL);
a=i/1000;
b=i%1000;
b=b/100;
c=b%10;
c=c/10;
d=c%10;
__delay_ms(20);
return (a);
__delay_ms(20);
return (b);
__delay_ms(20);
return (c);
__delay_ms(20);
return (d);
__delay_ms(20);
ldata(a);
__delay_ms(20);
ldata(b);
__delay_ms(20);
ldata(c);
__delay_ms(20);
ldata(d);
__delay_ms(20);
}
void linit(void)
{
int x;
unsigned char command[]={0x38,0x0c,0x06,0x01};
//LCD Command set for 8 bit Interface, 2 Lines, 5x7 Dots
//38 = 2 lines and 5x7 matrix
//0c = force cursor to begining of 2nd line
//06 = shift cursor to right
//01 = clear display screen
ADCON1 = 0x07; //Make PORTE Pin as Digital
TRISD = 0x00; //Make LCD control port (PORTE) as output
TRISE = 0x00;
__delay_ms(50);
// DelayMs(50); //Make LCD Data Port (PORTD) as output port
for(x=0;x<4;x++)
{
lcomd(command[x]); //Send the Initialisation Commands
__delay_ms(50);
// DelayMs(5);
}
__delay_ms(50);
// DelayMs(50);
}
void lclr(void) // 01 = LCD clear command
{
lcomd(0x01);
__delay_ms(20);
// DelayMs(20);
}
void lcomd(unsigned char cmd)
{
RS=0; RW=0; //Select Command Register, R/W--write enabled
//RS = 0 means data treated as command, 1 means data treated as text
//RW = 0 means write mode, 1 means read mode
EN=1; //Enable LCD to accept commands
DATA=cmd;
EN=0;
// DelayMs(50); //Give a Pulse via Enable pin
__delay_ms(50);
}
void ldata(char byte)
{
RS=1; RW=0; //Select Data register, R/W--write enabled
EN=1;
DATA=byte; //Give a Pulse via Enable pin
EN=0;
// DelayMs(5);
__delay_ms(5);
}
/* void DelayMs(unsigned int Ms)
{
int delay_cnst;
while(Ms>0)
{
Ms--;
for(delay_cnst = 0;delay_cnst <220;delay_cnst++);
}
}
*/
void main()
{
unsigned int a,i;
double x;
TRISB = 0x00;
TRISC = 0x00;
ADC_Init();
// unsigned char first[]={"Hello"};
// DelayMs(50);
__delay_ms(5);
linit();
// DelayMs(50);
__delay_ms(5);
while(1)
{
lclr();
lcomd(0x80); // 80 = force cursor at begining of 1st line
/* for(i=0;i<10;i++) //Display the Message
{
ldata(first);
DelayMs(50);
} */
}
do
{
a = ADC_Read(0);
PORTB = a;
PORTC = a>>8;
__delay_ms(100);
}while(1);
}
I am taking input in A port and wanted output in LED as well as LCD.
Code is given below.
Plz suggest me which is the missing portion???
#include<htc.h>
#include<pic.h>
#include<math.h>
#include<stdio.h>
#define RS RE0 //LCD Register Select
#define RW RE1 //LCD Read/Write Pin
#define EN RE2 //LCD Enable Pin
#define DATA PORTD //LCD Data Port
void linit(void); //LCD initialization Function
void lclr(void); //LCD Clear Function
void lcomd(unsigned char); //LCD Command Declaring Fucntion
void ldata(char); //LCD Data Display Fucntion
// void DelayMs(unsigned int);
#define _XTAL_FREQ 4000000
unsigned int ADC_Read(unsigned char);
void ADC_Init();
//unsigned int GO_nDONE;
void ADC_Init()
{
ADCON0 = 0x41;
ADCON1 = 0xC0; //right justified
}
unsigned int ADC_Read(unsigned char channel)
{
int i;
char a,b,c,d;
if(channel > 7)
return 0;
ADCON0 &= 0xC5;
ADCON0 |= channel<<3;
__delay_ms(2);
GODONE = 1;
while(GODONE);
i = ((ADRESH<<8)+ADRESL);
a=i/1000;
b=i%1000;
b=b/100;
c=b%10;
c=c/10;
d=c%10;
__delay_ms(20);
return (a);
__delay_ms(20);
return (b);
__delay_ms(20);
return (c);
__delay_ms(20);
return (d);
__delay_ms(20);
ldata(a);
__delay_ms(20);
ldata(b);
__delay_ms(20);
ldata(c);
__delay_ms(20);
ldata(d);
__delay_ms(20);
}
void linit(void)
{
int x;
unsigned char command[]={0x38,0x0c,0x06,0x01};
//LCD Command set for 8 bit Interface, 2 Lines, 5x7 Dots
//38 = 2 lines and 5x7 matrix
//0c = force cursor to begining of 2nd line
//06 = shift cursor to right
//01 = clear display screen
ADCON1 = 0x07; //Make PORTE Pin as Digital
TRISD = 0x00; //Make LCD control port (PORTE) as output
TRISE = 0x00;
__delay_ms(50);
// DelayMs(50); //Make LCD Data Port (PORTD) as output port
for(x=0;x<4;x++)
{
lcomd(command[x]); //Send the Initialisation Commands
__delay_ms(50);
// DelayMs(5);
}
__delay_ms(50);
// DelayMs(50);
}
void lclr(void) // 01 = LCD clear command
{
lcomd(0x01);
__delay_ms(20);
// DelayMs(20);
}
void lcomd(unsigned char cmd)
{
RS=0; RW=0; //Select Command Register, R/W--write enabled
//RS = 0 means data treated as command, 1 means data treated as text
//RW = 0 means write mode, 1 means read mode
EN=1; //Enable LCD to accept commands
DATA=cmd;
EN=0;
// DelayMs(50); //Give a Pulse via Enable pin
__delay_ms(50);
}
void ldata(char byte)
{
RS=1; RW=0; //Select Data register, R/W--write enabled
EN=1;
DATA=byte; //Give a Pulse via Enable pin
EN=0;
// DelayMs(5);
__delay_ms(5);
}
/* void DelayMs(unsigned int Ms)
{
int delay_cnst;
while(Ms>0)
{
Ms--;
for(delay_cnst = 0;delay_cnst <220;delay_cnst++);
}
}
*/
void main()
{
unsigned int a,i;
double x;
TRISB = 0x00;
TRISC = 0x00;
ADC_Init();
// unsigned char first[]={"Hello"};
// DelayMs(50);
__delay_ms(5);
linit();
// DelayMs(50);
__delay_ms(5);
while(1)
{
lclr();
lcomd(0x80); // 80 = force cursor at begining of 1st line
/* for(i=0;i<10;i++) //Display the Message
{
ldata(first);
DelayMs(50);
} */
}
do
{
a = ADC_Read(0);
PORTB = a;
PORTC = a>>8;
__delay_ms(100);
}while(1);
}
Last edited: