| Ecran LCD sur bus I2C |
|
|
|
| Écrit par r0ro | |
| 12-09-2007 | |
|
Utilisation d'un écran LCD sur bus I2C
Commande d'un écran LCD sur le bus I2CIntro Depuis longtemps on cherchait a avoir un écran sur notre robot, mais le probleme était de ne pas utiliser 10 IO pour faire beau ! En effet sur notre archi (basée sur un FPGA) on n'a pas une infinité d'IO. On a alors trouvé un module de commande d'écran en I2C, et un site qui vend l'écran et le module assemblés : http://www.crownhill.co.uk/product.php?prod=1304∞ Description du bus I2C Le bus I2C est un bus de communication série sur deux fils : SDA et SCL Vous trouverez une bonne description du protocole I2C sur le site de planete sciences : http://www.planete-sciences.org/robot/ressources/electronique/protocoleI2C/PDF/protocoleI2C.pdf∞ Code source utilisation de l'écran Le code fourni utilise des fonctions spécifiques au FPGA pour la gestion du bus I2C. En particulier la fonction : /***************************************************************** * UTILISATION DE L'ECRAN LCD via I2C v0.2 * * * * Auteur : r0ro * * Description : utilisation de l'écran via i2c * * Copyright : PLAYBOT 2007 * * Date : 13/12/06 * * * * * ******************************************************************/ #ifndef SCREEN_H #define SCREEN_H #define ADDR_SCREEN_IIC 99 #define CURSOR_HOME 1 #define SET_CURSOR 2 //suivi de la position (1-80) #define SET_CURSOR_2 3 //suivi de 2 bits : ligne, colonne #define HIDE_CURSOR 4 #define UNDERLINE_CURSOR 5 #define BLINKING_CURSOR 6 #define BACKSPACE 8 #define HORIZONTAL_TAB 9 //tab definie avec TAB_SET (defaut : 4) #define SMART_LINE_FEED 10 //descend le curseur d'une ligne #define VERTICAL_TAB 11 //remonte le curseur d'une ligne #define CLEAR_SCREEN 12 #define CARRIAGE_RETURN 13 #define CLEAR_COLLUMN 17 //efface la colonne courante #define TAB_SET 18 //definie la tabulation suivi de 1 bit (1-10) #define BACKLIGHT_ON 19 #define BACKLIGHT_OFF 20 #define CUSTOM_CHAR 27 //Permet de creer des caracteres perso (voir doc) //custom char #define FLECHE_HAUT 128 #define FLECHE_BAS 129 #define BACK_SLASH 130 #define CHAR_FULL 131 #include "xiic_l.h" #include "xparameters.h" #include "xbasic_types.h" void screen_init(); void screen_clear(); void screen_backlight(int on_off); void screen_write(char * txt, int x, int y); void screen_progress(int pourcent); #endif /***************************************************************** * UTILISATION DE L'ECRAN LCD via I2C v0.2 * * * * Auteur : r0ro * * Description : utilisation de l'écran via i2c * * Copyright : PLAYBOT 2007 * * Date : 13/12/06 * * * * * ******************************************************************/ #include "screen.h" //initialisation de l'ecran : Clean + Backlight ON + definition char perso void screen_init(){ Xuint8 cmd[11]; char * txt = "|. | . PLAYBOT | / Robots that play|/"; screen_clear(); screen_backlight(BACKLIGHT_ON); //definition des caracteres speciaux //fleche haut cmd[0] = ADDR_SCREEN_IIC * 2; cmd[1] = CUSTOM_CHAR; cmd[2] = FLECHE_HAUT; cmd[3] = 128; cmd[4] = 132; cmd[5] = 142; cmd[6] = 149; cmd[7] = 132; cmd[8] = 132; cmd[9] = 132; cmd[10] = 128; XIic_Send(XPAR_IIC_ECRAN_BASEADDR, ADDR_SCREEN_IIC, cmd, 11, XIIC_STOP); //fleche bas cmd[1] = CUSTOM_CHAR; cmd[2] = FLECHE_BAS; cmd[3] = 128; cmd[4] = 132; cmd[5] = 132; cmd[6] = 132; cmd[7] = 149; cmd[8] = 142; cmd[9] = 132; cmd[10] = 128; XIic_Send(XPAR_IIC_ECRAN_BASEADDR, ADDR_SCREEN_IIC, cmd, 11, XIIC_STOP); //backslash cmd[1] = CUSTOM_CHAR; cmd[2] = BACK_SLASH; cmd[3] = 128; cmd[4] = 144; cmd[5] = 136; cmd[6] = 132; cmd[7] = 130; cmd[8] = 129; cmd[9] = 128; cmd[10] = 128; XIic_Send(XPAR_IIC_ECRAN_BASEADDR, ADDR_SCREEN_IIC, cmd, 11, XIIC_STOP); //char_full cmd[1] = CUSTOM_CHAR; cmd[2] = CHAR_FULL; cmd[3] = 159; cmd[4] = 159; cmd[5] = 159; cmd[6] = 159; cmd[7] = 159; cmd[8] = 159; cmd[9] = 159; cmd[10] = 159; XIic_Send(XPAR_IIC_ECRAN_BASEADDR, ADDR_SCREEN_IIC, cmd, 11, XIIC_STOP); //Logo Playbot txt[1] = BACK_SLASH; txt[22] = BACK_SLASH; screen_write(txt, 1, 1); //on degage le curseur cmd[1] = HIDE_CURSOR; XIic_Send(XPAR_IIC_ECRAN_BASEADDR, ADDR_SCREEN_IIC, cmd, 2, XIIC_STOP); } // Controle l'eclairage de l'ecran void screen_backlight(int on_off){ Xuint8 cmd[2]; cmd[0] = ADDR_SCREEN_IIC * 2; cmd[1] = on_off; XIic_Send(XPAR_IIC_ECRAN_BASEADDR, ADDR_SCREEN_IIC, cmd, 2, XIIC_STOP); } // Efface l'ecran void screen_clear(){ Xuint8 cmd[2]; cmd[0] = ADDR_SCREEN_IIC * 2; cmd[1] = CLEAR_SCREEN; XIic_Send(XPAR_IIC_ECRAN_BASEADDR, ADDR_SCREEN_IIC, cmd, 2, XIIC_STOP); } // Ecrit un texte en X, Y void screen_write(char * txt, int x, int y) { Xuint8 size; Xuint8 cmd[84]; y = (y > 0 && y < 5) ? y : 1; x = (x > 0 && x < 20) ? x : 1; cmd[0] = ADDR_SCREEN_IIC * 2; cmd[1] = SET_CURSOR_2; cmd[2] = y; cmd[3] = x; size = 0; while (txt[size] != '\0' && size < 84) { cmd[size+4] = txt[size]; size++; } XIic_Send(XPAR_IIC_ECRAN_BASEADDR, ADDR_SCREEN_IIC, cmd, size + 4, XIIC_STOP); } // Affiche une barre de progression sur la derniere ligne et le pourcentage sur l'avant derniere void screen_progress(int pourcent) { char * txt = "xxx %"; char txt2[21]; Xuint8 i, nb_bloc; pourcent = (pourcent >= 0 && pourcent <= 100) ? pourcent : 0; nb_bloc = (pourcent/5); for (i=0; i<nb_bloc; i++) { txt2[i]=CHAR_FULL; } for (i=nb_bloc; i < 21; i++) { txt2[i] = ' '; } txt2[21] = '\0'; txt[0] = '0' + pourcent / 100 ; pourcent = pourcent % 100; txt[1] = '0' + (pourcent / 10); pourcent = pourcent % 10; txt[2] = '0' + pourcent; screen_write(txt, 9, 3); screen_write(txt2, 0, 4); } /***************************************************************** * UTILISATION DE L'ECRAN LCD via I2C v0.1 * * * * Auteur : r0ro * * Description : utilisation de l'écran via i2c * * Copyright : PLAYBOT 2007 * * Date : 13/12/06 * * * * * ******************************************************************/ #include "xiic_l.h" #include "xparameters.h" #include "xbasic_types.h" #include "xgpio.h" #include "xuartlite_l.h" #include "screen.h" main() { volatile int i; int j; print("TEST LCD\r\n"); screen_init(); screen_clear(); for (j=0; j < 101; j++) { screen_progress(j); for (i=0; i < 100000; i++); } return 1; } |
|
| Dernière mise à jour : ( 14-09-2007 ) |



