Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2610 connectés 

 


 Mot :   Pseudo :  
 
 Page :   1  2  3  4  5  6  7  8
Auteur Sujet :

[ Divers / C ] Ecrire pour un afficheur LCD

n°2110125
gilou
Modérateur
Modosaurus Rex
Posté le 07-11-2011 à 12:00:42  profilanswer
 

Reprise du message précédent :
Je suis justement en train d'écrire d'abord la fonction pour lire la position courante.
 
A+,


---------------
There's more than what can be linked! --  Le capitaine qui ne veut pas obéir à la carte finira par obéir aux récifs. -- Il ne faut plus dire Sarkozy, mais Sarkozon -- (╯°□°)╯︵ ┻━┻
mood
Publicité
Posté le 07-11-2011 à 12:00:42  profilanswer
 

n°2110128
Profil sup​primé
Posté le 07-11-2011 à 12:19:03  answer
 

Ok, je l'ai écrite.
 
Pour le moment, j'ai fait un import depuis Ada pour exploité ce que j'avais fait.
 
J'affiche du texte défilant de droite à gauche sur la première et seconde ligne, puis je fait clignoté le texte.
A la première itération, ça bouge mais rien ne s'affiche.
les itération suivantes, le texte défilant s'affiche mais pas le texte clignotant.
 

Code :
  1. with Interfaces.C;
  2. use Interfaces;
  3. procedure Lcd_Hello is
  4.  
  5.   procedure Open_Port;
  6.   pragma Import (C, Open_Port, "open_port" );
  7.   procedure Close_Port;
  8.   pragma Import (C, Close_Port, "close_port" );
  9.   procedure LCD_Init;
  10.   pragma Import(C, LCD_Init, "LCD_Init" );
  11.   procedure LCD_ClearDisplay;
  12.   pragma Import(C, LCD_ClearDisplay, "LCD_ClearDisplay" );
  13.   procedure LCD_WriteChar(Text : in C.Char);
  14.   pragma Import (C, LCD_WriteChar, "LCD_WriteChar" );
  15.   procedure LCD_WriteString(Text : in C.Char_Array);
  16.   pragma Import (C, LCD_WriteString, "LCD_WriteString" );
  17.   procedure LCD_Position(Pos : in C.Int);
  18.   pragma Import(C, LCD_Position, "LCD_Position" );
  19.   procedure Port_Clear;
  20.   pragma Import (C, Port_Clear, "port_clear" );
  21.  
  22.   Text1    : String(1..9)  := "Bonjour !";
  23.   Text2    : String(1..11) := "Hardware.fr";
  24.   Size    : C.Int := 1;
  25.   Line    : C.Int := 1;
  26.   Bigfont : C.Int := 0;
  27.   On      : C.Int := 1;
  28.   Cursor  : C.Int := 1;
  29.   Blink   : C.Int := 1;
  30.  
  31.   use Interfaces.C;
  32.   Position1_Right : Int := 18;
  33.   Position2_Right : Int := 82;
  34.   Position1_left : Int := 10;
  35.   Position2_left : Int := 72;
  36.  
  37. begin
  38.   Open_Port;
  39.   LCD_Init;
  40.   delay 0.2;
  41.   LCD_ClearDisplay;
  42.   delay 0.2;
  43.   LCD_Position(Position1_right);
  44.   loop
  45.      for I in 1..9 loop
  46.         LCD_WriteString(To_C(Text1(1..I)));
  47.         delay 0.025;
  48.         Position1_right := Position1_right - 1;
  49.         LCD_Position(Position1_right);
  50.         delay 0.01;
  51.  
  52.      end loop;
  53.      LCD_Position(Position2_right);
  54.      delay 1.0;
  55.      for I in 1..11 loop
  56.         LCD_WriteString(To_C(Text2(1..I)));
  57.         delay 0.025;
  58.         Position2_right := Position2_right - 1;
  59.         LCD_Position(Position2_right);
  60.         delay 0.01;
  61.      end loop;
  62.      delay 1.0;
  63.      for I in 1..5 loop
  64.         delay 0.025;
  65.         LCD_ClearDisplay;
  66.         delay 0.025;
  67.         LCD_Position(Position1_left);
  68.         delay 0.025;
  69.         LCD_WriteString(To_C(Text1(1..9)));
  70.         delay 0.2;
  71.         LCD_Position(Position2_left);
  72.         delay 0.025;
  73.         LCD_WriteString(To_C(Text2(1..11)));
  74.         delay 1.0;
  75.      end loop;
  76.      LCD_Init; -- après cet init le texte défilant s'affiche.
  77.      delay 0.2;
  78.      LCD_ClearDisplay;
  79.      delay 0.1;
  80.      Position1_right := 18;
  81.      LCD_Position(Position1_right);
  82.      Position2_right := 82;
  83.   end loop;
  84.   Close_Port;
  85. end Lcd_Hello;


Si j'enlève LCD_Init à la fin plus plus rien ne s'affiche.

n°2110130
gilou
Modérateur
Modosaurus Rex
Posté le 07-11-2011 à 12:35:28  profilanswer
 

Code :
  1. unsigned char  get_rawposition() {
  2.     unsigned char control = GetControl();
  3.     unsigned char data;
  4.     Clear_RS(control);
  5.     Set_RW(control);
  6.     usleep(1); 
  7.     SetData(0xFF);         // Set All Pins to FF before read
  8.     DataIn(control); 
  9.     Set_E(control);        // Strobe command to LCD
  10.     usleep(1);
  11.     data = GetData();      // Read Position
  12.     data &= 0x7F;          // Get high bit
  13.     DataOut(control);
  14.     Clear_E(control);
  15.     usleep(1);
  16.     Clear_RW(control);      // Avoid Bus conflict
  17.     usleep(1);
  18.     return data;
  19. }
  20. int GetLine_LCD() {
  21.     int linepos = 0;
  22.     unsigned char rawposition = get_rawposition();
  23.     wait_LCD();
  24.     if (rawposition >= 0) {
  25. if (rawposition <= 19) {
  26.     linepos = 1;
  27. }
  28. else if (rawposition <= 39) {
  29.     linepos = 3;
  30. }
  31. else if (rawposition >= 64) {
  32.     if (rawposition <= 83) {
  33.  linepos = 2;
  34.     }
  35.     else if (rawposition <= 103) {
  36.  linepos = 4;
  37.     }
  38. }
  39.     }
  40.     if (linepos < 1 || linepos > 4) {
  41. printf("Incorrect raw position value: %X\n", rawposition);
  42.     }
  43.     return linepos;
  44. }
  45. int GetLinePos_LCD(int linepos) {
  46.     int charpos = 0;
  47.     unsigned char rawposition = get_rawposition();
  48.     wait_LCD();
  49.     switch (linepos) {
  50.     case 1:
  51. charpos = rawposition +1;
  52. break;
  53.     case 2:
  54. charpos = (rawposition +1) - 64;
  55. break;
  56.     case 3:
  57. charpos = (rawposition +1) - 20;
  58. break;
  59.     case 4:
  60. charpos = (rawposition +1) - 84;
  61. break;
  62.     default:
  63. break;
  64.     }
  65.     if (charpos < 1 || charpos > 20) {
  66. printf("Line %d Incorrect raw position value: %X\n", linepos, rawposition);
  67. charpos = 0;
  68.     }
  69.     return charpos;
  70. }


 
Et après avoir écrit hello, tu peux tester en faisant:
int linepos, charpos;  (déclaré comme variables de main)
 
linepos = GetLine_LCD();
charpos = GetLinePos_LCD(linepos);
printf("Position: caractère %d de la ligne %d\n", charpos, linepos);
 
A+,

Message cité 1 fois
Message édité par gilou le 07-11-2011 à 12:36:52

---------------
There's more than what can be linked! --  Le capitaine qui ne veut pas obéir à la carte finira par obéir aux récifs. -- Il ne faut plus dire Sarkozy, mais Sarkozon -- (╯°□°)╯︵ ┻━┻
n°2110131
Profil sup​primé
Posté le 07-11-2011 à 12:40:10  answer
 

gilou a écrit :

Code :
  1. unsigned char  get_rawposition() {
  2.     unsigned char control = GetControl();
  3.     unsigned char data;
  4.     Clear_RS(control);
  5.     Set_RW(control);
  6.     usleep(1); 
  7.     SetData(0xFF);         // Set All Pins to FF before read
  8.     DataIn(control); 
  9.     Set_E(control);        // Strobe command to LCD
  10.     usleep(1);
  11.     data = GetData();      // Read Position
  12.     data &= 0x7F;          // Get high bit
  13.     DataOut(control);
  14.     Clear_E(control);
  15.     usleep(1);
  16.     Clear_RW(control);      // Avoid Bus conflict
  17.     usleep(1);
  18.     return data;
  19. }
  20. int GetLine_LCD() {
  21.     int linepos = 0;
  22.     unsigned char rawposition = get_rawposition();
  23.     wait_LCD();
  24.     if (rawposition >= 0) {
  25. if (rawposition <= 19) {
  26.     linepos = 1;
  27. }
  28. else if (rawposition <= 39) {
  29.     linepos = 3;
  30. }
  31. else if (rawposition >= 64) {
  32.     if (rawposition <= 83) {
  33.  linepos = 2;
  34.     }
  35.     else if (rawposition <= 103) {
  36.  linepos = 4;
  37.     }
  38. }
  39.     }
  40.     if (linepos < 1 || linepos > 4) {
  41. printf("Incorrect raw position value: %X\n", rawposition);
  42.     }
  43.     return linepos;
  44. }
  45. int GetLinePos_LCD(int linepos) {
  46.     int charpos = 0;
  47.     unsigned char rawposition = get_rawposition();
  48.     wait_LCD();
  49.     switch (linepos) {
  50.     case 1:
  51. charpos = rawposition +1;
  52. break;
  53.     case 2:
  54. charpos = (rawposition +1) - 64;
  55. break;
  56.     case 3:
  57. charpos = (rawposition +1) - 20;
  58. break;
  59.     case 4:
  60. charpos = (rawposition +1) - 84;
  61. break;
  62.     default:
  63. break;
  64.     }
  65.     if (charpos < 1 || charpos > 20) {
  66. printf("Line %d Incorrect raw position value: %X\n", linepos, rawposition);
  67. charpos = 0;
  68.     }
  69.     return charpos;
  70. }


 
Et après avoir écrit hello, tu peux tester en faisant:
int linepos, charpos;  (déclaré comme variables de main)
 
linepos = GetLine_LCD();
charpos = GetLinePos_LCD(linepos);
printf("Position: caractère %d de la ligne %d\n", charpos, linepos);
 
A+,


 
Je teste ça, je reviens.
 
J'ai fais ça en C, ça marche impecable.
 

