We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi Im new with this and my language is bad. I have 4X20 LCD and LPC936 and i dont know hov to write a program. I try something and nothing heppens. Please can you see my work and tell me whats wrong and how to fix this problem. My code:
Main.c
/********************************************************************************/ /* Module: LCD driver */ /* Author: Ales Moskon */ /* Compiler: Keil C */ /* Version: 1.00.00 maj-2007 */ /* Notes: "LCD" driver */ /********************************************************************************/
#include <reg936.h> #include <stdio.h>
typedef unsigned char uchar;
void delay_ms (unsigned int count_ms); void LCD_cls(void); void LCD_cursor_blink(uchar mode); void LCD_dcode ( uchar b); void LCD_gotoxy(uchar x,y); //bit LCD_busy(void); void LCD_home(void); void LCD_init(void); void LCD_on(uchar mode); void LCD_print(void); void LCD_putchar ( uchar b); void LCD_puts ( uchar b[]); void LCD_send4(uchar ch); void v_PortConfig(void);
void main() { LCD_init(); LCD_cls(); LCD_gotoxy(1,1); LCD_print();
return; }
Lcd.c
#include <REG936.H> #include <stdio.h>
typedef unsigned char uchar; typedef unsigned int ttimedate;
sbit LCD_AD4 = P2^3; sbit LCD_AD5 = P2^4; sbit LCD_AD6 = P2^5; sbit LCD_AD7 = P2^6; sbit LCD_RS = P2^2; sbit LCD_EN = P2^0; sbit LCD_RW = P2^1;
void LCD_cls(void); void LCD_home(void); void LCD_on(uchar mode); void LCD_cursor_blink(uchar mode); void LCD_gotoxy(uchar x,y); //bit LCD_busy(void); void LCD_init(void); void LCD_send4(uchar ch); void delay_ms (unsigned int count_ms); void LCD_putchar(uchar ch); void LCD_puts(char s[]);
void LCD_dcode(uchar b);
void LCD_print_temp(int temp); void LCD_print_timedate(ttimedate ctime);
static blinkstate = 0;
/*--------------------------------------------------------------------------------------*/
void delay_ms (unsigned int count_ms) { unsigned int i,j; for (j=0; j<count_ms*2; j++) for (i=0; i<123; i++); }
void LCD_send4(uchar ch) { /*while(LCD_busy()); */ LCD_RW = 0; LCD_EN=1; LCD_AD7=ch&128; LCD_AD6=ch&64; LCD_AD5=ch&32; LCD_AD4=ch&16; LCD_EN=0;
delay_ms (10);
LCD_EN=1; LCD_AD7=ch&8; LCD_AD6=ch&4; LCD_AD5=ch&2; LCD_AD4=ch&1;
LCD_EN=0; }
void LCD_init(void) { LCD_RW = 0; LCD_EN=0; delay_ms (15); LCD_RS=0; LCD_EN=1; LCD_AD7=0;LCD_AD6=0;LCD_AD5=1;LCD_AD4=1; LCD_EN=0; delay_ms (5); LCD_RS=0; LCD_EN=1; LCD_AD7=0;LCD_AD6=0;LCD_AD5=1;LCD_AD4=1; LCD_EN=0;
delay_ms (1); LCD_RS=0; LCD_EN=1; LCD_AD7=0;LCD_AD6=0;LCD_AD5=1;LCD_AD4=1; LCD_EN=0; delay_ms (1); LCD_RS=0; LCD_EN=1; LCD_AD7=0;LCD_AD6=0;LCD_AD5=1;LCD_AD4=0; LCD_EN=0;
LCD_dcode (0x28); LCD_dcode (0x08); LCD_dcode (0x09); LCD_dcode (0x06); LCD_on(1); LCD_cls(); LCD_home();
LCD_cursor_blink(1); }
void LCD_dcode ( uchar b) { delay_ms (10);
LCD_RS=0; LCD_send4(b); }
/*--------------------------------------------------------------------------*/
void LCD_puts ( uchar b[]) { char i; for (i=0;((b[i]!='\0'));i++) { LCD_putchar(b[i]);
} }
void LCD_putchar ( uchar b) { delay_ms (1); LCD_RS=1; LCD_send4(b); }
void LCD_home(void) { LCD_dcode (0x80); }
void LCD_cursor_blink(uchar mode) {
#define _disp_off 0x08 #define _ncrsr_blnk 0x0D #define _ncrsr_nblnk 0x0C #define _crsr_blnk 0x0F #define _crsr_nblnk 0x0E
switch (mode) { case 0 : LCD_dcode(_disp_off); break; case 1 : LCD_dcode(_ncrsr_nblnk); break; case 2 : LCD_dcode(_ncrsr_blnk); break; case 3 : LCD_dcode(_crsr_nblnk); break; case 4 : LCD_dcode(_crsr_blnk); break; } if (mode>0) blinkstate=mode; }
void LCD_cls(void) {
LCD_dcode(1); }
void LCD_on(uchar mode) { if (mode==0) LCD_cursor_blink(0); else LCD_cursor_blink(blinkstate); }
/*bit LCD_busy(void) { bit tmp; LCD_RW=1; LCD_EN = 1; tmp = LCD_AD7; LCD_EN = 0; LCD_RW=0; return tmp; } */ /*--------------------------------------------------------------------------------------*/
void LCD_gotoxy(uchar x,y) { LCD_dcode(0x80+0x40*(y-1)+(x-1)); delay_ms (10); }
void LCD_print(void) { uchar LCD_buf[16]; printf ( "Zdravo " ); LCD_puts(LCD_buf); }
Can you explain this sentence: There is probably a thread/weak about the use of displays.
Im sorry im bad in other language.
Ales
"There is probably a thread/weak (sic) about the use of displays."
I think he means, "There is probably a thread per week about the use of displays."
In other words, it's already been thoroughly discussed and you just need to do a little 'Search' to find what you're looking for...
Did the Application Note suggested earlier not help you?
Yes, I was thinking about something else when writing the text.
I definitely meant a thread per week.
Sorry for the confusion!
www.8052.com/.../read.phtml
While you're there, look at the 'Tutorials' section...
Please can you check my program. I try everything and nothing happen.
Please Ales
Probably this is importaint: I have LPC936 and CM2040 (4x20 LCD). I connect RS---P2.2 EN---P2.1 RW---P2.0
LP Ales
I have LPC936 and CM2040 (4x20 LCD). Insert a 5V powered HCT between the 3V3 LPC and the 5V LCD. The slow risetimes from the 'wonderful' 5V compatible pins can 'kill' the LCD.
Erik
Maybe the loops in delay_ms() are optimised out?
Can you write me witch number is this HCT please, and how to connect. LCD is 5V and also working with 3V.
LP Aleš
There are many HCT chips that may be used. Hence, many ways to connect them too.
I've got a big problem with the LCD showing fixed text that never changes.
I've tried changing the program but it doesn't help.
Where can I send the code?