Mostrando postagens com marcador Programa Módulo de LCD via Porta Paralela. Mostrar todas as postagens
Mostrando postagens com marcador Programa Módulo de LCD via Porta Paralela. Mostrar todas as postagens

Programando Módulo de LCD via Porta Paralela

Fonte: ElectroSofts

#include "dos.h"
#include "string.h"
#include "conio.h"
#include "time.h"


#define PORTADDRESS 0x378 /* Enter Your Port Address Here */

#define DATA PORTADDRESS+0
#define STATUS PORTADDRESS+1
#define CONTROL PORTADDRESS+2

void lcd_init(void);
void lcd_write(char char2write);
void lcd_putch(char char2write);
void lcd_puts(char * str2write);
void lcd_goto(int row, int column);
void lcd_clear(void);
void lcd_home(void);
void lcd_cursor(int cursor);
void lcd_entry_mode(int mode);


void main(void)
{

lcd_init();
lcd_goto(1,1);
lcd_puts("Welcome To");
lcd_goto(1,0);
lcd_puts("electroSofts.com");

while(!kbhit() ) //wait until a key is pressed...
{}

}

void lcd_init()
{

outportb(CONTROL, inportb(CONTROL) & 0xDF);
//config data pins as output

outportb(CONTROL, inportb(CONTROL) 0x08);
//RS is made high: control (register select)

lcd_write(0x0f);
delay(20);
lcd_write( 0x01);
delay(20);
lcd_write( 0x38);
delay(20);

}

void lcd_write(char char2write)
{

outportb(DATA, char2write);
outportb(CONTROL,inportb(CONTROL) 0x01); /* Set Strobe */
delay(2);
outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe */
delay(2);

}

void lcd_putch(char char2write)
{

outportb(CONTROL, inportb(CONTROL) & 0xF7);
//RS=low: data
lcd_write(char2write);

}

void lcd_puts(char *str2write)
{

outportb(CONTROL, inportb(CONTROL) & 0xF7);
//RS=low: data
while(*str2write)
lcd_write(*(str2write++));

}

void lcd_goto(int row, int column)
{

outportb(CONTROL, inportb(CONTROL) 0x08);
if(row==2) column+=0x40;
/* Add these if you are using LCD module with 4 columns
if(row==2) column+=0x14;
if(row==3) column+=0x54;
*/

lcd_write(0x80 column);

}

void lcd_clear()
{

outportb(CONTROL, inportb(CONTROL) 0x08);
lcd_write(0x01);

}

void lcd_home()
{

outportb(CONTROL, inportb(CONTROL) 0x08);
lcd_write(0x02);

}

void lcd_entry_mode(int mode)
{

/*
if you dont call this function, entry mode sets to 2 by default.
mode: 0 - cursor left shift, no text shift
1 - no cursor shift, text right shift
2 - cursor right shift, no text shift
3 - no cursor shift, text left shift
*/

outportb(CONTROL, inportb(CONTROL) 0x08);
lcd_write(0x04 + (mode%4));

}

void lcd_cursor(int cursor)
{

/*
set cursor: 0 - no cursor, no blink
1 - only blink, no cursor
2 - only cursor, no blink
3 - both cursor and blink
*/


outportb( CONTROL, inportb(CONTROL) 0x08 );
lcd_write( 0x0c + (cursor%4));

}

Exemplo de Programa para Escrever no Módulo LCD

void main(void)
{

struct time t;
struct date d;
char strtime[17];

textbackground(0);
clrscr();
textcolor(0);
textbackground(10);
gotoxy(8,5);
cputs(" ");
gotoxy(8,4);
cputs(" ");

lcd_init();
lcd_cursor(0);

while(!kbhit())
{

gettime(&t);
getdate(&d);
lcd_goto(0,4);
sprintf(strtime,"%02d:%02d:%02d", t.ti_hour%12, t.ti_min, t.ti_sec);
lcd_puts(strtime);
gotoxy(12,4);
cputs(strtime);

lcd_goto(1,3);
sprintf(strtime,"%02d:%02d:%4d", d.da_day, d.da_mon, d.da_year);
lcd_puts(strtime);
gotoxy(11,5);
cputs(strtime);
delay(200);

}
textbackground(0);
textcolor(7);

}