Code :
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. #include "./libparalcd.h"
  6.  
  7. int main (void)
  8. {
  9.  if (ioperm(BASEPORT, 3, 1)) {
  10.    perror("can't set IO permissions!" );
  11.    return -1;
  12.  }
  13.  
  14.  int i;
  15.  int position = 17;
  16.  char Text1[9] = {'H', 'e', 'l', 'l', 'o', '.', '.', '.', ' '};
  17.  char Text2[11] = {'H', 'a', 'r', 'd', 'w', 'a', 'r', 'e', '.', 'f', 'r'};
  18.  
  19.  LCD_Init();    
  20.  while (1) {
  21.    LCD_ClearDisplay();    
  22.    usleep(1);
  23.    LCD_Position(position);      
  24.    for (i = 0; i <= 8 ; i++) {
  25.      int j;
  26.      for (j = 0 ; j <= i ; j++) {
  27.     LCD_WriteChar(Text1[j]);        
  28.     usleep(5000);
  29.      }
  30.      
  31.      position = position - 1;
  32.      LCD_Position(position);
  33.      usleep(5000);
  34.    }
  35.    position = 0x52;
  36.  
  37.    LCD_Position(position);
  38.    sleep(1);
  39.    for (i = 0; i <= 10 ; i++) {
  40.      int j;
  41.    
  42.      for (j = 0 ; j <= i ; j++) {
  43.     LCD_WriteChar(Text2[j]);        
  44.     usleep(5000);
  45.      }
  46.      position = position - 1;
  47.    
  48.      LCD_Position(position);
  49.      usleep(5000);
  50.    }  
  51.    sleep(1);
  52.    position = 17;
  53.  }  
  54.  if (ioperm(BASEPORT, 3, 0)) {
  55.    perror("can't reset IO permissions!" );
  56.    return -1;
  57.  }  
  58.  return 0;
  59. }

n°2110132
Profil sup​primé
Posté le 07-11-2011 à 12:45:38  answer
 

j'ai testé le code.
 
 

void:libparalcd# ./paralcd bonjour
Position: caractère 9 de la ligne 1
Taper quelque chose pour quitter le programme.


 
Ca affiche "bonjour  ".  :pt1cable:
 
edit, avec deux espace à la fin de la chaîne.


Message édité par Profil supprimé le 07-11-2011 à 12:46:49
n°2110134
gilou
Modérateur
Modosaurus Rex
Posté le 07-11-2011 à 12:54:10  profilanswer
 

Donc c'est OK: On est en ligne 1, au 9e caractère :whistle:  
 
Bon, je suis à la bourre, alors c'est très brut de décoffrage...
 

Code :
  1. void set_rawposition(unsigned char rawposition) {
  2.     unsigned char command = 0x80 + rawposition;
  3.     unsigned char control = GetControl();
  4.    
  5.     Set_RS(control);
  6.     usleep(1); 
  7.     SetData(command);
  8.     Set_E(control);
  9.     usleep(1); 
  10.     Clear_E(control);
  11.     usleep(1); 
  12.    
  13. }
  14. void SetPosition_LCD(int linepos, int charpos) {
  15.     unsigned char rawposition = 0;
  16.     if (linepos < 1 || linepos > 4) {
  17. printf("Incorrect line value: %d\n", linepos);
  18.     }
  19.     if (charpos < 1 || charpos > 20) {
  20. printf("Incorrect character position value: %d\n", charpos);
  21.     }
  22.     switch (linepos) {
  23.     case 1:
  24. rawposition = charpos - 1;
  25. break;
  26.     case 2:
  27. rawposition = 64 + (charpos - 1);
  28. break;
  29.     case 3:
  30. rawposition = 20 + (charpos - 1);
  31. break;
  32.     case 4:
  33. rawposition = 84 + (charpos - 1);
  34. break;
  35.     default:
  36. break;
  37.     }
  38.     set_rawposition(rawposition);
  39.     wait_LCD();
  40. }


 
Je vais bouffer, la.
A+,


---------------
There's more than what can be linked! --  Le capitaine qui ne veut pas obéir à la carte finira par obéir aux récifs. -- Il ne faut plus dire Sarkozy, mais Sarkozon -- (╯°□°)╯︵ ┻━┻
n°2110135
Profil sup​primé
Posté le 07-11-2011 à 12:55:54  answer
 

Je vais en faire  autant. Bon ap.

n°2110155
Profil sup​primé
Posté le 07-11-2011 à 13:50:20  answer
 


Ca plante toujours (mais moins) à l'utilisation de firefox, mais bon, y a pas le LCD_Wait qu'il faut aussi.  :??:
 


Message édité par Profil supprimé le 07-11-2011 à 14:00:31
n°2110266
Profil sup​primé
Posté le 08-11-2011 à 05:19:13  answer
 


 
 
Ca marche pas mal ça en fait, là.
 
Sauf que j'ai pas mon début de ligne. Et à chaque itération le curseur saute un peu n'importe où. Mais en faisant un SetPosition c'est déjà plus stable.
Si non, plus de séparateur entre les caractères. Mais c'est plus wait_LCD qu'il faux incriminer là, j'ai viré tous les appelle à la fonction. Je les remet... Ca décale toujours pareil, avec ou sans les appels à Wait_LCD, c'est pas toujours afficher là ou ça devrais et il me manque le début de ligne.
 
J'espère que t'as pas bossé toute la nuit pour rien là.  [:arn0]

Message cité 2 fois
Message édité par Profil supprimé le 08-11-2011 à 05:22:25
n°2110267
Profil sup​primé
Posté le 08-11-2011 à 05:53:19  answer
 


 
En fait non, j'ai fait une bétise, j'ai copié la fonction dans la fonction ce qui fait que ça a compilé mais ça devait pas marcher comme il faut, du coup, ben, les caractère sont bien tout décalé, avec cette fonction qui marchait encore moins.
 
Décidément, (je ferais mieux de dormir la nuit. Peut-être même le jour aussi.)

mood
Publicité
Posté le 08-11-2011 à 05:53:19  profilanswer
 

n°2110281
gilou
Modérateur
Modosaurus Rex
Posté le 08-11-2011 à 09:36:05  profilanswer
 

Non, j'ai une réunion qui me prendra toute la journée, alors j'ai fait en sorte de dormir suffisamment (ou presque, si ce [:aless] de plombier avait pas sonné a la porte très tôt ce matin).
A+,


---------------
There's more than what can be linked! --  Le capitaine qui ne veut pas obéir à la carte finira par obéir aux récifs. -- Il ne faut plus dire Sarkozy, mais Sarkozon -- (╯°□°)╯︵ ┻━┻
n°2110423
Profil sup​primé
Posté le 08-11-2011 à 23:27:25  answer
 

La bibliothèque que j'utilise actuellement :

Code :
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/io.h>
  5. // Base port cablé sur LPT1 ici
  6. #define BASEPORT    0x378
  7. #define DATAREG     BASEPORT+0
  8. #define STATUSREG   BASEPORT+1
  9. #define CONTROLREG  BASEPORT+2
  10. // Clear E : outb(control |= 0x01, CONTROLREG);   
  11. // Clear RW: outb(control |= 0x02, CONTROLREG);   
  12. // Clear RS: outb(control |= 0x08, CONTROLREG);
  13. // Set E   : outb(control &= 0xFE, CONTROLREG);
  14. // Set RW  : outb(control &= 0xFD, CONTROLREG);   
  15. // Set RS  : outb(control &= 0xF7, CONTROLREG);
  16. // Set incoming: outb(control |= 0x20, CONTROLREG);
  17. // Set outgoing: outb(control &= 0xD0, CONTROLREG);
  18. #define Clear_E(z)   outb(z |= 0x01, CONTROLREG)
  19. #define Clear_RW(z)  outb(z |= 0x02, CONTROLREG)
  20. #define Clear_RS(z)  outb(z |= 0x08, CONTROLREG)
  21. #define Set_E(z)     outb(z &= 0xFE, CONTROLREG)
  22. #define Set_RW(z)    outb(z &= 0xFD, CONTROLREG)
  23. #define Set_RS(z)    outb(z &= 0xF7, CONTROLREG)
  24. #define DataIn(z)    outb(z |= 0x20, CONTROLREG)
  25. #define DataOut(z)   outb(z &= 0xD0, CONTROLREG)
  26. #define GetControl() inb(CONTROLREG)
  27. #define GetData()    inb(DATAREG)
  28. #define SetData(z)   outb(z, DATAREG)
  29. void InitPort();
  30. void wait_LCD();
  31. void LCD_Init();
  32. void LCD_ClearDisplay();
  33. void LCD_WriteChar(char c);
  34. void LCD_WriteString(char *s);
  35. void LCD_CursorStartLine1();
  36. void LCD_CursorStartLine2();
  37. unsigned char  get_rawposition();
  38. int GetLine_LCD();
  39. int GetLinePos_LCD(int linepos);
  40. void set_rawposition(unsigned char rawposition);
  41. void SetPosition_LCD(int linepos, int charpos);
  42. void LCD_Position(int pos);
  43. void open_port (void);
  44. void close_port (void);
  45. void port_clear (void);


 

