Le Jeudi 27 Novembre 2003 17:06, PierreDu a écrit :
> Le seul but est de programmer sur le port parallèle, rien d'autre...
> D'ailleurs, avez-vous une doc sur ça ?
Voila un peu de code que j'avais fait pour piloter un écran LCD connecté au
port //, si ça peut etre utile à qqn... (il y a le fichier .c et .h dans la
suite de ce mail.
---------------------------------------------------
/***************************************************************************
lcdg.c - description
-------------------
begin : Mon Mar 11 2002
copyright : (C) 2002 by
email :
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <string.h> // pour avoir strlen
#include <sys/io.h> // pour avoir outb
#include <stdio.h>
#include "lcdg.h"
int t,i;
void IO_init()
{
/* demande d'accès au port */
if (ioperm(Data,3,1))
{
printf("Accès au port refusé, désolé");
exit(1);
}
}
void checkbusy()
{
unsigned char flag;
outb(0,Data);
do
{
outb(ERWRS,Control);
usleep(1);
outb(RWRS,Control);
usleep(1);
flag=(inb(Data)&128);
fprintf(stderr,"Busy = %d\n",flag);
}
while(flag==128);
outb(ZERO,Control);
}
void LCDg_init(char mde)
{
if (mde==0) { LCD_MODE=0;
fprintf(stderr,"Mode texte\n");
LCDg_init_text(); }
else { LCD_MODE=1;
fprintf(stderr,"Mode graphique\n");
LCDg_init_graph(); }
}
void LCDg_init_text()
{
LCDg_setreg(ctrl);
LCDg_out(32+16+8+4); //disp on,master mode,blink on,cursor on,text
mode,internal CG
LCDg_setreg(cpitch);
// LCDg_out(128+32+4); // font 5*11
LCDg_out(128+4); // font 5*9
LCDg_setreg(nbrcar);
LCDg_out(41);
LCDg_setreg(nbrtdiv);
LCDg_out(64); //valeur au pif mais qui va bien....
LCDg_setreg(curpos);
LCDg_out(7);
LCDg_setreg(dsLOa);
LCDg_out(0);
LCDg_setreg(dsHOa);
LCDg_out(0);
LCDg_setreg(scLOa);
LCDg_out(0x00);
LCDg_setreg(scHOa);
LCDg_out(0x00);
LCDg_setreg(scLOa);
LCDg_out(0x0);
LCDg_setreg(scHOa);
LCDg_out(0x0);
LCDg_setreg(wddata);
}
void LCDg_init_graph()
{
// writereg (0x00 , 0x3e );
LCDg_setreg(ctrl);
LCDg_out(32+16+2);//mode graphique
LCDg_setreg(cpitch);
LCDg_out(7);//on affiche 8 bits/8
LCDg_setreg(nbrcar);
LCDg_out(31);
LCDg_setreg(nbrtdiv);
LCDg_out(64);
LCDg_setreg(curpos);
LCDg_out(50);
LCDg_setreg(dsLOa);
LCDg_out(0);
LCDg_setreg(dsHOa);
LCDg_out(0);
LCDg_setreg(scLOa);
LCDg_out(0);
LCDg_setreg(scHOa);
LCDg_out(0);
LCDg_setreg(wddata);
}
void LCDg_out(unsigned char data)
{
outb(ZERO,Control);
outb(data,Data);
// usleep(1);
outb(E,Control);
//pause(1000);
// usleep(1);// Pour être sûr que l'impulsion E est suffisemment longue (au
moins 450ns)
outb(ZERO,Control);
// usleep(1);
//usleep(TEMPO);
// checkbusy();
}
void LCDg_setreg(unsigned char reg)
{
outb(RS,Control);
outb(reg,Data);
// usleep(1);
outb(ERS,Control);
// usleep(1);// Pour être sûr que l'impulsion E est suffisemment longue
(au moins 450ns)
outb(RS,Control);
// usleep(1);
//checkbusy();
// usleep(1);
}
void LCDg_puts(char *str)
{
char i;
for (i=0;i<strlen(str);i++)
{
LCDg_out(str[i]);
}
}
void pause(int t)
{
int i,j;
for (i=0;i<(t);i++)
for (j=0;j<t/2;j++);
}
void LCDg_cls()
{
if (LCD_MODE) { LCDg_setreg(scLOa);
LCDg_out(0);
LCDg_setreg(scHOa);
LCDg_out(0);
LCDg_setreg(wddata);
for
(i=0;i<2048;i++) LCDg_out(0);
LCDg_setreg(scLOa);
LCDg_out(0);
LCDg_setreg(scHOa);
LCDg_out(0);
LCDg_setreg(wddata); }
else { LCDg_setreg(scLOa);
LCDg_out(0);
LCDg_setreg(scHOa);
LCDg_out(0);
LCDg_setreg(wddata);
for (i=0;i<340;i++) LCDg_out(' ');
LCDg_setreg(scLOa);
LCDg_out(0);
LCDg_setreg(scHOa);
LCDg_out(0);
LCDg_setreg(wddata); }
}
void locate(unsigned char x, unsigned char y)
{
unsigned int pos=0;
unsigned char scloa, schoa;
if ((x>40)||(y>7)) return;
for (i=0;i<y;i++) pos+=42;
fprintf(stderr,"pos=%d\n",pos);
pos = (pos+x);
scloa=(pos & 255); //récupération bits de pds fbl
schoa=((pos & 65280) >> 8); //récupération bits de pds fort et décalage
vers
pds fbl
fprintf(stderr,"locate: x=%d, y=%d, pos=%d, lo=%d,
ho=%d\n",x,y,pos,scloa,schoa);
LCDg_setreg(scLOa);
LCDg_out(scloa);
LCDg_setreg(scHOa);
LCDg_out(schoa);
LCDg_setreg(wddata);
}
void plot(unsigned int x,unsigned int y)
{
int i,j;
unsigned int add=0;
unsigned char scloa, schoa, bit;
fprintf(stderr,"Dans plot, x=%d, y=%d\n",x,y);
if ((x>255)||(y>63)) return;
for (i=0;i<y;i++) add+=32;
for (i=0;i<(x/8);i++) add++;
fprintf(stderr,"add=%d\n",add);
scloa=(add & 255); //récupération bits de pds fbl
schoa=((add & 65280) >> 8); //récupération bits de pds fort et décalage
vers
pds fbl
fprintf(stderr,"scloa=%d, schoa=%d\n",scloa,schoa);
LCDg_setreg(scLOa);
LCDg_out(scloa);
LCDg_setreg(scHOa);
LCDg_out(schoa);
bit=(x%8);
LCDg_setreg(setbit);
LCDg_out(bit);
//LCDg_setreg(wddata);
}
void unplot(unsigned int x,unsigned int y)
{
int i,j;
unsigned int add=0;
unsigned char scloa, schoa, bit;
fprintf(stderr,"Dans unplot, x=%d, y=%d\n",x,y);
if ((x>255)||(y>63)) return;
for (i=0;i<y;i++) add+=32;
for (i=0;i<(x/8);i++) add++;
fprintf(stderr,"add=%d\n",add);
scloa=(add & 255); //récupération bits de pds fbl
schoa=((add & 65280) >> 8); //récupération bits de pds fort et décalage
vers
pds fbl
fprintf(stderr,"scloa=%d, schoa=%d\n",scloa,schoa);
LCDg_setreg(scLOa);
LCDg_out(scloa);
LCDg_setreg(scHOa);
LCDg_out(schoa);
bit=(x%8);
LCDg_setreg(clrbit);
LCDg_out(bit);
// LCDg_setreg(wddata);
}
void bigplot(unsigned int x,unsigned int y,char taille)
{
if ((x>255)||(y>63)) return;
plot(x,y);
}
--------------------------
/***************************************************************************
lcdg.h - description
-------------------
begin : Mon Mar 11 2002
copyright : (C) 2002 by
email :
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef LCD
#define LCD
#define Data 0x378
#define Status 0x379
#define Control 0x37A
//#define PULSE ???
#define TEMPO 200000
//signaux de controle
#define ZERO 10
#define E 8
#define ERW 12
#define ERS 0
#define ERWRS 4
#define RS 2
#define RWRS 6
#define RW 14
//registres
#define ctrl 0
#define cpitch 1
#define nbrcar 2
#define nbrtdiv 3
#define curpos 4
#define dsLOa 8
#define dsHOa 9
#define scLOa 10
#define scHOa 11
#define wddata 12
#define rddata 13
#define clrbit 14
#define setbit 15
char LCD_MODE;
void pause(int t);
//fonctions de gestion
void IO_init();
void LCDg_init(char mde);
void LCDg_init_text();
void LCDg_init_graph();
void checkbusy();
void LCDg_setreg(unsigned char reg);
void LCDg_out(unsigned char data);
void LCDg_puts(char *str);
void locate(unsigned char x, unsigned char y);
void plot(unsigned int x,unsigned int y);
void unplot(unsigned int x,unsigned int y);
void bigplot(unsigned int x,unsigned int y,char taille);
#endif //LCD
Vous souhaitez acquerir votre Pack ou des Services MandrakeSoft?
Rendez-vous sur "http://www.mandrakestore.com"
|