


Moderators: pedja089, stojke369, [eDo], trax
Code: Select all
//// \f Clear display
//// \n Go to start of second line
//// \b Move back one position
//// lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1)
#ifndef LCDCLK
#define LCDCLK PIN_B2
#endif
#ifndef LCDDAT
#define LCDDAT PIN_B1
#endif
#define DATA1 output_high(LCDDAT)
#define DATA0 output_low(LCDDAT)
void lcd_Es() {
output_high(LCDDAT);
// delay_us(200); //only in high mhz
output_low(LCDDAT);
}
void lcd_Clk() {
output_high(LCDCLK);
output_low(LCDCLK);
}
void lcd_Send_Nibble( char nibble, int1 rs) {
int8 i;
DATA0; // clear output
for (i=0; i<6; i++) lcd_Clk();
DATA1; // Output the "AND" Value
lcd_Clk();
IF (rs==1) {
DATA1; // Output the RS Bit Value
} ELSE {
DATA0;
}
lcd_Clk();
for (i = 0; i<4; i++) { // Output the Nybble
if (nibble & 0x08) {
DATA1; // Output the High Order Bit
}
else {
DATA0;
}
lcd_Clk(); // Strobe the Clock
nibble<<=1; // Shift up Nybble for Next Byte
}
lcd_Es(); // Toggle the "E" Clock Bit
}
void lcd_send_byte( int n , int1 rs) {
lcd_send_nibble(n >> 4 , rs);
lcd_send_nibble(n & 0xf, rs);
}
void lcd_init( void) {
lcd_send_nibble(0x03,0);
delay_ms(5);
lcd_es();
delay_us(160);
lcd_es();
delay_us(160);
lcd_send_nibble(0x02,0);
delay_us(160);
lcd_send_byte(0x28,0);
lcd_send_byte(0x08,0);
lcd_send_byte(0x01,0);
delay_ms(5);
lcd_send_byte(0x06,0);
lcd_send_byte(0x0C,0);
}
void lcd_gotoxy( int x, int y) {
BYTE address;
if (y!=1) {
address=0x40;
} else {
address=0;
}
address+=x-1;
lcd_send_byte(0x80|address,0);
}
void lcd_putc( char c) {
switch (c) {
case '\f' : lcd_send_byte(1,0); delay_ms(5); break; //clear display
case '\n' : lcd_gotoxy(1,2); break; //
case '\b' : lcd_send_byte(0x10,0); break;
default : lcd_send_byte(c,1); break;
}
}
Code: Select all
void Write_LCD_Nibble(unsigned short N){
Enable_Pin = 0;
// ****** Write RS *********
Clk_Pin = 0;
Data_Pin = RS;
Clk_Pin = 1;
Clk_Pin = 0;
// ****** End RS Write
// Shift in 4 bits
Mask = 8;
for (t=0; t<4; t++){
Flag = N & Mask;
if(Flag==0) Data_Pin = 0;
else Data_Pin = 1;
Clk_Pin = 1;
Clk_Pin = 0;
Mask = Mask >> 1;
}
// One more clock because SC and ST clks are tied
Clk_Pin = 1;
Clk_Pin = 0;
Data_Pin = 0;
Enable_Pin = 1;
Enable_Pin = 0;
}
Code: Select all
void lcd_Send_Nibble( char nibble, int1 rs) {
int8 i;
DATA0; // clear output
for (i=0; i<6; i++) lcd_Clk();
DATA1; // Output the "AND" Value
lcd_Clk();
IF (rs==1) {
DATA1; // Output the RS Bit Value
} ELSE {
DATA0;
}
lcd_Clk();
for (i = 0; i<4; i++) { // Output the Nybble
if (nibble & 0x08) {
DATA1; // Output the High Order Bit
}
else {
DATA0;
}
lcd_Clk(); // Strobe the Clock
nibble<<=1; // Shift up Nybble for Next Byte
}
lcd_Es(); // Toggle the "E" Clock Bit
}