Code :
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/io.h>
  5. #include "./libparalcd.h"
  6. // Base port cablé sur LPT1 ici
  7. void InitPort() {
  8.   unsigned char control = GetControl();;
  9.   Clear_RW(control); // On met le port de données en mode || -> LCD par defaut
  10. }
  11. void wait_LCD() {
  12.   int maxtries = 255;
  13.   while(maxtries) {
  14.     usleep(3);
  15.     --maxtries;
  16.   }
  17. }
  18. void LCD_Init(){
  19.   unsigned char control = GetControl();
  20.  
  21.   // On va utiliser les valeurs par défaut
  22.   /* ************************************************** */
  23.   Clear_RS(control);
  24.   usleep(1);
  25.   SetData(0x38);      // 8 bits, 2 lignes, (Fonte 5x8)
  26.   Set_E(control);
  27.   usleep(1);
  28.   Clear_E(control);
  29.   usleep(1);
  30.   wait_LCD();
  31.   /**************************************************** */
  32.   Clear_RS(control);
  33.   usleep(1);
  34.   SetData(0x0F);      // Display ON Cursor ON
  35.   Set_E(control);
  36.   usleep(1);
  37.   Clear_E(control);
  38.   usleep(1);
  39.   wait_LCD();
  40.   Clear_RS(control);
  41.   usleep(1);
  42.   SetData(0x06);      // Left -> Right
  43.   Set_E(control);
  44.   usleep(1);
  45.   Clear_E(control);
  46.   usleep(1);
  47.   wait_LCD();
  48. }
  49. void LCD_ClearDisplay() {
  50.   unsigned char control = GetControl();
  51.   Clear_RS(control);
  52.   usleep(1);
  53.   SetData(0x01);
  54.   Set_E(control);
  55.   usleep(1);
  56.   Clear_E(control);
  57.   usleep(1);
  58.   wait_LCD();
  59. }
  60. void LCD_WriteChar(char c) {
  61.   unsigned char control = GetControl();
  62.   usleep(200);
  63.   Set_RS(control);
  64.   usleep(1);
  65.   SetData(c);
  66.   Set_E(control);
  67.   usleep(1);
  68.   Clear_E(control);   
  69.   wait_LCD();
  70.  
  71. }
  72. void LCD_WriteString(char *s) {
  73.   while (*s) {
  74.     LCD_WriteChar(*s++);
  75.     usleep(20);
  76.   }
  77. }
  78. void LCD_CursorStartLine1() {
  79.   unsigned char control = GetControl();
  80.  
  81.   Clear_RS(control);
  82.   usleep(1);
  83.   SetData(0x80);
  84.   Set_E(control);
  85.   usleep(1);
  86.   Clear_E(control);
  87.   usleep(1);
  88.   wait_LCD();
  89. }
  90. void LCD_CursorStartLine2() {
  91.   unsigned char control = GetControl();
  92.  
  93.   Clear_RS(control);
  94.   usleep(1);
  95.   SetData(0xC0);
  96.   Set_E(control);
  97.   usleep(1);
  98.   Clear_E(control);
  99.   usleep(1);
  100.   wait_LCD();
  101. }
  102. unsigned char  get_rawposition() {
  103.   unsigned char control = GetControl();
  104.   unsigned char data;
  105.   Clear_RS(control);
  106.   Set_RW(control);
  107.   usleep(1);
  108.   SetData(0xFF);         // Set All Pins to FF before read
  109.   DataIn(control);
  110.   Set_E(control);        // Strobe command to LCD
  111.   usleep(1);
  112.   data = GetData();      // Read Position
  113.   data &= 0x7F;          // Get high bit
  114.   DataOut(control);
  115.   Clear_E(control);
  116.   usleep(1);
  117.   Clear_RW(control);      // Avoid Bus conflict
  118.   usleep(1);
  119.   return data;
  120. }
  121. int GetLine_LCD() {
  122.   int linepos = 0;
  123.   unsigned char rawposition = get_rawposition();
  124.   wait_LCD();
  125.   if (rawposition >= 0) {
  126.     if (rawposition <= 19) {
  127.       linepos = 1;
  128.     }
  129.     else if (rawposition <= 39) {
  130.       linepos = 3;
  131.     }
  132.     else if (rawposition >= 64) {
  133.       if (rawposition <= 83) {
  134. linepos = 2;
  135.       }
  136.       else if (rawposition <= 103) {
  137. linepos = 4;
  138.       }
  139.     }
  140.   }
  141.   if (linepos < 1 || linepos > 4) {
  142.     printf("Incorrect raw position value: %X\n", rawposition);
  143.   }
  144.   return linepos;
  145. }
  146. int GetLinePos_LCD(int linepos) {
  147.   int charpos = 0;
  148.   unsigned char rawposition = get_rawposition();
  149.   wait_LCD();
  150.   switch (linepos) {
  151.   case 1:
  152.     charpos = rawposition +1;
  153.     break;
  154.   case 2:
  155.     charpos = (rawposition +1) - 64;
  156.     break;
  157.   case 3:
  158.     charpos = (rawposition +1) - 20;
  159.     break;
  160.   case 4:
  161.     charpos = (rawposition +1) - 84;
  162.     break;
  163.   default:
  164.     break;
  165.   }
  166.   if (charpos < 1 || charpos > 20) {
  167.     printf("Line %d Incorrect raw position value: %X\n", linepos, rawposition);
  168.     charpos = 0;
  169.   }
  170.   return charpos;
  171. }
  172. void set_rawposition(unsigned char rawposition) {
  173.   unsigned char command = 0x80 + rawposition;
  174.   unsigned char control = GetControl();
  175.  
  176.   outb(0x08, CONTROLREG);
  177.   usleep(20);
  178.   outb(command, DATAREG);
  179.   usleep(20);
  180.   outb(0x0A,    CONTROLREG); // Signal LCD with a strobe [0x0A 0: Emission, A: E active]
  181.   usleep(10);                 // Strobe duration: 500 ns
  182.   outb(0x0B,    CONTROLREG); // Reset CONTROL [0x0B 0: Write, B: RS RW E inactive]
  183.   usleep(50);                 // Wait before next strobe: 500 ns
  184. }
  185. void SetPosition_LCD(int linepos, int charpos) {
  186.   unsigned char rawposition = 0;
  187.   if (linepos < 1 || linepos > 4) {
  188.     printf("Incorrect line value: %d\n", linepos);
  189.   }
  190.   if (charpos < 1 || charpos > 20) {
  191.     printf("Incorrect character position value: %d\n", charpos);
  192.   }
  193.   switch (linepos) {
  194.   case 1:
  195.     rawposition = charpos - 1;
  196.     break;
  197.   case 2:
  198.     rawposition = 64 + (charpos - 1);
  199.     break;
  200.   case 3:
  201.     rawposition = 20 + (charpos - 1);
  202.     break;
  203.   case 4:
  204.     rawposition = 84 + (charpos - 1);
  205.     break;
  206.   default:
  207.     break;
  208.   }
  209.   set_rawposition(rawposition);
  210.   wait_LCD();
  211. }
  212. void open_port (void) {
  213.   if (ioperm(BASEPORT, 3, 1)) {
  214.     perror("can't set IO permissions!" );   
  215.   } 
  216. }
  217. void close_port (void) {
  218.   if (ioperm(BASEPORT, 3, 0)) {
  219.     perror("can't reset IO permissions!" );
  220.   } 
  221. }
  222. void port_clear (void) {
  223.   outb(0xFF, DATAREG); 
  224.   usleep(20);
  225. }


 
La fonction original de set_rawposition n'était pas efficace, alors, je suis revenu à une anciene méthode.
 
 
Un programme qui exploite la bibliothèque ci-dessus :
 

Code :
  1. /* Ce programme affiche les information de /proc/meminfo sur un L'afficheur LCD */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <string.h>
  6. #include "./libparalcd.h"
  7. #include <time.h>
  8. int main (void) {
  9.  
  10.   char date[9];
  11.   char hostname[9];
  12.  
  13.   char dummy[4096];
  14.  
  15.   char file[] = "/proc/meminfo";
  16.   FILE *fp;
  17.   char valeur[10];
  18.   char name[10];
  19.   if (system(dummy)) return (1);
  20.  
  21.   fp = fopen(file, "r" );
  22.   if (!fp) {
  23.     perror("/proc/meminfo" );
  24.     return -1;
  25.   }
  26.    
  27.   time_t current_date = time(NULL);
  28.  
  29.   strftime(date, sizeof(date), "%H:%M:%S", localtime(&current_date));
  30.   gethostname(hostname, sizeof(hostname));
  31.  
  32.   if (ioperm(BASEPORT, 3, 1)) {
  33.     perror("can't set IO permissions!" );
  34.     return -1;
  35.   }
  36.  
  37.  
  38.   LCD_Init();   
  39.   usleep(120); 
  40.    
  41.   int i; 
  42.   for (i = 1; i <= 29 ; i++) {
  43.     fscanf(fp, "%s%s%s\n", name, valeur, dummy);   
  44.     current_date = time(NULL);
  45.    
  46.     strftime(date, sizeof(date), "%H:%M:%S", localtime(&current_date));
  47.     LCD_ClearDisplay();       
  48.     usleep(120);
  49.     SetPosition_LCD(1, 1);
  50.     usleep(120); 
  51.     LCD_WriteString(date);
  52.     usleep(120); 
  53.     SetPosition_LCD(1, 10);
  54.     usleep(120); 
  55.     LCD_WriteString(hostname);   
  56.     usleep(120); 
  57.     SetPosition_LCD(3, 1);   
  58.     usleep(120); 
  59.     LCD_WriteString(name);
  60.     usleep(120); 
  61.     SetPosition_LCD(4, 1);
  62.     usleep(120); 
  63.     LCD_WriteString(valeur);   
  64.     usleep(120); 
  65.     port_clear();
  66.     sleep(1);
  67.   }
  68.   fclose(fp);
  69.   port_clear();
  70.   if (ioperm(BASEPORT, 3, 0)) {
  71.     perror("can't reset IO permissions!" );
  72.     return -1;
  73.   }
  74.   return 0;
  75. }


 
 
L'utilisation de port_clear, c'est à cause d'un afficheur défectueux.
 
 

n°2110429
gilou
Modérateur
Modosaurus Rex
Posté le 09-11-2011 à 01:09:00  profilanswer
 

Tu as combien de lignes sur l'afficheur?
4 de 20 caractères?
avec une poursuite de la 1 sur la 3 et de la 2 sur la 4?
 
Comme je l'ai faite rapidement, elle était peut être pas bonne.
Ces temps ci, je devrais être plus au calme que la semaine dernière.
 
A+,


Message édité par gilou le 09-11-2011 à 01:11:53

---------------
There's more than what can be linked! --  Le capitaine qui ne veut pas obéir à la carte finira par obéir aux récifs. -- Il ne faut plus dire Sarkozy, mais Sarkozon -- (╯°□°)╯︵ ┻━┻
n°2110431
Profil sup​primé
Posté le 09-11-2011 à 01:27:15  answer
 

Oui, j'ai 4x20 caractères et ça saute aussi de la 3 à la 2 et de la 4 à la 1.
 
 
Rhhhaaa.  :o


Message édité par Profil supprimé le 09-11-2011 à 01:28:20
n°2110437
Profil sup​primé
Posté le 09-11-2011 à 04:11:35  answer
 

Un autre programme qui affiche des information sur le système.
 
$hostname : hh:mm:ss
cpu            :$cpu_usage
mem          :$mem_usage
swap          :$swap_usage
 

