![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jun 2008
Posts: 11
Rep Power: 0
![]() |
Hello. I have some problem with my LCD codes. I'm using an 8x2 character display. The program codes can be build successfully in the MP lab program but the characters would not show on the LCD. I tried troubleshooting but i cant find the problem. Below is my LCD codes. Any help is greatly appreciated(:
#include<p18f2620.h>
#include<delays.h>
#include<string.h>
void Init_LCD(void);
void W_LCD(char,char);
void Out_LCD(char rom near*);
void Out_Dec_LCD(unsigned int i);
void Out_Hex_LCD(unsigned int i);
void Puts_LCD(char *);
char Hex2ascii(char);
void LCD_Intro(void);
void disp_val(void);
void Delay_msec(unsigned int);
void Delay_sec(unsigned int);
#define LCD_DATA PORTB
#define LCD_E PORTBbits.RB1
#define LCD_RS PORTBbits.RB0
#define PB1 PORTAbits.RA4
#define ROM_TYPE (char rom near*)
#define OSC_FREQ 32000000
#define DELAY1MS 8 // 1ms delay = OSC_FREQ/(4*1000*1000)
#define DELAY1S 200 // 1s delay = OSC_FREQ/(4*10000*4)
#define LCD_Line1 W_LCD(0x80,0)
#define LCD_Line2 W_LCD(0xC0,0)
#define CLEAR_LCD W_LCD(0x01,0)
#define HOME_LCD W_LCD(0x02,0)
unsigned char LCD_TEMP;
unsigned int i,x,y;
void main()
{
TRISA = 0b11111111;
TRISB = 0b00001100; // PORTB=>LCD_DATA, RB0=>LCD_E, RB1=>LCD_RS;
while(1)
{
if(PB1==1)
{
Init_LCD();
LCD_Intro();
// Prompt user to put on cuff
W_LCD(0x81,0);
Out_LCD(ROM_TYPE "Put on");
W_LCD(0xC2,0);
Out_LCD(ROM_TYPE "cuff");
Delay_sec(5); // Wait for 5 seconds
W_LCD(0b00000001,0);
for(x=10; x>0; x--)
{
W_LCD(0x81,0);
Out_LCD(ROM_TYPE "s");
Delay_sec(1);
W_LCD(0b00000001,0);
}
for(y=60; y>0; y--)
{
W_LCD(0x81,0);
Out_LCD(ROM_TYPE "Taking");
W_LCD(0xC1,0);
Out_LCD(ROM_TYPE "your BP");
Delay_msec(1000); // Wait for 60 seconds
W_LCD(0b00000001,0);
W_LCD(0x81,0);
Out_LCD(ROM_TYPE " ");
W_LCD(0x81,0);
Out_LCD(ROM_TYPE " ");
Delay_msec(1000);
}
W_LCD(0x83,0);
Out_LCD(ROM_TYPE "BP");
W_LCD(0xC2,0);
Out_LCD(ROM_TYPE "Taken");
Delay_sec(3); // Wait for 3 seconds
W_LCD(0b00000001,0);
disp_val(); // Display BP measurements
}
}
}
// Initialise LCD
void Init_LCD() // LCD display Initialization
{
W_LCD(0x03 ,0);
Delay_msec(15);
W_LCD(0x02 ,0);
Delay_msec(5);
W_LCD(0x28 ,0);
Delay_msec(1);
W_LCD(0x0C ,0);
Delay_msec(1);
W_LCD(0x06 ,0);
Delay_msec(1);
W_LCD(0x01 ,0);
Delay_msec(5);
}
void W_LCD(char x, char i)
{
LCD_RS = i;
LCD_TEMP = x;
LCD_TEMP &= 0xF0;
LCD_E = 1;
LCD_DATA = LCD_TEMP;
Delay_msec(1);
LCD_E = 0;
Delay_msec(1);
LCD_TEMP = x;
LCD_TEMP <<= 4;
LCD_E = 1;
LCD_DATA = LCD_TEMP;
Delay_msec(1);
LCD_E = 0;
Delay_msec(1);
}
// Display const message on LCD
void Out_LCD(char rom near *message)
{
while (*message)
{
W_LCD(*message,1);
message++;
}
}
// Print decimal number to LCD
void Out_Dec_LCD(unsigned int i)
{
char digit, zero, value;
long denom;
denom = 1000000000;
zero = 1;
if (!value)
W_LCD('0',1);
else
{
while (denom)
{
digit = value/denom;
if (digit)
{
W_LCD(digit + '0',1);
zero = 0;
}
else if (!zero)
W_LCD('0',1);
value -= digit*denom;
denom /= 10;
}
}
}
// Print hexadecimal number to LCD
void Out_Hex_LCD(unsigned int i)
{
unsigned char ctmp0, ctmp1, ctmp2, ctmp3;
ctmp0 = 0x000f & i;
i >>= 4;
ctmp1 = 0x000f & i;
i >>= 4;
ctmp2 = 0x000f & i;
i >>= 4;
ctmp3 = 0x000f & i;
W_LCD(Hex2ascii(ctmp3),1);
W_LCD(Hex2ascii(ctmp2),1);
W_LCD(Hex2ascii(ctmp1),1);
W_LCD(Hex2ascii(ctmp0),1);
}
// Convert hexadecimal number to ASCII character
char Hex2ascii(char c)
{
c &= 0x07;
if(c < 0x0a)
return (c + 0x30);
else
return (c + 0x37);
}
// Output variable string to LCD
void Puts_LCD(char *message)
{
while (*message)
{
W_LCD(*message,1);
message++;
}
}
// Output initialisation messages
void LCD_Intro(void)
{
CLEAR_LCD;
W_LCD(0x80,0);
Out_LCD(ROM_TYPE "TEMASEK");
W_LCD(0xC2,0);
Out_LCD(ROM_TYPE "POLY");
Delay_sec(2);
W_LCD(0b00000001,0);
W_LCD(0x80,0);
Out_LCD(ROM_TYPE "PORTABLE");
W_LCD(0x80,0);
Out_LCD(ROM_TYPE "BP METER");
Delay_sec(2);
W_LCD(0b00000001,0);
}
// Display user's bp measurement
void disp_val()
{
while(1)
{
W_LCD(0x82,0);
Out_LCD(ROM_TYPE "SYS");
W_LCD(0xC0,0);
Out_LCD(ROM_TYPE "mmHg");
Delay_sec(4);
W_LCD(0b00000001,0);
W_LCD(0x82,0);
Out_LCD(ROM_TYPE "DIAS");
W_LCD(0xC0,0);
Out_LCD(ROM_TYPE "mmHg");
Delay_sec(4);
W_LCD(0b00000001,0);
W_LCD(0x81,0);
Out_LCD(ROM_TYPE "PULSE");
W_LCD(0xC0,0);
Out_LCD(ROM_TYPE "bpm");
Delay_sec(4);
W_LCD(0b00000001,0);
}
}
// Delay multiple number of msec
void Delay_msec(unsigned int delayInMSEC)
{
while (delayInMSEC--)
Delay1KTCYx(DELAY1MS);
}
// Delay multiple number of sec
void Delay_sec(unsigned int delayInSEC)
{
while (delayInSEC--)
{
Delay10KTCYx(DELAY1S);
Delay10KTCYx(DELAY1S);
Delay10KTCYx(DELAY1S);
Delay10KTCYx(DELAY1S);
}
}Last edited by big_k105; Jul 22nd, 2008 at 9:25 PM. Reason: added code tags |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Nov 2007
Location: Ireland
Posts: 18
Rep Power: 0
![]() |
Re: Lcd
Most of your define statements aren't necessary which cause your code to be confusing and you should work on your indentation.
It's recommended to use LATB for outputs instead of PORTB. It isn't necessary to send 0x03 to the LCD on start up. You can just delay for 200mS while it starts up and begin with the Function Set (datasheet). The LCD is enabled by a high-to-low transition on E. LCD_E = 1; LCD_E = 0; A slight delay of a 1uS or two between those might be necessary if your using a fast clock. The LCD needs to be enabled like that after every instruction or data you put on its pins. You need to create a re-usable program which simply displays any string that you pass to a function. Forget numerical data until you've done that. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jun 2008
Posts: 11
Rep Power: 0
![]() |
Re: Lcd
My lcd is able to work already. Thx for any help(:
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Remotely changing baud rates. | hoffmandirt | C# | 9 | Nov 19th, 2007 8:47 PM |
| Serial Port Communication | hoffmandirt | C# | 3 | Sep 19th, 2007 3:38 PM |