English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

#include
#include
#include "ascii5x7.h"

#define LCD_RW P2_3 // 40-DIP pin 24
#define LCD_CS2 P2_4 // 40-DIP pin 25
#define LCD_CS1 P2_5 // 40-DIP pin 26
#define LCD_DI P2_6 // 40-DIP pin 27
#define LCD_EN P2_7 // 40-DIP pin 28
#define LCD_D07 P0 // 40-DIP pins 39 down to 32

void LCD_delay (void) _naked
{
_asm
nop
nop
ret
_endasm;
}

// Sends a command to the display.
void LCD_Command (bit lr, unsigned char val)
{
if(lr) LCD_CS1=1; // Left half
else LCD_CS2=1; // Right half

LCD_DI=0; //Command
LCD_D07=val;
LCD_EN=1;
LCD_delay();
LCD_EN=0; //Strobe command in
LCD_CS1=0;
LCD_CS2=0;
}

// Sends a byte of data to the display.
void LCD_Write (unsigned char x, unsigned char y, unsigned char val)
{
bit lr;
lr=(x<64)?1:0;

//Set the x position
LCD_Command(lr, (x&0x3f)|0x40);

//Set the y position (page address)
LCD_Command(lr, (y&0x7)|0xb8);

if(lr) LCD_CS1=1; // Left half
else LCD_CS2=1;

2007-03-23 17:24:05 · 2 answers · asked by Anonymous in Computers & Internet Programming & Design

2 answers

pretty much what the other person said, but there are 2 LCD displays. it looks like they are 2x32 displays (2 lines with 32 characters per line).

the LCD_Write function is called, and the parameters for the character position in the display, line of the display, and character to write out are given. it seems like something is missing in this routine. they write out the command for the line and character position, but not the actual character. i think you need to add a line after "LCD_Command(lr, (y&0x7|0xb8);" which should be "LCD_Command(lr, val);"

the LCD_Command function uses the lr bit to determine what display you are writing to and enables it by setting the LCD_CS1 or LCD_CS2 bit. then it writes out the val to the LCD.

the delay routine is just adding some delay because the displays need the EN line to remain high for a specified period of time. this routine was done in assembly.

2007-03-24 02:32:31 · answer #1 · answered by justme 7 · 0 0

Well for a start, it's driving a Liquid Crystal Display (LCD).
These can take time to respond to commands, so the first section is a little "delay" that the program occasionally calls, giving the LCSD time to catch up.

The next function sends a command to the left (or right) half of the LCD, depending on bit (lr). Disable Interrupts (DI), write the data to DO7, and Enable (EN). Wait a bit to be sure the LCD got it, remove Enable(EN), deselect (CS =0)

Finally, a byte of data (val) is sent to the LCD. The actual location on the LCD is determined by some funky workings on 2 values x and y.

2007-03-23 17:44:08 · answer #2 · answered by Alan 6 · 0 0

fedest.com, questions and answers