Code :
  1. /* Ce programme affiche les informations sur les ressources du PC sur l'afficheur LCD */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <string.h>
  6. #include "./libparalcd.h"
  7. #include <time.h>
  8. int main (void) {
  9.  
  10.   char date[9];
  11.   char hostname[9];
  12.  
  13.  
  14.  
  15.   char file[] = "/proc/meminfo";
  16.  
  17.   char valeur[10];
  18.   char name[10];
  19.   char dummy[4];
  20.   FILE *cpufp;
  21.   FILE *memfp;
  22.   FILE *fp;
  23.   char label_cpu[]  = "cpu   : \0";
  24.   char label_mem[]  = "mem   : \0";
  25.   char label_swap[] = "swap  : \0";
  26.   //char label_proc[] = "proc  : \0";
  27.   //char label_pid[]  = "pid   : \0";
  28.   //char label_pri[]  = "prio  : \0";   
  29.  
  30.   char value_used[10];
  31.   char value_swap[10];
  32.   char value_cpu[10];
  33.  
  34.  
  35.  
  36.   if (system(dummy)) return (1);
  37.  
  38.   fp = fopen(file, "r" );
  39.   if (!fp) {
  40.     perror("/proc/meminfo" );
  41.     return -1;
  42.   }
  43.    
  44.   time_t current_date = time(NULL);
  45.  
  46.   strftime(date, sizeof(date), "%H:%M:%S", localtime(&current_date));
  47.   gethostname(hostname, sizeof(hostname));
  48.  
  49.   if (ioperm(BASEPORT, 3, 1)) {
  50.     perror("can't set IO permissions!" );
  51.     return -1;
  52.   }
  53.  
  54.  
  55.   LCD_Init();   
  56.   usleep(120); 
  57.    
  58.   int i; 
  59.   for (i = 1; i <= 5 ; i++)
  60.     fscanf(fp, "%s%s%s\n", name, value_swap, dummy);   
  61.   fclose(fp);
  62.   cpufp = popen("ps aux| awk 'NR > 0 { s +=$3 }; END {print s}'","r" );
  63.   fread(value_cpu, 1, sizeof(value_cpu)-1, cpufp);
  64.   fclose(cpufp);
  65.   memfp = popen("ps aux| awk 'NR > 0 { s +=$4 }; END {print s}'","r" );
  66.   fread(value_used, 1, sizeof(value_used)-1, memfp);
  67.   fclose(memfp);
  68.  
  69.   strftime(date, sizeof(date), "%H:%M:%S", localtime(&current_date));
  70.   LCD_ClearDisplay();       
  71.   usleep(120);           
  72.   SetPosition_LCD(1, 1);
  73.   usleep(120); 
  74.   LCD_WriteString(hostname);   
  75.   usleep(120);
  76.   SetPosition_LCD(1, 7);
  77.   usleep(120); 
  78.   LCD_WriteString(":" );   
  79.   usleep(120);
  80.   SetPosition_LCD(1, 9);
  81.   usleep(120); 
  82.   LCD_WriteString(date);
  83.   usleep(120);     
  84.   SetPosition_LCD(2, 1);     
  85.   usleep(120);
  86.   LCD_WriteString(label_cpu);   
  87.   usleep(120); 
  88.   LCD_WriteString(value_cpu);   
  89.   usleep(120); 
  90.   SetPosition_LCD(3, 1);
  91.   LCD_WriteString(label_mem);   
  92.   usleep(120); 
  93.   LCD_WriteString(value_used);   
  94.   usleep(120); 
  95.   SetPosition_LCD(4, 1);
  96.   usleep(120); 
  97.   LCD_WriteString(label_swap);   
  98.   usleep(120);       
  99.   LCD_WriteString(value_swap);     
  100.   port_clear();
  101.   if (ioperm(BASEPORT, 3, 0)) {
  102.     perror("can't reset IO permissions!" );
  103.     return -1;
  104.   }
  105.   return 0;
  106. }


Message édité par Profil supprimé le 09-11-2011 à 06:28:26
n°2110441
Profil sup​primé
Posté le 09-11-2011 à 07:33:57  answer
 

La version en boucle infini.

Code :
  1. /* Ce programme affiche les informations de d'usage du PC sur l'afficheur afficheur LCD */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <string.h>
  6. #include "./libparalcd.h"
  7. #include <time.h>
  8. int main (void) {
  9.   char date[9];
  10.   char hostname[9];
  11.   char dummy[4096];
  12.  
  13.   char file[] = "/proc/meminfo";
  14.   FILE *fp;
  15.   FILE *cpufp; 
  16.   char valeur[10];
  17.   char name[10];
  18.   char label_mem[]  = "mem  : \0";
  19.   char label_swap[] = "swap : \0";
  20.   char label_cpu[]  = "cpu  : \0";
  21.   float mem_total, mem_free, mem_swap, mem_used = 0;
  22.  
  23.   char value_total[10];
  24.   char value_swap[10];
  25.   char value_cpu[10];
  26.   time_t current_date = time(NULL);
  27.   if (system(dummy)) return (1);
  28.  
  29.   strftime(date, sizeof(date), "%H:%M:%S", localtime(&current_date));
  30.   gethostname(hostname, sizeof(hostname));
  31.  
  32.   if (ioperm(BASEPORT, 3, 1)) {
  33.     perror("can't set IO permissions!" );
  34.     return -1;
  35.   }
  36.   cpufp = popen("ps aux| awk 'NR > 0 { s +=$3 }; END {print s}'","r" );
  37.   fread(value_cpu, 1, sizeof(value_cpu)-1, cpufp);
  38.   fclose(cpufp);
  39.   LCD_Init(); 
  40.   while (1) {
  41.   usleep(120);
  42.   fp = fopen(file, "r" );
  43.   if (!fp) {
  44.     perror("/proc/meminfo" );
  45.     return -1;
  46.   }
  47.   int i;
  48.   for (i = 1; i <= 5 ; i++) {
  49.     fscanf(fp, "%s%s%s\n", name, valeur, dummy); 
  50.     current_date = time(NULL);
  51.  
  52.     switch (i) {
  53.    
  54.     case 1 : {
  55.    
  56.       char *p_conv = NULL;
  57.       mem_total = (float)strtol(valeur, &p_conv, 10);   
  58.       strftime(date, sizeof(date), "%H:%M:%S", localtime(&current_date));
  59.      
  60.       break;
  61.     }
  62.     case 2 : {
  63.       char *p_conv = NULL;
  64.       mem_free = (float)strtol(valeur, &p_conv, 10);
  65.       mem_used = ((mem_total-mem_free)*100)/mem_total;                     
  66.      
  67.       break;
  68.     }
  69.     case 5 : {
  70.       char *p_conv = NULL;
  71.       mem_swap = (float)strtol(valeur, &p_conv, 10);   
  72.       strftime(date, sizeof(date), "%H:%M:%S", localtime(&current_date));
  73.       LCD_ClearDisplay();           
  74.       usleep(120);         
  75.       SetPosition_LCD(1, 1);
  76.       usleep(1); 
  77.       LCD_WriteString(hostname);   
  78.       usleep(1);
  79.       SetPosition_LCD(1, 6);
  80.       usleep(1); 
  81.       LCD_WriteChar(':');   
  82.       usleep(1);
  83.       SetPosition_LCD(1, 8);
  84.       usleep(1); 
  85.       LCD_WriteString(date);
  86.       usleep(1);     
  87.       SetPosition_LCD(2, 1);     
  88.       usleep(1);
  89.       LCD_WriteString(label_cpu);   
  90.       usleep(1); 
  91.       LCD_WriteString(value_cpu);   
  92.       usleep(1); 
  93.       SetPosition_LCD(3, 1);
  94.       LCD_WriteString(label_mem);   
  95.       usleep(1);             
  96.       sprintf(value_total, "%f", mem_used);
  97.       LCD_WriteString(value_total); 
  98.       usleep(120);
  99.       SetPosition_LCD(4, 1);
  100.       usleep(120);
  101.       LCD_WriteString(label_swap); 
  102.       usleep(120);     
  103.       sprintf(value_swap, "%f", mem_swap);
  104.       LCD_WriteString(value_swap);   
  105.       port_clear();
  106.       sleep(1);
  107.    
  108.     }
  109.     }
  110.   }
  111.   fclose(fp);
  112.   port_clear();
  113.   LCD_Init(); 
  114.   }
  115.   if (ioperm(BASEPORT, 3, 0)) {
  116.     perror("can't reset IO permissions!" );
  117.     return -1;
  118.   }
  119.   return 0;
  120. }


 


Message édité par Profil supprimé le 09-11-2011 à 15:01:41
n°2110446
Profil sup​primé
Posté le 09-11-2011 à 08:49:03  answer
 

Je teste une config comme ça ce matin...
 

Code :
  1. #define GetControl() 0x0F
  2. #define SetControl(z) outb(z, CONTROLREG)
  3. #define REGISTER_DELAY 1
  4. void InitPort() {
  5.   unsigned char control = GetControl();
  6.   Clear_RW(control); // On met le port de données en mode || -> LCD par defaut
  7. void wait_LCD() {
  8.   char control = GetControl();
  9.   int maxtries = 255;
  10.   unsigned char busy = 0x80; // Mask for D7                                                                                                   
  11.   while (maxtries && busy?1:0) {
  12.     usleep(REGISTER_DELAY);
  13.     outb(0x28, CONTROLREG); // Signal LCD with a strobe [0x28 2: Reception, 8: RW E active]                                                   
  14.     usleep(REGISTER_DELAY);
  15.     outb(0x0B, CONTROLREG); // Reset CONTROL [0x0B 0: Emission, B: RS RW E inactive]                                                         
  16.     usleep(REGISTER_DELAY);
  17.     busy &= inb(DATAREG);
  18.     --maxtries;
  19.   }
  20.   SetControl(control);


 
Parfois ça marche parfois ça marche pas. Je commence à me demander sérieusement, si c'est pas du à l'afficheur qu'est à mettre au rebut.

n°2110449
Profil sup​primé
Posté le 09-11-2011 à 09:49:51  answer
 


 
 
 
 
Bonjour Gilou,
 
Topo, on doit travailler avec le code du postquoted ci-dessus avec GetChar pour connaître les caractère non affichable qui espace le texte source.
 
Amoins que tu ais une autre idée ?
 
Et si t'as du code, je prend même si c'est pas finalisé. Histoire de garder ton esprit pour le développement des outils utiles.  :p  
 

n°2110453
Profil sup​primé
Posté le 09-11-2011 à 10:00:53  answer
 
n°2110455
gilou
Modérateur
Modosaurus Rex
Posté le 09-11-2011 à 10:24:10  profilanswer
 

> on doit travailler avec le code du postquoted ci-dessus avec GetChar pour connaître les caractère non affichable qui espace le texte source
Il faut se positionner en mémoire au bon endroit (SetPosition_LCD) et faire un appel avec une version modifiée de wait_LCD :whistle:  
par exemple, en partant de ceci:

Code :
  1. void wait_LCD() {
  2.     unsigned char control = GetControl();
  3.     unsigned char data = 0xFF;
  4.     int maxtries = 255;
  5.     while (data && maxtries) {
  6. Clear_RS(control); 
  7. Set_RW(control);
  8. usleep(1);     
  9. SetData(0xFF);         // Set All Pins to FF before read
  10. DataIn(control);     
  11. Set_E(control);        // Strobe command to LCD
  12. usleep(1);
  13. data = GetData();      // Read Data
  14. data &= 0x80;          // Get high bit
  15. DataOut(control);     
  16. --maxtries;
  17.     }
  18.     Clear_E(control); 
  19.     usleep(1);   
  20.     Clear_RW(control);      // Avoid Bus conflict
  21.     usleep(1);
  22. }


on fait quelque chose comme (écrit un poil rapidement, car je sors en course dès que c'est posté):

Code :
  1. unsigned char get_char() {
  2.     unsigned char control = GetControl();
  3.     unsigned char data = 0xFF;
  4.     int maxtries = 255;
  5.     Set_RS(control);        // RS = 1 et non 0 maintenant
  6.     Set_RW(control);
  7.     usleep(1);     
  8.     SetData(0xFF);         // Set All Pins to FF before read
  9.     DataIn(control);     
  10.     Set_E(control);        // Strobe command to LCD
  11.     usleep(5);                // On laisse un peu de temps pour que ca se fasse en interne
  12.     data = GetData();      // Read Data
  13.     DataOut(control);
  14.     Clear_E(control); 
  15.     usleep(1);
  16.     Clear_RS(control);   
  17.     Clear_RW(control);      // Avoid Bus conflict
  18.     usleep(1);
  19.     return data;
  20. }
  21. unsigned char GetChar_LCD(int line, int linepos) {
  22.    
  23.     int oldline, oldlinepos;
  24.     unsigned char data;
  25.     oldline = GetLine_LCD();
  26.     oldlinepos = GetLinePos_LCD(oldlinepos);
  27.     SetPosition_LCD(line, linepos);
  28.     data = char get_char();
  29.     SetPosition_LCD(oldline, oldlinepos);
  30.     return data;
  31. }


 
A+,
 


---------------
There's more than what can be linked! --  Le capitaine qui ne veut pas obéir à la carte finira par obéir aux récifs. -- Il ne faut plus dire Sarkozy, mais Sarkozon -- (╯°□°)╯︵ ┻━┻
n°2110489
Profil sup​primé
Posté le 09-11-2011 à 13:02:07  answer
 

Merci gilou !
 
 
J'ai fait une page de sorties console, c'est quatre appel d'un programme qui affiche divers chaîne sur les 4 ligne tout frais d'un reboot à froid. before indique qu'on est juste aprrès le positionnement, after après l'affichage.
 

void:libparalcd-2.012e+03# ./lcd_sys2
Line 0 Incorrect raw position value: 6
Incorrect character position value: 0
before get char 32 at raw 3 line 1  
After get char 32 at raw 3 line 1  
Incorrect raw position value: 3D
Line -1074145888 Incorrect raw position value: 3E
Incorrect line value: 0
Incorrect character position value: 0
before get char 32 at raw 4 line 1  
after char 32 at raw 4 line 1  
Incorrect raw position value: 28
Line -1074145888 Incorrect raw position value: 2B
Incorrect line value: 0
Incorrect character position value: 0
before get char 32 at raw 1 line 1  
After get char 32 at raw 1 line 1  
Incorrect raw position value: 3C
Line 0 Incorrect raw position value: 31
Incorrect line value: 0
Incorrect character position value: 0
before get char 32 at raw 2 line 1  
after get char 32 at raw 2 line 1  
void:libparalcd-2.012e+03# ./lcd_sys2
Line 0 Incorrect raw position value: 1D
Incorrect character position value: 0
before get char 32 at raw 3 line 1  
After get char 32 at raw 3 line 1  
Line -1078193728 Incorrect raw position value: 57
Incorrect character position value: 0
before get char 32 at raw 4 line 1  
after char 32 at raw 4 line 1  
Line -1078193728 Incorrect raw position value: 3
Incorrect character position value: 0
before get char 32 at raw 1 line 1  
After get char 32 at raw 1 line 1  
Line 0 Incorrect raw position value: 4B
Incorrect character position value: 0
before get char 32 at raw 2 line 1  
after get char 32 at raw 2 line 1  
void:libparalcd-2.012e+03# ./lcd_sys2
Line 0 Incorrect raw position value: 23
Incorrect character position value: 0
before get char 32 at raw 3 line 1  
After get char 32 at raw 3 line 1  
Line -1079273280 Incorrect raw position value: 57
Incorrect character position value: 0
before get char 32 at raw 4 line 1  
after char 32 at raw 4 line 1  
Line -1079273280 Incorrect raw position value: 3
Incorrect character position value: 0
before get char 32 at raw 1 line 1  
After get char 32 at raw 1 line 1  
Line 0 Incorrect raw position value: 2C
Incorrect character position value: 0
before get char 32 at raw 2 line 1  
after get char 32 at raw 2 line 1  
void:libparalcd-2.012e+03# ./lcd_sys2
Line 0 Incorrect raw position value: 23
Incorrect character position value: 0
before get char 32 at raw 3 line 1  
After get char 32 at raw 3 line 1  
Line -1080131600 Incorrect raw position value: 57
Incorrect character position value: 0
before get char 32 at raw 4 line 1  
after char 32 at raw 4 line 1  
Line -1080131600 Incorrect raw position value: 3
Incorrect character position value: 0
before get char 32 at raw 1 line 1  
After get char 32 at raw 1 line 1  
Line 0 Incorrect raw position value: 11
Incorrect character position value: 0
before get char 0 at raw 2 line 1  
after get char 0 at raw 2 line 1


 
J'oubliais, ça marche pas, ça affiche rien.


Message édité par Profil supprimé le 09-11-2011 à 13:02:38
n°2110496
Profil sup​primé
Posté le 09-11-2011 à 13:28:51  answer
 

La il y avait 49 dans une espace.
 
 
Ca avance d'un caractère à la lecture ?
 
 
 
Apriori, je ne peux même pas lire le tableau sans modifier l'état de l'afficheur.
J'ai fait ça simplement

Code :
  1. int i, j;
  2.   for (i = 1 ;i <= 4; i++) {
  3.     for (j = 1 ; j <= 20; j++) {
  4.       getted_char = GetChar_LCD(i, j);
  5.       printf("after char %d at raw %d line %d \n", getted_char, i, j);
  6.     }
  7.   }


Ca m'a effacé l'écran.


Message édité par Profil supprimé le 09-11-2011 à 13:42:45
n°2110525
gilou
Modérateur
Modosaurus Rex
Posté le 09-11-2011 à 15:28:50  profilanswer
 

Si tu fais  
SetData('A');         // Set All Pins to FF before read
au lieu de
SetData(0xFF);         // Set All Pins to FF before read
dans get_char()
Est-ce que ça te remplis l'écran de A en faisant ta boucle précédente?
A+,


---------------
There's more than what can be linked! --  Le capitaine qui ne veut pas obéir à la carte finira par obéir aux récifs. -- Il ne faut plus dire Sarkozy, mais Sarkozon -- (╯°□°)╯︵ ┻━┻
n°2110526
Profil sup​primé
Posté le 09-11-2011 à 15:31:13  answer
 

J'ai refais le même chose en l'exécution d'un seul prog, sans Wait_LCD.
L'appel à GetChar_LCD à des effets de bord.
 
Bon, je t'attend un peu.

n°2110529
gilou
Modérateur
Modosaurus Rex
Posté le 09-11-2011 à 15:34:48  profilanswer
 

>> L'appel à GetChar_LCD à des effets de bord.
A un flag près (RS a 1 et pas a 0) et sans boucle, c'est la même chose que Wait_LCD, vu que c'est une des deux seules commandes qui va lire des données de l'afficheur.
Alors, si l'une a des problèmes, je suis pas surpris que l'autre en ait aussi.
A+,


---------------
There's more than what can be linked! --  Le capitaine qui ne veut pas obéir à la carte finira par obéir aux récifs. -- Il ne faut plus dire Sarkozy, mais Sarkozon -- (╯°□°)╯︵ ┻━┻
n°2110532
Profil sup​primé
Posté le 09-11-2011 à 15:38:52  answer
 

gilou a écrit :

Si tu fais  
SetData('A');         // Set All Pins to FF before read
au lieu de
SetData(0xFF);         // Set All Pins to FF before read
dans get_char()
Est-ce que ça te remplis l'écran de A en faisant ta boucle précédente?
A+,


 
Pas du tout, par contre dans les itération du programme qui affiche les info system la liste des 80 caractère représente bien à première vue le texte écrit. Ca lie bien quoi, mais aubout d'un certain nombre d'itération tout semble décalé. Et ca affiche plus rien, puis ça réapparait.

n°2110543
gilou
Modérateur
Modosaurus Rex
Posté le 09-11-2011 à 15:56:22  profilanswer
 

D'un point de vue général, SetPosition_LCD met bien le curseur a l'endroit prévu?
>> mais aubout d'un certain nombre d'itération tout semble décalé
Je vois pas trop ce qui fait ça.
Si tu veux lire les specs du controlleur de ton afficheur sur un document plus détaillé, http://doc.chipfind.ru/pdf/sitronix/st7066u0a.pdf
A+,


---------------
There's more than what can be linked! --  Le capitaine qui ne veut pas obéir à la carte finira par obéir aux récifs. -- Il ne faut plus dire Sarkozy, mais Sarkozon -- (╯°□°)╯︵ ┻━┻
n°2110567
Profil sup​primé
Posté le 09-11-2011 à 16:28:57  answer
 

gilou a écrit :

D'un point de vue général, SetPosition_LCD met bien le curseur a l'endroit prévu?


 
pour line de 1 à 4 et raw de 1 à 20
 
A  chaque itérationde SetPosition_LCD(line, raw) ça met un caractère plein en position courante et ça avance d'un caractère.
 
Je parle de ce set rawposition :
 

Code :
  1. void set_rawposition(unsigned char rawposition) {
  2.   unsigned char command = 0x80 + rawposition;
  3.   unsigned char control = GetControl();
  4.     Set_RS(control);
  5.     usleep(1);
  6.     SetData(command);
  7.     Set_E(control);
  8.     usleep(1);
  9.     Clear_E(control);
  10.     usleep(1);
  11. }


 
Corrrection, c'est 80 raw, mais 20


Message édité par Profil supprimé le 09-11-2011 à 17:14:11
n°2110570
Profil sup​primé
Posté le 09-11-2011 à 16:33:38  answer
 

En plus c'est pas ça du tout qui se passe je capte rien, ça incrémente d'un caractère, c'est à dire que de la ligne 1 on pase à la trois de la 3 à la deux de deux à 4. On suit la ligne quoi.

n°2110577
Profil sup​primé
Posté le 09-11-2011 à 16:49:18  answer
 

Et mon code ne fonctionne plus non plus, c'est à dire que l'utilisation de SetPosition_LCD  juste après l'Init_LCD plante l'afficheur.

n°2110583
Profil sup​primé
Posté le 09-11-2011 à 17:03:21  answer
 

Si ça ça marche pas trop mal, c'est ton code, je disais le mien mais c'est l'ancien.
Mais au bout d'un certain nombre d'itération ça perturbe.quand même de fait 80 set_position d'affilé.
 

Code :
  1. void set_rawposition(unsigned char rawposition) {
  2.   unsigned char command = 0x80 + rawposition;
  3.   unsigned char control = GetControl();
  4.   outb(0x08, CONTROLREG);
  5.   usleep(20);
  6.   outb(command, DATAREG);
  7.   usleep(20);
  8.   outb(0x0A,    CONTROLREG); // Signal LCD with a strobe [0x0A 0: Emission, A: E active]                                                                                                                             
  9.   usleep(10);                 // Strobe duration: 500 ns                                                                                                                                                             
  10.   outb(0x0B,    CONTROLREG); // Reset CONTROL [0x0B 0: Write, B: RS RW E inactive]                                                                                                                                   
  11.   usleep(50);                 // Wait before next strobe: 500 ns                                                                                                                                                     
  12.   }


 
 
Il y a ce pdf très simple sur les compatible HD44780. http://www.google.fr/url?sa=t&rct= [...] TA&cad=rja

Message cité 1 fois
Message édité par Profil supprimé le 09-11-2011 à 17:09:42
n°2110590
Profil sup​primé
Posté le 09-11-2011 à 17:37:17  answer
 


 
 
 
J'ai commencé à écrire une lib en fonction de ce que je comprenais de ce document, mais j'ai buté sur la troisième valeur de io, qui peut prendre STROBE en plus de READ et CTRL
 

Code :
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/io.h>
  5. // Base port cablé sur LPT1 ici                                                                                                                                                                                     
  6. #define BASEPORT    0x378
  7. #define DATAREG     BASEPORT+0
  8. #define STATUSREG   BASEPORT+1
  9. #define CONTROLREG  BASEPORT+2
  10. char reg;
  11. #define CTRL 0
  12. #define READ 1
  13. #define clrbit(io) outb(io?0x01:0x28, CONTROLREG);
  14. #define setbit(io) outb(io?0xFE:0x0D, CONTROLREG);
  15. woid WriteCommon (unsigned char value)
  16. {
  17.   clrbi(READ);
  18.   value = value & 0x0F;
  19.   value = value << 4;
  20. void WriteCtrl(unsigned char value)
  21. {
  22.   clrbit(CTRL);
  23.   WriteCommon(value);
  24. }
  25. void LCD_Init (void) {
  26. }


Message édité par Profil supprimé le 09-11-2011 à 17:38:25
n°2110603
Profil sup​primé
Posté le 09-11-2011 à 18:54:34  answer
 

Là j'ai ça comme Wait_Busy()  
 

Code :
  1. void wait_busy() {                                                                                                                                                 
  2.   unsigned char busy = 0x80; // Mask for D7                                                                                                                                                                         
  3.   do {
  4.     outb(0x01, CONTROLREG); // Signal LCD with a strobe [0x28 2: Reception, 8: RW E active]                                                                                                                         
  5.     usleep(100);
  6.     outb(0xFE, CONTROLREG); // Reset CONTROL [0x0B 0: Emission, B: RS RW E inactive]                                                                                                                                 
  7.     usleep(100);
  8.     busy &= inb(DATAREG);
  9.                                                                                                                                                                                  
  10.   } while  (busy?1:0);


 
M'ais j'affiche même pas le curseur. Mais ça sort de la boucle. C'est du "vieux" code.
 
Bon, je vais essayer de me débrouiller pour suivre le doc pdf d'au-dessus.

n°2110606
gilou
Modérateur
Modosaurus Rex
Posté le 09-11-2011 à 19:30:17  profilanswer
 

si tu imprimais la valeur de datareg, qu'on aie une idée de ce qu'il y a dedans...
 
printf("DATAREG: %x\n", inb(DATAREG));
 
A+,

Message cité 1 fois
Message édité par gilou le 09-11-2011 à 19:43:25

---------------
There's more than what can be linked! --  Le capitaine qui ne veut pas obéir à la carte finira par obéir aux récifs. -- Il ne faut plus dire Sarkozy, mais Sarkozon -- (╯°□°)╯︵ ┻━┻
n°2110613
Profil sup​primé
Posté le 09-11-2011 à 20:16:41  answer
 

gilou a écrit :

si tu imprimais la valeur de datareg, qu'on aie une idée de ce qu'il y a dedans...
 
printf("DATAREG: %x\n", inb(DATAREG));
 
A+,


 
Dans la boucle Wait_Busy ?
 
 
 
J'ai fait ça mais je me tape une erreur de segmentation avant même d'attaquer le programme.
C'est mon premier code C pour ainsi dire, alors, ne soyez pas trop indigné par mon verbe.

Code :
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/io.h>
  5. #include <time.h>
  6. // Base port cablé sur LPT1 ici                                                                                                                                                                                     
  7. #define BASEPORT    0x378
  8. #define DATAREG     BASEPORT+0
  9. #define STATUSREG   BASEPORT+1
  10. #define CONTROLREG  BASEPORT+2
  11. #define STROBE 0
  12. #define CTRL 1
  13. #define READ 2
  14. unsigned char clear_bit(int bit, unsigned char reg) { 
  15.   switch (bit) {       
  16.   case 0 : { // STROBE
  17.     reg &= 0x01;
  18.     outb(reg, CONTROLREG);
  19.   }
  20.    
  21.   case 1 : { //CTRL  
  22.     reg &= 0x02;
  23.     outb(reg, CONTROLREG);
  24.   }
  25.   case 2 : { //READ
  26.     reg &= 0x08;
  27.     outb(reg, CONTROLREG);
  28.   }
  29.   default
  30.     return -1;
  31.   }
  32.   return reg;
  33. }
  34. unsigned char set_bit(int bit, unsigned char reg) {
  35.  
  36.   switch (bit) {       
  37.   case 0 : { // STROBE
  38.     reg &= 0xFE;
  39.     outb(reg, CONTROLREG);
  40.   }
  41.    
  42.   case 1 : { //CTRL  
  43.     reg &= 0xFD;
  44.     outb(reg, CONTROLREG);
  45.   }
  46.   case 2 : { //READ
  47.     reg &= 0xF7;
  48.     outb(reg, CONTROLREG);
  49.   }
  50.   default
  51.     return -1;
  52.   }
  53.   return reg;
  54. }
  55. unsigned char WriteCommon (unsigned char value, unsigned char reg) {
  56.  
  57.   unsigned char data = 0x00;
  58.   reg = clear_bit(READ, reg);
  59.   value = value & 0x0F;
  60.   value = value << 4;
  61.   data = data & 0x0F;
  62.   data = data | value;
  63.   outb(data, DATAREG);
  64.   reg = set_bit(STROBE, reg);
  65.   usleep(4.5);
  66.   reg = clear_bit(STROBE, reg);
  67.   reg = set_bit(READ, reg);
  68.   usleep(4.5);
  69.   return reg; 
  70.    
  71. }
  72. unsigned char WriteData (unsigned char value, unsigned char reg) {
  73.   reg = set_bit(CTRL, reg);
  74.   reg = WriteCommon(value >> 4, reg);
  75.   reg = WriteCommon(value, reg);
  76.   return reg;
  77. }
  78. unsigned char WriteCtrl (unsigned char value, unsigned char reg) {
  79.   reg = clear_bit(CTRL, reg);
  80.   reg = WriteCommon(value, reg);
  81.   return reg;
  82. }
  83. unsigned char WriteLcd (char * value, unsigned char reg) {
  84.   while (*value) {
  85.     reg = WriteData(*value++, reg);
  86.   }
  87.   return reg;
  88. }
  89. unsigned char InitLcd (unsigned char reg) {
  90.   reg = WriteCtrl(0x03, reg);
  91.   usleep(50000);
  92.   reg = WriteCtrl(0x03, reg);
  93.   usleep(1000);
  94.   reg = WriteCtrl(0x03, reg);
  95.   usleep(4.5);
  96.   reg = WriteCtrl(0x02, reg);
  97.   usleep(450);
  98.   reg = WriteCtrl(0x02, reg);
  99.   usleep(450);
  100.   reg = WriteCtrl(0x08, reg);
  101.   usleep(450);
  102.   reg = WriteCtrl(0x00, reg);
  103.   usleep(450);
  104.   reg = WriteCtrl(0x0F, reg);
  105.   usleep(450);
  106.   reg = WriteCtrl(0x00, reg);
  107.   usleep(450);
  108.   reg = WriteCtrl(0x06, reg);
  109.   usleep(450);
  110.   reg = WriteCtrl(0x00, reg);
  111.   usleep(450);
  112.   reg = WriteCtrl(0x01, reg);
  113.   usleep(450);
  114.   reg = WriteCtrl(0x00, reg);
  115.   usleep(450);
  116.   reg = WriteCtrl(0x02, reg);
  117.  
  118.   return reg;
  119. }
  120. int main (int argc, char * argv[]) {
  121.   unsigned char control;
  122.   printf("main: InitLcd...." );
  123.   control = InitLcd(control);
  124.   printf("main: WriteLcd...." );
  125.   control = WriteLcd(argv[1], control);
  126.   return control;
  127. }

n°2110614
Profil sup​primé
Posté le 09-11-2011 à 20:20:12  answer
 

DATAREG: ff
DATAREG: ff
DATAREG: 7f
DATAREG: 7f
DATAREG: 7f
DATAREG: ff
DATAREG: 7f
DATAREG: 7f
DATAREG: 7f
DATAREG: 7f
DATAREG: 7f
DATAREG: ff
DATAREG: 7f
DATAREG: 7f

Message cité 1 fois
Message édité par Profil supprimé le 09-11-2011 à 20:20:33
n°2110627
gilou
Modérateur
Modosaurus Rex
Posté le 09-11-2011 à 21:21:49  profilanswer
 


Les séquences  
DATAREG: ff
DATAREG: 7f
c'est quand on passe d'un état busy à un état non busy
Donc on doit sortir de la boucle, mais a condition que le masque du bit D7 soit mis avant:
 
    outb(0x01, CONTROLREG); // Signal LCD with a strobe [0x28 2: Reception, 8: RW E active]                                                                                                                          
    usleep(100);
    outb(0xFE, CONTROLREG); // Reset CONTROL [0x0B 0: Emission, B: RS RW E inactive]                                                                                                                                  
    usleep(100);
    busy = 0x80;
    busy &= inb(DATAREG);
 
sinon, le test (busy?1:0) va être assez aléatoire.
 
A+,


---------------
There's more than what can be linked! --  Le capitaine qui ne veut pas obéir à la carte finira par obéir aux récifs. -- Il ne faut plus dire Sarkozy, mais Sarkozon -- (╯°□°)╯︵ ┻━┻
n°2110628
Profil sup​primé
Posté le 09-11-2011 à 21:46:17  answer
 

J'obtiens pas le même comportement de wait_busy selon le programme auquel je l'integre.
 
J'ai à nouveau un curseur comme au début du travail.
J'ai viré LCD_SoftReset. Et il est apparu.  [:shimay:1]

n°2110629
Profil sup​primé
Posté le 09-11-2011 à 21:55:01  answer
 

Je travaille sur ce code là.
Je trouve que c'est ce que nous avons de mieux.
Parce que c'est le premier à afficher quelque chose de plus ou moins cohérent avec l'utilisation de Wait_busy(celui que tu vien de poster).
 
 

Code :
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/io.h>
  5. #include <time.h>
  6. // Base port cablé sur LPT1 ici
  7. #define BASEPORT    0x378
  8. #define DATAREG     BASEPORT+0
  9. #define STATUSREG   BASEPORT+1
  10. #define CONTROLREG  BASEPORT+2
  11. #define NEWCODE 0
  12. #ifdef NEWCODE
  13. /* ***************************************************************************** */
  14. /*                       Commandes de bas niveau                                 */
  15. /* ***************************************************************************** */
  16. // Envoi de commandes SPP -> LCD
  17. void send_cmd(unsigned char cmd) { // Cas RS=0, (Emission et) RW=0
  18.  
  19.   outb(0x0B, CONTROLREG); // Set Control [0x0B 0: Emission, B: RS RW E inactive]
  20.   usleep(100);
  21.   outb(cmd,  DATAREG);    // Set command in DATA
  22.   usleep(100);
  23.   outb(0x0A, CONTROLREG); // Signal LCD with a strobe [0x0A 0: Emission, A: E active]
  24.   usleep(100);
  25.   outb(0x0B, CONTROLREG); // Reset CONTROL [0x0B 0: Emission, B: RS RW E inactive]
  26.   usleep(100);
  27. }
  28.     // Envoi d'un caractere SPP -> LCD
  29. void send_char(char c) {    // Cas RS=1, (Ecriture et) RW = 0
  30.   outb(0x03, CONTROLREG); // Set Control [0x03 0: Emission, 3: RS active]
  31.   usleep(100);
  32.   outb(c,    DATAREG);    // Set command in DATA
  33.   usleep(100);
  34.   outb(0x02, CONTROLREG); // Signal LCD with a strobe [0x02 0: Emission, 2: RS E active]
  35.   usleep(100);
  36.   outb(0x0B, CONTROLREG); // Reset CONTROL [0x0B 0: Emission, B: RS RW E inactive]
  37.   usleep(100);
  38. }
  39. // Lecture busy + addresse courante RAM LCD -> SPP
  40. unsigned char address_read() { // Cas RS=0, (Reception et) RW = 1
  41.   unsigned char address = 0x7F; // Mask for D6..D0
  42.   outb(0x29, CONTROLREG); // Set Control [0x29 2: Reception, 9: RW active]
  43.   usleep(1);
  44.   outb(0x28, CONTROLREG); // Signal LCD with a strobe [0x28 2: Reception, 8: RW E active]
  45.   usleep(1);
  46.   outb(0x0B, CONTROLREG); // Reset CONTROL [0x0B 0: Emission, B: RS RW E inactive]
  47.   usleep(1);
  48.   address &= inb(DATAREG);
  49.   return address;
  50. }
  51. // Test du flag busy du LCD.   
  52. void wait_busy() {             // Cas RS=0, (Reception et) RW = 1
  53.   //unsigned char maxtries = 255;
  54.   unsigned char busy = 0x80; // Mask for D7
  55.  
  56.   do {   
  57.    
  58.    
  59.     outb(0x01, CONTROLREG); // Signal LCD with a strobe [0x28 2: Reception, 8: RW E active]                                                                                                                           
  60.     usleep(100);
  61.     outb(0xFE, CONTROLREG); // Reset CONTROL [0x0B 0: Emission, B: RS RW E inactive]                                                                                                                                   
  62.     usleep(100);
  63.     busy = 0x80;
  64.     busy &= inb(DATAREG);   
  65.     usleep(100);
  66.     printf("DATAREG: %x\n", inb(DATAREG));
  67.     //--maxtries;
  68.   } while  (busy?1:0);
  69. }
  70. // Lecture valeur a l'addresse courante RAM LCD -> SPP
  71. unsigned char data_read() {   // Cas RS=1, (Reception et) RW = 1
  72.   unsigned char data;
  73.   outb(0x21, CONTROLREG); // Set Control [0x21 2: Reception, 1: RS RW active]
  74.   usleep(1);
  75.   outb(0x20, CONTROLREG); // Signal LCD with a strobe [0x20 2: Reception, 0: RS RW E active]
  76.   usleep(1);
  77.   outb(0x0B, CONTROLREG); // Reset CONTROL [0x0B 0: Emission, B: RS RW E inactive]
  78.   usleep(1);
  79.   data = inb(DATAREG);
  80.   return data;
  81. }
  82. void LCD_Position(int pos) {
  83.   outb(0x08, CONTROLREG);
  84.   usleep(20);
  85.   outb(128+pos, DATAREG);
  86.   usleep(20);
  87.   outb(0x0A,    CONTROLREG); // Signal LCD with a strobe [0x0A 0: Emission, A: E active]                                                     
  88.   usleep(10);                 // Strobe duration: 500 ns                                                                                     
  89.   outb(0x0B,    CONTROLREG); // Reset CONTROL [0x0B 0: Write, B: RS RW E inactive]                                                           
  90.   usleep(50);                 // Wait before next strobe: 500 ns                                                                             
  91. }
  92. #else
  93. // Envoi de commandes SPP -> LCD
  94. void send_cmd(unsigned char cmd) { // Cas RS=0, (Emission et) RW=0
  95.   outb(cmd, DATAREG);        // Set command in DATA
  96.   usleep(100);
  97.   outb(0x0A,    CONTROLREG); // Signal LCD with a strobe [0x0A 0: Emission, A: E active]
  98.   usleep(100);                 // Strobe duration: 500 ns   
  99.   outb(0x0B,    CONTROLREG); // Reset CONTROL [0x0B 0: Write, B: RS RW E inactive]
  100.   usleep(100);                 // Wait before next strobe: 500 ns
  101. }
  102. // Envoi d'un caractere SPP -> LCD
  103. void send_char(char c) {    // Cas RS=1, (Ecriture et) RW = 0
  104.   outb(c,    DATAREG);    // Set command in DATA
  105.   usleep(100);
  106.   outb(0x02, CONTROLREG); // Signal LCD with a strobe [0x02 0: Emission, 2: RS E active]
  107.   usleep(100);              // Strobe duration: 500 ns   
  108.   outb(0x0B, CONTROLREG); // Reset CONTROL [0x0B 0: Write, B: RS RW E inactive]
  109.   usleep(100);              // Wait before next strobe: 500 ns
  110. }
  111.     // Lecture addresse courante RAM LCD -> SPP
  112. unsigned char address_read() { // Cas RS=0, (Reception et) RW = 1
  113.   unsigned char address = 0x7F; // Mask for D6..D0
  114.      
  115.   outb(0x00, DATAREG);    // reset DATA [NOTE: C'est peut être une précaution inutile, a tester sans ]
  116.   usleep(100);
  117.   outb(0x28, CONTROLREG); // Signal LCD with a strobe [0x28 2: Reception, 8: RW E active]
  118.   usleep(100);              // Strobe duration: 500 ns
  119.   address &= inb(DATAREG);
  120.   outb(0x0B, CONTROLREG); // Reset CONTROL [0x0B 0: Write, B: RS RW E inactive]
  121.   usleep(100);              // Wait before next strobe: 500 ns
  122.   return address;
  123. }
  124. // Test du flag busy du LCD.   
  125. void wait_busy() {             // Cas RS=0, (Reception et) RW = 1
  126.   //unsigned char maxtries = 255;
  127.   unsigned char busy = 0x80; // Mask for D7
  128.  
  129.   do {   
  130.     outb(0x00, DATAREG);    // reset DATA [NOTE: C'est peut être une précaution inutile, a tester sans ]
  131.     usleep(100);
  132.     outb(0x01, CONTROLREG); // Signal LCD with a strobe [0x28 2: Reception, 8: RW E active]                                                                                                                           
  133.     usleep(100);
  134.     outb(0xFE, CONTROLREG); // Reset CONTROL [0x0B 0: Emission, B: RS RW E inactive]                                                                                                                                   
  135.     usleep(100);
  136.     busy = 0x80;
  137.     busy &= inb(DATAREG);   
  138.     usleep(100);
  139.     printf("DATAREG: %x\n", inb(DATAREG));
  140.   } while  (busy?1:0);
  141. }
  142.     outb(0x01, CONTROLREG); // Signal LCD with a strobe [0x28 2: Read, 8: RW E active]
  143.     usleep(100);              // Strobe duration: 500 ns
  144.     busy &= inb(DATAREG);
  145.     outb(0xFE, CONTROLREG); // Reset CONTROL [0x0B 0: Write, B: RS RW E inactive]
  146.     usleep(100);              // Wait before next strobe: 500 ns
  147.   } while  (busy?1:0);
  148. }
  149. // Lecture valeur a l'addresse courante RAM LCD -> SPP
  150. unsigned char data_read() {   // Cas RS=1, (Reception et) RW = 1
  151.   unsigned char data;
  152.  
  153.   outb(0x00, DATAREG);    // reset DATA [NOTE: C'est peut être une précaution inutile, a tester sans ]
  154.   usleep(100);
  155.   outb(0x20, CONTROLREG); // Signal LCD with a strobe [0x20 2: Read, 0: RS RW E active]
  156.   usleep(100);              // Strobe duration: 500 ns   
  157.      data = inb(DATAREG);
  158.      outb(0x0B, CONTROLREG); // Reset CONTROL [0x0B 0: Write, B: RS RW E inactive]
  159.      usleep(100);              // Wait before next strobe: 500 ns
  160.      return data;
  161.     }
  162. void LCD_Position(int pos) {
  163.   outb(0x08, CONTROLREG);
  164.   usleep(20);
  165.   outb(128+pos, DATAREG);
  166.   usleep(20);
  167.   outb(0x0A,    CONTROLREG); // Signal LCD with a strobe [0x0A 0: Emission, A: E active]                                                     
  168.   usleep(10);                 // Strobe duration: 500 ns                                                                                     
  169.   outb(0x0B,    CONTROLREG); // Reset CONTROL [0x0B 0: Write, B: RS RW E inactive]                                                           
  170.   usleep(50);                 // Wait before next strobe: 500 ns                                                                             
  171. }
  172.     #endif
  173. /* ***************************************************************************** */
  174.     /*                       Commandes du LCD                                        */
  175.     /* ***************************************************************************** */
  176.     // cas 00000001
  177.     void LCD_Clear() {
  178.       unsigned char command = 0x01;  // Clear command
  179.        wait_busy(); /* wait */;
  180.      usleep(1);
  181.      send_cmd(command);
  182.     }
  183.     // cas 0000001x
  184.     void LCD_Home() {
  185.      unsigned char command = 0x02;  // Home command
  186.      wait_busy(); /* wait */;
  187.      send_cmd(command);
  188.     }
  189.     // cas 000001xx
  190.     void LCD_EntryMode(int lr, int shift) {
  191.       unsigned char command = 0x04;  // Entry Mode command
  192.      if (lr)      command |= 0x02; // Left -> Right [else Right Left] default
  193.      if (shift)   command |= 0x01; // Shift visible   
  194.      wait_busy(); /* wait */;
  195.      usleep(1);
  196.      send_cmd(command);
  197.     }
  198.     // cas 00001xxx
  199.     void LCD_Display(int on, int cursor, int blink) {
  200.      unsigned char command = 0x08;  // DISPLAY command
  201.      if (on)      command |= 0x04; // Display on/off bit
  202.      if (cursor)  command |= 0x02; // Cursor on/off bit
  203.      if (blink)   command |= 0x01; // Cursor blink on/off bit
  204.      //wait_busy(); /* wait */;
  205.      usleep(1);
  206.      send_cmd(command);
  207.     }
  208.     // cas 0001xxxx -> LCD CursorMove (et Display Move)
  209.     // cas 001xxxxx
  210.     void LCD_Mode(int size8, int line2, int bigfont) {
  211.      unsigned char command = 0x20;  // Mode command
  212.      if (size8)   command |= 0x10; // 8 bit data [else 4 bit data mode] default
  213.      if (line2)   command |= 0x08; // 2 lines mode [else 1 line mode] default
  214.      if (bigfont) command |= 0x04; // 5x11 font [else 5x8 font, default]
  215.      wait_busy(); /* wait */;
  216.      send_cmd(command);
  217.     }
  218.     // cas 01xxxxxx -> LCD Set CGRAM
  219.     // cas 1xxxxxxx -> LCD Set DDRAM
  220.     /* ***************************************************************************** */
  221.     /*                       Fonctions de "haut niveau"                              */
  222.     /* ***************************************************************************** */
  223.     // Ecriture d'un caractère
  224.     void LCD_WriteChar(char c) {
  225.      wait_busy(); /* wait */;
  226.    
  227.      send_char(c);
  228.     }
  229.     // Ecriture d'une chaine
  230. void LCD_WriteString(char *s) {
  231.   while (*s) {   
  232.    
  233.     send_char(*s++);
  234.   }
  235. }
  236.     // Reset du LCD et Initialisation
  237.     // Note le hard reset de mise sous tension equivaut a LCD_SoftReset(1,0,0)
  238.     void LCD_SoftReset(int size8, int line2, int bigfont) {
  239.      unsigned char command = 0x20;  // Mode command
  240.      if (size8)   command |= 0x10; // 8 bit data [else 4 bit data mode] default
  241.      if (line2)   command |= 0x08; // 2 lines mode [else 1 line mode] default
  242.      if (bigfont) command |= 0x04; // 5x11 font [else 5x8 font, default]
  243.      // Sequence de reinitialisation
  244.      // D'abord, 3 commandes Mode avec la valeur voulue pour bit8
  245.      //wait_busy(); /* wait */;
  246.      send_cmd(command); //   
  247.      usleep(5000);      // more than 4.1 ms
  248.      send_cmd(command);
  249.      usleep(500);      // more than 100 µs
  250.      send_cmd(command); // Maintenant is_busy va fonctionner   
  251.      usleep(500);      // more than 100 µs
  252.      // Sequence de parametrage
  253.      LCD_Clear();                     // Display Clear
  254.      wait_busy(); /* wait */;
  255.      LCD_Mode(size8, line2, bigfont); // les valeurs passees seront inchangeables dorenavant
  256.      wait_busy(); /* wait */;
  257.      LCD_Display(0, 0, 0);            // Display Off
  258.      wait_busy(); /* wait */;
  259.      
  260.      LCD_EntryMode(1, 0);             // Left-Right, no shift
  261.      wait_busy(); /* wait */;
  262.     }
  263. int main (void) {
  264.  
  265.   char date[9];
  266.   char hostname[9];
  267.  
  268.   char dummy[4096];
  269.  
  270.   char file[] = "/proc/meminfo";
  271.   FILE *fp;
  272.   char valeur[10];
  273.   char name[10];
  274.   char cpu[7];
  275.   FILE *cpufp;
  276.   char label_cpu[]  = "cpu   : \0";
  277.   char label_mem[]  = "mem   : \0";
  278.   char label_swap[] = "swap  : \0";
  279.   char label_proc[] = "proc  : \0";
  280.   char label_pid[]  = "pid   : \0";
  281.   char label_pri[]  = "prio  : \0";
  282.  
  283.   float mem_total, mem_free, mem_swap, mem_used = 0.0;
  284.  
  285.   char value_total[10];
  286.   char value_swap[10];
  287.  
  288.   char getted_char;
  289.  
  290.  
  291.   if (system(dummy)) return (1);
  292.  
  293.   fp = fopen(file, "r" );
  294.   if (!fp) {
  295.     perror("/proc/meminfo" );
  296.     return -1;
  297.   }
  298.    
  299.   time_t current_date = time(NULL);
  300.  
  301.   strftime(date, sizeof(date), "%H:%M:%S", localtime(&current_date));
  302.   gethostname(hostname, sizeof(hostname));
  303.  
  304.   if (ioperm(BASEPORT, 3, 1)) {
  305.     perror("can't set IO permissions!" );
  306.     return -1;
  307.   }
  308.  
  309.   //LCD_SoftReset(1,1,0); // Ce serait bien de tester ceci aussi
  310.   usleep(500);
  311.   LCD_Display(1, 1, 1); // Display On LCD ON Cursor ON Cursor Blink     
  312.   usleep(120); 
  313.    
  314.   int i;
  315.     for (i = 1; i <= 5 ; i++) {
  316.     fscanf(fp, "%s%s%s\n", name, valeur, dummy);
  317.     current_date = time(NULL);
  318.     cpufp = popen("ps aux| awk 'NR > 0 { s +=$3 }; END {print s}'","r" );
  319.     fread(cpu, 1, sizeof(cpu)-1, cpufp);
  320.     fclose(cpufp);
  321.     switch (i) {
  322.      
  323.     case 1 : {
  324.      
  325.       char *p_conv = NULL;
  326.       mem_total = (float)strtol(valeur, &p_conv, 10);
  327.      
  328.      
  329.       break;
  330.     }
  331.     case 2 : {
  332.       char *p_conv = NULL;
  333.       mem_free = (float)strtol(valeur, &p_conv, 10);
  334.       mem_used = ((mem_total-mem_free)*100)/mem_total;
  335.      
  336.       break;
  337.     }
  338.     case 5 : {
  339.       char *p_conv = NULL;
  340.       mem_swap = (float)strtol(valeur, &p_conv, 10);
  341.       strftime(date, sizeof(date), "%H:%M:%S", localtime(&current_date));
  342.      
  343.       LCD_Clear();
  344.       usleep(120);
  345.       LCD_Position(14);
  346.      
  347.      
  348.       usleep(120);
  349.       LCD_WriteString(hostname);
  350.       usleep(120);
  351.       LCD_WriteString(date);
  352.       usleep(120);
  353.      
  354.       LCD_Position(54);
  355.      
  356.       usleep(120);
  357.       LCD_WriteString(label_cpu);
  358.       usleep(120);
  359.       LCD_WriteString(cpu);
  360.       usleep(120);
  361.      
  362.       LCD_Position(0);
  363.      
  364.       LCD_WriteString(label_mem);
  365.       usleep(120);
  366.       sprintf(value_total, "%f", mem_used);
  367.       LCD_WriteString(value_total);
  368.       usleep(120);
  369.       LCD_Position(40);
  370.      
  371.       usleep(120);
  372.       LCD_WriteString(label_swap);
  373.       usleep(120);
  374.       sprintf(value_swap, "%f", mem_swap);
  375.       LCD_WriteString(value_swap);
  376.      
  377.       sleep(1);
  378.      
  379.     }
  380.     }
  381.   }
  382.   fclose(fp);
  383.  
  384.   if (ioperm(BASEPORT, 3, 0)) {
  385.     perror("can't reset IO permissions!" );
  386.     return -1;
  387.   }
  388.   return 0;
  389. }


 
Il manquerait une fonction de positionnement. Même pas.


Message édité par Profil supprimé le 09-11-2011 à 21:58:06
n°2110647
Profil sup​primé
Posté le 10-11-2011 à 00:46:52  answer
 

gilou a écrit :

Donc c'est OK: On est en ligne 1, au 9e caractère :whistle:  
 
Bon, je suis à la bourre, alors c'est très brut de décoffrage...
 

Code :
  1. void set_rawposition(unsigned char rawposition) {
  2.     unsigned char command = 0x80 + rawposition;
  3.     unsigned char control = GetControl();
  4.    
  5.     Set_RS(control);
  6.     usleep(1); 
  7.     SetData(command);
  8.     Set_E(control);
  9.     usleep(1); 
  10.     Clear_E(control);
  11.     usleep(1); 
  12.    
  13. }


 
Je vais bouffer, la.
A+,


 
Le code qui suit fonctionne, même version de bibliothèque. Mais pas le même ordre des instructions.
 

Code :
  1. void set_rawposition(unsigned char rawposition) {
  2.   unsigned char command = 0x80 + rawposition;
  3.   unsigned char control = GetControl();
  4.   Clear_RS(control);
  5.   usleep(1);
  6.   SetData(command);
  7.   Set_E(control);
  8.   usleep(1);
  9.   Clear_E(control);
  10.   usleep(1);
  11.   Set_RS(control);
  12. }


 

n°2110649
Profil sup​primé
Posté le 10-11-2011 à 01:30:46  answer
 

Ca plante toujours à l'utilisation de firefox. Je vais faire tourner un peu.
 
La j'ai retrouvé le code qui fonction sans précondition, si ce n'est qu'il ne faux pas avoir planté l'afficheur avant.
 
Au boot ça marche, après j'ai capté quand l'intérompre ou pas. J'ai des programme pour récupérer un plantage. Faut que j'arrive à tout réunir. Et manquera plus que le buzy.

mood
Publicité
Posté le   profilanswer
 

 Page :   1  2  3  4  5  6  7  8

Aller à :
Ajouter une réponse
 

Sujets relatifs
[C] Modifier un tableau existant ... pour bouger un pion ![C# / .Net] Migration OS 32Bits vers OS 64Bits. Quid des Perfs?
[C#] FormView, edit/insert mode[C] programme cherche les racines des polynomes
[C] trouver la longueur de la plus longue suite decroissante en CC++, Compter des caractères ...
Linux C/C++ broadcast UDP sur machine sans gatewayConvolution de 2 tableaux unidimensionnels avec FFTW C++
Plus de sujets relatifs à : [ Divers / C ] Ecrire pour un afficheur LCD


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)